Java jshell REPL: Rapid Code Testing with Interactive Environment
🧠 What Will You Learn in This Guide?
This guide introduces the jshell tool that comes with Java 9.
JShell is an interactive Java shell that works with the Read–Evaluate–Print–Loop (REPL) approach.
You can test Java expressions in a single line and run small pieces of code instantly, without the need for an IDE.
💡 Why jshell?
For many years, Java has been criticized for "not being able to run code without compiling".
While REPL environments offered by languages such as Scala and Python accelerate the learning process, this opportunity was not available in Java.
jshell, which came with Java 9, exactly fixed this deficiency.
Advantages:
- Testing code without writing
public static void main - Quick expression execution without semicolons
- Ability to define instant variables and calculate
- Code block, class or method tests
⚙️ 1. How to Start jshell?
If Java 9 or higher is installed, type the following command in the terminal:
jshell
Output:
| Welcome to JShell -- Version 9
| For an introduction type: /help intro
jshell>
This interface is an interactive environment where you can now directly write and run Java expressions.
🧩 2. Running Simple Expressions
Test variables or expressions without the need for the classic public class structure:
jshell> System.out.println("Merhaba GenixNode Geliştiricileri")
Merhaba GenixNode Geliştiricileri
jshell> String projeAdi = "GenixNodeCloud-TR"
projeAdi ==> "GenixNodeCloud-TR"
jshell> int sayac = 5
sayac ==> 5
jshell> sayac++
$6 ==> 5
jshell> sayac
sayac ==> 6
💬 Note: In simple expressions; It is not mandatory, but should be used in complex blocks of code.
🧱 3. Class and Method Definition
jshell supports not only expressions but also class and method definitions:
jshell> class Uygulama {
...> public static void mesajVer() {
...> System.out.println("Uygulama Basladi");
...> }
...> }
| created class Uygulama
jshell> Uygulama.mesajVer()
Application Started 💡 This example shows that a class can be created directly in memory without compiling.
🔍 4. Help and Exit Commands
To see all jshell commands:
/help
To log out:
/exit
Alternatively, you can use the Ctrl + D shortcut.
🧭 5. Frequently Asked Questions (FAQ)
- Is an IDE required to use jshell?
No. jshell runs directly on the command line and does not require an IDE.
- Why was REPL added to Java?
It was aimed to have the interactive code testing environment offered by languages such as Scala in Java.
- Is the semicolon always necessary?
No, it is unnecessary in simple expressions. However, it is recommended for complex structures or loops.
- Which Java version does jshell come with?
It is available by default in Java 9 and above.
- Can jshell be used in large projects?
No, jshell is for quick tests. Real projects require an IDE or build system.
🚀 Conclusion
jshell is a powerful tool that accelerates the learning process of Java developers. Provides instant feedback, perfect for small tests.
To test new features and Java versions in a secure environment, you can create your own virtual server (instance) on the GenixNode platform and instantly try the innovations of Java 9 and later.

