--I want to test with a specific version of the JVM --JVM installation is troublesome
At that time, it is easier to utilize the Docker image of the JVM.
$ cat Hoge.java
public class Moge {
public static void main(String[] args) {
System.out.println("hoge");
}
}
$ docker run --rm -it --volume `pwd`:/tmp adoptopenjdk/openjdk11-openj9 java /tmp/Hoge.java
hoge
Are you running java without compiling? -> JEP330 Java11: Run Java code in a single file as is Java 11 allows you to execute Java files without javac
Reference Try various JDKs with Docker AdoptOpenJDK https://adoptopenjdk.net Official Docker image https://hub.docker.com/u/adoptopenjdk/
$ docker run --rm -it --volume `pwd`:/tmp adoptopenjdk/openjdk11-openj9 /bin/sh -c 'for i in `seq 1 10`; do java -jar /tmp/MDTest.jar |grep -v dig; done' | awk '{sum+=$3} END {print "avg="sum/NR}'
avg=26.1
jshell --I want to quickly execute (written) processing in Java --I don't want to write classes and main, it's troublesome to compile and execute
At that time, jshell is convenient. If you have Docker, you can use it quickly even in an environment where Java 9 or later is not installed.
$ docker run --rm -it adoptopenjdk/openjdk11-openj9 jshell
Nov 16, 2018 12:00:26 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
| Welcome to JShell -- Version 11.0.1
| For an introduction type: /help intro
jshell> System.out.println("moge")
moge
jshell> java.time.Instant.ofEpochMilli(1294012469700l);
$1 ==> 2011-01-02T23:54:29.700Z
jshell>
Well, how do you write one-liner?
[How to write a one-liner script in Java JShell (and FizzBuzz code golf)] (http://sucrose.hatenablog.com/entry/2018/05/05/230434)
I see!
$ echo 'println("hello, world!")' | docker run --rm -it adoptopenjdk/openjdk11-openj9 jshell PRINTING -
the input device is not a TTY
that? Ah.
$ echo 'println("hello, world!")' | docker run --rm -i adoptopenjdk/openjdk11-openj9 jshell PRINTING -
Nov 16, 2018 3:12:46 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
hello, world!
I put -it on anything.
Reference Java starting with JShell-Look into the world of Java Play with Java2D using JShell [Java9 New Features] Introduction to jshell
Recommended Posts