Introduction to JShell

  In this JShell tutorial, we will learn the JShell Tool from beginning to expert, this tutorial provides a brief explanation of the JShell Java Toole. JShell is a Java read-eval-print loop tool first introduced in Java JDK9, JShell services maintain by JEP ( Java Enhancement Protocol).

JShell Introduction

JShell is an interactive tool to evaluate the program declarations, expressions, and statements in a read-eval-print loop (REPL). REPL means to evaluate the code and get an output of each element instantly.

Advantages of JShell :

By writing a java program using JShell, you can evaluate each element one at a time and get the output immediately.

  1. Easy to write and understand the concepts.
  2. JShell is able to get the output of Each element immediately.
  3. Easy to debug and fix errors.
  4. Easy to manage your code.
  5. JShell can help to test each statement individually.
  6. JShell doesn’t replace the IDE, user can easily run IDE code in JShell and vice-versa.

Table of Contents

What if we don’t use JShell? We need the following steps to execute the Java Program.

  1. Need to write a complete java program.
  2. Compile and fix each and every error if occur.
  3. Compile and Run the Java Program.
  4. If getting any issues then need to fix.
  5. Edit and re-compile the code.
  6. Repeat the process until you will get the output.

If you are using JShell Java Tool then you don’t need to follow the above steps.

JShell Introduction.

Quick Example

Let’s have a quick look at the JShell Tool example, the following java program will print the “Hello, JShell !”.

   
 
C:\Users\codenaive>jshell
|  Welcome to JShell -- Version 16.0.1
|  For an introduction type: /help intro

jshell> System.out.print("Hello, JShell !");
Hello, JShell !
jshell>    

Leave a Reply

Your email address will not be published. Required fields are marked *