servlets struts hibernate jsf spring maven
 

Java 9 - REPL (JShell)


REPL represents Read-Eval-Print Loop. JShell enables us to execute Java code snippets

Java REPL application name is jshell. JShell represents Java Shell. jshell is an intuitive apparatus to execute and assess java basic projects like variable assertions, articulations, articulations, simple Programs and so on.

Java REPL – jshell basics

 

 

javacode:~ geeks$ jshell 

| Welcome to JShell - Version 9 

| For a presentation type:/help introduction 

jshell> 

jshell> System.out.println("Hello World"); 

Hi World 

jshell> String str = "Hi Javacodegeeks Users" 

str ==> "Hi JournalDev Users" 

jshell> str 

str ==> "Hi Javacodegeeks Users" 

jshell> System.out.println(str) 

Hi 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.

jshell> class Hello { ...> public static void sayHello() { ...> System.out.print("Hello"); ...> } ...> } | created class Hello jshell> Hello.sayHello() Hello jshell> java repl class Java REPL – Help and Exit

To get jshell tool help section, use /help command. To exit from jshell, use command /exit.

jshell> /help | Type a Java language expression, statement, 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$





javacodegeeks is optimized for learning.© javacodegeeks .
All Right Reserved and you agree to have read and accepted our term and condition