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-2
java9-3

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


/exit
java9-4

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 TECHNOLOGY”)
Here semicolon(;) is also optional, whether u may put or u may not put.

 

Output
java9-5

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


java9-6

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

If u type $2+50, then u get


java9-8

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


java9-9

We can perform some logical operations. Let’s see


java9-10

We can declare variable and initialize it also. For example


java9-11

 

 

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Data Science with Python Training | Projects

SILAN Technology
Call to: 9439202111  |  9658317757  |  0674-2361252

Comment