Java 9 : JShell (REPL) feature

We heard a lot about REPL when we were developing AngularJS app or NodeJS app. Which works on Read-Evaluate-Print-Loop mechanism.

Java Shell tool is an interactive tool for learning Java and prototyping java code. JShell works on REPL mechanism which evaluates declarations, statements, and expressions as they are entered and immediately shows the results. The tool is run from the command line.

Earlier Java program used to follow below steps:

  1. Write your Java code
  2. Compile the code and check/fix erros (If any)
  3. Run the program
  4. Check the result and if its wrong
  5. Update the code again and repeat the 1-5 steps again.

 

Jshell will replace this, You can test your logic in this JShell command  and check the result instantly and make required changes and it will automatically show you the updated results without worrying about traditional process of compile/run java program.

 

To start the JShell write below command (Make sure you set the JAVA_HOME path to jdk-9 path)

jshell-1
Start Java JShell REPL

It will start the CLI of JShell

jshell-2
JShell Inline Programming – Java REPL

To stop the JShell type below command in CLI

jshell-3-exit
Exit Java REPL – JShell

 

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s