JShell: Introduction To Java Shell Tool
Posted By : Neha Yadav | 28-May-2018
Java Shell Tool is an interactive tool to learn java and to do prototyping of java code.
It is in one of the good features of java 9.
In Jshell you don't have to make a class. You can directly type your statements, expressions. You can test your logic and explore more about your logic it.
To use it, you must have Java 9 installed on the system.
To open it, you have to type
$
| Welcome to JShell -- Version 10.0.1
| For an introduction type: /help intro
jshell>
There is no need to compile it and run , you can directly type the statement you want to check.
some examples to use it:-
1. Print Message.
jshell> System.out.
Hello world
2. Sum two numbers
i) jshell> 1+1
$2 ==> 2
ii)jshell> int a=10; int b=20; a+b;
a ==> 10
b ==> 20
$5 ==> 30
iii)jshell> int a=10; int b=20; System.out.println(a+b);
a ==> 10
b ==> 20
30
3. Create a class, create its object and call its methods;
jshell> class A{ public void show(){System.out.println("hello world");}}
| created class A
jshell> A a = new A();
a ==> A@3abbfa04
jshell> a.show();
hello world
All of these statements which we write and execute get stored in a file. We can edit that and store it as .java extension as per requirement.
1. To edit that file
jshell> /edit
2. To save the file
jshell> /save filename.java
3. To exit from Jshell
jshell> /exit
| Goodbye
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Neha Yadav
Neha is a creative person. She is having good knowledge of core java, advance java, hibernate,spring boot. She likes to solve puzzles, sudoku. She is a fun loving person.