Last active
May 12, 2023 13:01
-
-
Save jexp/499e608545b2b2d5974df4178a48967b to your computer and use it in GitHub Desktop.
JDK Command Line Tools https://tinyurl.com/java-cli-tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# english output for tools | |
export JAVA_TOOL_OPTIONS=-Duser.language=en | |
# sdkman | |
sdk list | |
sdk list java | |
#sdk install java 20-open | |
sdk use java 20-open | |
java -version | |
# jshell | |
jshell --enable-preview | |
System.out.println("Hello Devoxx UK!") | |
IntStream.range(1,10).map(i -> i*i).filter(i -> i%2==0).toArray() | |
var threads = | |
IntStream.range(0,10).mapToObj(i -> | |
Thread.ofVirtual().start(() -> { | |
System.out.println("Hello Virtual Thread "+i+" "+Thread.currentThread()); | |
})).toList(); | |
for (Thread t : threads) { | |
t.join(); | |
} | |
# Game of Life in jshell | |
// GOL Rules: Cell is alive, if it was alive and has 2 or 3 | |
// living neighbours or always with 3 living neighbours | |
import static java.util.stream.IntStream.range; | |
import static java.util.stream.Collectors.*; | |
import static java.util.function.Predicate.*; | |
record Cell(int x, int y) { | |
Stream<Cell> nb() { | |
return range(x()-1,x()+2) | |
.mapToObj(i -> i) | |
.flatMap(x -> range(y()-1,y()+2) | |
.mapToObj(y -> new Cell(x,y))) | |
.filter(c -> !this.equals(c)); | |
} | |
boolean alive(Set<Cell> cells) { | |
var count = nb().filter(cells::contains).count(); | |
return (cells.contains(this) && count == 2) || count == 3; | |
} | |
} | |
Set<Cell> evolve(Set<Cell> cells) { | |
return cells.stream().flatMap(c -> c.nb()).distinct() | |
.filter(c -> c.alive(cells)) | |
.collect(toSet()); | |
} | |
void print(Set<Cell> cells) { | |
var min=new Cell(cells.stream().mapToInt(Cell::x).min().getAsInt(), | |
cells.stream().mapToInt(Cell::y).min().getAsInt()); | |
var max=new Cell(cells.stream().mapToInt(Cell::x).max().getAsInt(), | |
cells.stream().mapToInt(Cell::y).max().getAsInt()); | |
range(min.y(), max.y()+1) | |
.mapToObj(y -> range(min.x(), max.x()+1) | |
.mapToObj(x -> cells.contains(new Cell(x,y)) ? "X" : " ") | |
.collect(joining(""))).forEach(System.out::println); | |
} | |
var cells = Set.of(new Cell(0,1), new Cell(1,0), new Cell(1,1),new Cell(1,2),new Cell(2,1)); | |
void gen(Set<Cell> cells, int steps) { | |
print(cells); | |
if (steps>0) gen(evolve(cells),steps-1); | |
} | |
gen(cells, 10) | |
# java execution | |
# java source execution | |
cat > Hello.java <<EOF | |
public class Hello { | |
public static void main(String...args) { | |
System.out.println("Hello "+String.join(" ",args)+"!"); | |
} | |
} | |
EOF | |
java Hello.java | |
cp Hello.java hello | |
chmod +x hello | |
vi hello | |
#!/usr/bin/java --source 20 | |
./hello London | |
# jbang | |
jbang init -t cli hellocli.java | |
jbang hellocli.java | |
./hellocli.java --help | |
jbang edit hellocli.java | |
jbang hellocli.java London | |
# jwebserver | |
jwebserver -d `pwd` | |
# jps | |
jps | |
jps -l | |
jps -q | |
jps -m | |
# jstack | |
jstack 36612 | |
jstack -h | |
kill -3 36612 | |
# jcmd | |
jcmd 36612 | |
jcmd 36612 GC.run | |
jcmd 36612 VM.info | |
jps | |
jcmd EnterpriseEntryPoint $'VM.version\nVM.uptime\nVM.flags' | |
jcmd EnterpriseEntryPoint GC.heap_info | |
jcmd EnterpriseEntryPoint GC.class_histogram | head | |
jbang NeoTest.java --requests 10000 --query "RETURN 1" | |
jbang NeoTest.java --requests 10000 --query "MATCH path=(:Person)-->() RETURN path LIMIT 5" | |
jbang NeoTest.java --requests 10000 --query "MATCH () RETURN count(*)" --concurrency 6 | |
jcmd EnterpriseEntryPoint JFR.start name=neo | |
jcmd EnterpriseEntryPoint JFR.dump name=neo filename=/tmp/my_recording.jfr | |
jcmd EnterpriseEntryPoint JFR.stop name=neo | |
jfr summary /tmp/my_recording.jfr | head -20 | |
# async-profiler | |
./async-profiler-2.8.3-macos/profiler.sh 36612 -d 15 -f /tmp/flamegraph.html | |
open /tmp/flamegraph.html -a "Arc" | |
# jlink | |
java --list-modules | |
jlink \ | |
--add-modules java.base \ | |
--output ./jdk-base | |
./jdk-base/bin/java --list-modules | |
du -sh jdk-base | |
jdeps -s hello.jar | |
jdeps -s | |
rm -rf jdk-base | |
jlink \ | |
--add-modules java.base \ | |
--compress 2 --output ./jdk-base | |
du -sh jdk-base | |
# javac -d target module-info.java | |
# javac -d target --module-path target HttpEcho.java | |
# java --module-path target --module httpEchoModule/de.jexp.jlink.HttpEcho | |
jdeps --module-path /Users/mh/d/java/javaspektrum/jlink/target -s --module httpEchoModule | |
# jdeprscan | |
jdeprscan --release 20 neo4j-kernel-5.7.0.jar 2>&1 | grep -v "cannot" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment