Java Design Pattern
Introduction to Java 10
Introduction to Java 11
Introduction to Java 12

JShell(REPL)

Oracle Corp has introduced a new tool called “jshell”. It stands for Java Shell and also known as REPL (Read Evaluate Print Loop). It is used to execute and test any Java Constructs like class, interface, enum, object, statements etc. very easily. After installation of JDk1.9, go to command prompt and type jshell then it will open jshell environment for you.

java9-1

In jshell environment you can execute commands and java statements. For command we use /(slash). Example,
In jshell environment, we type /help command then we get list of command(all commands) that we use.

java9-1

java9-1

To come out from the environment the following command we type,

/exit java9-1

Here in jshell environment writing code is very simple, and very easy to write. For example, I want to print a message then there is no need to declare a class, no need to define a main() method. We can directly write System.out.println(“JAVA means SILAN SOFTWARE)
Here semicolon(;) is also optional, whether u may put or u may not put.

Output:

java9-1

This is the base thing of jshell.
Now I want to perform some operation, then it is very simple. Let’s see :

java9-1

Here the question may arise what is $2
$2 is the unique id whose value is representing as 50
For clarity, if u will type $2, then

java9-1

If u type $2+50, then u get

java9-1

Now $4 is the id. We can use this id in a statement, like
System.out.println($4), then the output is 100

java9-1

We can perform some logical operations. Let’s see

java9-1

We can declare variable and initialize it also. For example

java9-1

About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.


We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc






 PreviousNext