A quick note on using jshell with the official Docker image of the JDK

Leverage the official Java Docker image

--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/

Note: Repeat execution

$  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

A quick note on using jshell with the official Docker image of the JDK
Create a Docker image with the Oracle JDK installed (yum
Proceed with the official Rust documentation on a Docker container (2. Program a number guessing game)
A note about the seed function of Ruby on Rails
Note on the path of request.getRequestDispatcher
Set up a Wordpress Docker environment without using the Worpdress image
Run (provisionally) a Docker image with ShellCommandActivity on AWS Data Pipeline
Create a large number of records with one command using the Ruby on Rails seeds.rb file
The story of setting up an Oracle V $ -like thing from 0 on PostgreSQL: 12 of the official Docker image
Display text on top of the image
Make a daily build of the TOPPERS kernel with Gitlab and Docker
A note on the libGDX Utils class
A rudimentary note on the Fibonacci sequence
(Note) Get a set of dependent library jars with the help of Gradle
Up to the point of launching a Docker container built using RedHat Quarkus
Send a notification to slack with the free version of sentry (using lambda)
Using templates on the classpath with Apache Velocity
Come out with a suffix on the method
Come out with a suffix on the method 2
Update container image with KUSANAGI Runs on Docker
Push the image to docker hub using Jib
How to build a Jenkins server with a Docker container on CentOS 7 of VirtualBox and access the Jenkins server from a local PC
[Docker] How to see the contents of Volumes. Start a container with root privileges.
Getting a little stuck on the last day of the month using Java's Calendar class
Docker the development environment of Ruby on Rails project
The story of making a reverse proxy with ProxyServlet
I built an environment to execute unit tests using Oracle database (oracle12c) on the Docker in Docker (dind) image of GitLab-CI.
Run the Android emulator on Docker using Android Emulator Container Scripts
[Note] Build a Python3 environment with Docker in EC2
[Note] Create a java environment from scratch with docker
Try using the query attribute of Ruby on Rails
The story of pushing a Docker container to GitHub Package Registry and Docker Hub with GitHub Actions
[Oracle Cloud] Build a 4-Node RAC environment of Oracle Database 19c with Docker on OCI Compute
[Automatic trading of Bitcoin] A story about operating with Docker on AWS, with 1 TAP ON / OFF & Line notification from Apple Watch on the go
Proceed with Rust official documentation on Docker container (1. Getting started)
Creating a docker host on AWS using Docker Machine (personal memorandum)
A quick explanation of the five types of static in Java
Transition using the header image of CardView as it is
Register your own Docker image with ECR using AWS CLI
A story packed with the basics of Spring Boot (solved)
Check the operation of two roles with a chat application
[Swift 5] Select a date with the IDate Picker on iOS14
Until the production deployment of hello-app with k3d on Time4VPS
I tried JAX-RS and made a note of the procedure
Try launching a webAP server on the micro using Helidon
How to install JDK 8 on Windows without using the installer
Explain the benefits of the State pattern with a movie rating
Time is wrong with the application launched on the Docker container
Try Hello World using plain Java on a Docker container
Find the number of days in a month with Kotlin
One file of Docker x Laravel threat! Build a local development environment with the minimum configuration
Build a NAS with DLNA function at the speed of a second with Raspberry Pi and Docker Compose
[Be careful about changing the version of Xdebug! ] Create a development environment with Xdebug3 + docker + VS Code
The story of fighting ubuntu errors 0x80370114, 0x80000000 to enable docker desktop with wsl2 on windows10 home