JShell is Java’s first official REPL (READ-EVAL-PRINT-LOOP) tool. It is part of JDK 9 is going to be released in September 2017.
JShell REPL creates a simple programming environment in the command line that can:
- read user's input
- evaluate it
- print the result
- repeat the cycle
It works similar to Python interpreter or other JVM languages that have a REPL like Scala, Kotlin and Groovy.
You can write Java language expressions and statements in the JShell REPL, and they will be evaluated on their own without having to wrap them in classes or methods.
Let's take a look how to start with JShell.
As mentioned above, JShell is a part of upcoming Java 9. But eraly access is already available.
When JDK 9 is installed, type
jshell in your terminal to start a JShell session -
$ jshell | Welcome to JShell -- Version 9 | For an introduction type: /help intro jshell>
An interactive JShell session will be started and JShell will greet you with a welcome message.
Learn more with this tutorial.