0% found this document useful (0 votes)
17 views8 pages

Usage of JShell

JShell is an interactive tool introduced in Java 9 for learning Java and prototyping code, functioning as a Read-Evaluate-Print Loop (REPL). It simplifies the coding process by allowing users to enter and evaluate Java statements immediately without the need for a complete program structure. Users can start JShell via the command line and exit with the command '/exit', while it supports various Java snippets but has limitations on package statements and non-access modifiers.

Uploaded by

cocic79333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views8 pages

Usage of JShell

JShell is an interactive tool introduced in Java 9 for learning Java and prototyping code, functioning as a Read-Evaluate-Print Loop (REPL). It simplifies the coding process by allowing users to enter and evaluate Java statements immediately without the need for a complete program structure. Users can start JShell via the command line and exit with the command '/exit', while it supports various Java snippets but has limitations on package statements and non-access modifiers.

Uploaded by

cocic79333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

IT-31045

Programming language in Java

Java Shell Tool (Jshell)


Daw Win Pa Pa Phyo
Demonstrator
What is JShell?
2

 The Java Shell tool (JShell) is an interactive tool for learning the
Java programming language and prototyping Java code.

 JShell is a Read-Evaluate-Print Loop (REPL), which evaluates


declarations, statements, and expressions as they are entered and
immediately shows the results.

 The tool is run from the command line.

 Jshell was introduced in Java9.

12/12/2022
Why use Jshell?
3  Jshell has reduced all the efforts that are required to run a Java program
and test a business logic.

 Using JShell, you can enter program elements one at a time, immediately
see the result, and make adjustments as needed.

 If we don't use Jshell, creating of Java program involves the following


steps.
• Open editor and write program
• Save the program
• Edit if any compile time error
• Run the program
• Edit if any run time error 12/12/2022

• Repeat the process


 Jshell does not require above steps.
4
 We can evaluate statements, methods and classes, even can write hello
program without creating class.

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

12/12/2022
Start and exit JShell
5
 To start Jshell, open terminal in Linux or command prompt in
windows and type “jshell” . It will start jshell session and displays a
welcome message to the console.

 To exit JShell, enter command: ”/exit”

12/12/2022
Snippets
6
 JShell accepts Java statements; variable, method, and class
definitions; imports; and expressions. These pieces of Java code are
referred to as snippets.

 Trying Out Snippets

Snippets of Java code are entered into JShell and immediately


evaluated. Feedback about the results, actions performed, and any
errors that occurred is shown. Use the examples in this section to give
JShell a try.

12/12/2022
Don’t use in JShell
7
 Can't write Package Statement

 Can’t use non access modifier in top level of Jshell

12/12/2022
References link for JShell
8

 https://docs.oracle.com/javase/9/jshell/introduction-jshell.htm#JSHEL-
GUID-630F27C8-1195-4989-9F6B-2C51D46F52C8

 https://www.javatpoint.com/java-shell-tool

12/12/2022

You might also like