Java 9 - REPL (JShell)
REPL stands for Read-Eval-Print Loop. JShell allows us to execute Java code snippets
Java REPL application name isjshell
. JShell stands for Java Shell. jshell is an interactive tool to execute and evaluate java simple programs like variable declarations, statements, expressions, simple Programs etc.
Java REPL – jshell basics
javacode:~ geeks$ jshell
| Welcome to JShell -- Version 9
| For an introduction type: /help intro
jshell>
jshell> System.out.println("Hello World");
Hello World
jshell> String str = "Hello Javacodegeeks Users"
str ==> "Hello JournalDev Users"
jshell> str
str ==> "Hello Javacodegeeks Users"
jshell> System.out.println(str)
Hello Javacodegeeks Users
jshell> int counter = 0
counter ==> 0
jshell> counter++
$6 ==> 0
jshell> counter
counter ==> 1
jshell> counter+5
$8 ==> 6
jshell> counter
counter ==> 1
jshell> counter=counter+5
counter ==> 6
jshell> counter
counter ==> 6
jshell>
Java REPL – execute class
We can also define and execute class methods in Java REPL shell.
class Hello {
...> public static void sayHello() {
...> System.out.print("Hello");
...> }
...> }
| created class Hello
jshell> Hello.sayHello()
Hello
jshell>
jshell> 
To get jshell tool help section, use /help
command. To exit from jshell, use command /exit
.
or declaration.
| Or type one of the following commands:
| /list [<name or id>|-all|-start]
| list the source you have typed
| /edit <name or id>
...
jshell> /exit
| Goodbye
java:~ java$
jshell> /help
| Type a Java language expression, statement,