JShell : Test your logic right away

You might have heard about Java version 9 release and lot of buzzwords related to the new features that are going to unleashed from Oracle. New Module system(jigsaw), Jlink and more tools are introduced.
Today we will talk about one of the tool(aka. feature) which provides functionality that you might have used when you have used javascript and other languages...

So, What it is ....REPL (Read-Evaluate-Print-Loop).

So as you know, when you are writing software all these years, and at any point of time if you want to just execute some random code, some logic that you think it can work, you go to the command line shell (any shell that helps you to execute that language commands) and just right it there and execute..that's it..

Just check out the below features from your browser tools console executing javascript code (REPL feature).

Python, Ruby, Haskell, Tcl also have  REPL features.

Unfortunately java was lacking REPL feature from long time..and with the release of java 9 it has joined the group REPL gladiators to ease your code development.

So, You must be eager to check this cool feature..
  1. Install JDK 9 from Official Oracle website.
  2. Add java to your path variable if its not there.
  3. Go to command prompt. write jschell. Press enter.
Jshell java 9 REPL

So test your logic write away:

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

  jshell> 2+2
  $1 ==> 4

  jshell> int counter=100;
  counter ==> 100
  jshell> System.out.println("Increment counter by 20: "+(counter+20));
  Increment counter by 20: 120

To start the Jshell in verbose mode you can use below command:
jshell -v
To exit out of Jshell use below command:
jshell> /exit
|  Goodbye
JShell helps you try out code and easily explore options as you develop your program. You can test individual statements, try out different variations of a method, and experiment with unfamiliar APIs within the JShell session. JShell doesn’t replace an IDE. As you develop your program, paste code into JShell to try it out, and then paste working code from JShell into your program editor or IDE.

Cookies Consent

This website uses cookies to offer you a better Browsing Experience. By using our website, You agree to the use of Cookies

Privacy Policy