Jshell REPL in Java
Jshell is a REPL(Real-Eval-Print-Loop) tool introduced in Java. Jshell provides a shell for evaluating Java expressions and statements. Jshell is used for experimenting with Java code, new features and learning Java programming.
Steps of stating Jshell
- Install JDK 9 or Latest: Download JDK from the Oracle website. And install in the system.
- Open the Terminal/ Command Prompt: Open Command Prompt using CMD or using VS code terminal.
- Launch Jshell: Type Jshell in terminal and enter.
Basic Commands
Get Sachin Mahor’s stories in your inbox
Join Medium for free to get updates from this writer.
Starting Jshell
C:\Users\DEll>jshell
| Welcome to JShell -- Version 20.0.1
| For an introduction type: /help introEvaluation
jshell> 5 + 2
$1 ==> 7
jshell> String name = "Sachin Mahor"
name ==> "Sachin Mahor"Creating Method
jshell> int sum(int a, int b){
...> return a + b;
...> }
| created method sum(int,int)
jshell> sum(10, 20);
$4 ==> 30Check Variable
jshell> /vars
| int $1 = 7
| String name = "Sachin Mahor"
| int $4 = 30Importing Package
jshell> List<String> names = Arrays.asList("Raju", "Kamal", "Pinki");
names ==> [Raju, Kamal, Pinki]
jshell> for(String name: names){
...> System.out.println(name);
...> }
Raju
Kamal
PinkiExiting fro Jshell
jshell> /exit
| Goodbye Jshell is a tool for testing the java code without writing whole code. You can read more about Jshell. There are lot more commands.







