Interactive Java (REPL) shell.

Interactive Java (REPL) shell.

For more stories.

When I started learning about the python I encounter with the interactive shell, which is a really cool feature to explore the API, prototyping then I feel why it is not in Java. But the answer is here. JDK 9 come with project kulla. What is the goal of project kulla? Master in Java9

The goal of the Kulla project is to investigate the creation of a
Read Evaluate Print Loop (REPL) tool for the Java programming

When my friend ask me why you love Java. I told them Java is rich. There is a native way to REPL (Read-eval-print loops). If you want to checkout quickly the System.out.print(“Hello world”); then you have to create a separate project. JShell has emerged a powerful tool introduced in JDK9.

JShell is playground, on playground you can play cricket, football or whatever you want.

JShell is deeply integrated with JDK. JShell is tightly integrated with the Java compiler and Java virtual machine, JShell enhances the programming experience for the Java language. You can test your code as you create it, and way before you are done with your whole project. JShell is simple UNIX shell it will read instruction set, evaluate them & present the outcome.

JShell’s Advantages.

  1. It reduces the Java learning curve
  2. Start expression rather with classes.
  3. Immediate feedback & easy understanding.
  4. Explore new API, experiment, instantly get a result.
  5. Incrementally write complex code.

JShell takes two kinds of inputs

  1. Java code “Snippets” — snippet is small chunks of code.
  2. JShell Commands.

Experience without theory is blind, but theory without experience is mere intellectual play.

Let’s experience the JShell & interact with the project kulla. Get your hands dirty.

For downloading the JDK9 click here.

For mac os multiple JDK path. Please go through this.

  1. Download latest JDK build
  2. set the Java_Home path & check java version

3) Open terminal/ command prompt type jshell.

If Jshell not open then I have a trick for mac os redirect to the below path


The world is your playground. Why aren’t you playing? Let us play.

Let’s play and enjoy. If you are the wrong jshell will give you the meaningful message. Please look below message ” it created variable all, it cannot be referenced until class lists are declared”.

You can declare, define & call a method from jshell.

JShell Commands

List of JShell commands

/help — to get the list of commands.

| /list [<name or id>|-all|-start] — list the source you have typed

| /edit <name or id> — edit a source entry referenced by name or id

| /drop <name or id> — delete a source entry referenced by name or id
| /save [-all|-history|-start] <file> — Save snippet source to a file.
| /open <file> — open a file as source input
| /vars [<name or id>|-all|-start] — list the declared variables and their values
| /methods [<name or id>|-all|-start] — list the declared methods and their signatures
| /types [<name or id>|-all|-start] — list the declared types
| /imports — list the imported items
| /exit — exit jshell
| /reset — reset jshell
| /reload [-restore] [-quiet] — reset and replay relevant history — current or previous (-restore)
| /classpath <path> — add a path to the classpath
| /history — history of what you have typed
| /help [<command>|<subject>] — get information about jshell
| /set editor|start|feedback|mode|prompt|truncation|format … — set jshell configuration information
| /retain editor|start|feedback|mode — retain jshell configuration information for subsequent sessions
| /? [<command>|<subject>] — get information about jshell
| /! — re-run last snippet
| /<id> — re-run snippet by id
| /-<n> — re-run n-th previous snippet

| intro — an introduction to the jshell tool
| shortcuts — a description of shortcuts

For example ‘/help intro’.

Then play and enjoy. Thanks for reading.

If you found this post is helpful, recommend it to others.

For more stories.

If you enjoyed this article, please don’t forget to Clap.