What is JShell?

JShell is a new tool introduced with Java 9. It is an interactive read-eval-print loop tool that is used to evaluate the following Java programming language components--declarations, statements, and expressions. It has its own API so that it can be used by external applications.

Read-Eval-Print Loop is often referred to as REPL, taking the first letter from each word in the phrase. It is also knows language shell or interactive top-level.

The introduction of JShell was a result of Java Enhancement Program (JEP) 222. Here are the stated goals of this JEP in regards to the Java Shell command-line tool:

  • Facilitate rapid investigation
  • Facilitate rapid coding
  • Provide an edit history

The rapid investigation and coding listed previously includes statements and expressions. Impressively, these statements and expressions do not need to be part of a method. Furthermore, variables and methods are not required to be part of a class, making this tool especially dynamic.

In addition, the following listed features were included to make JShell much easier to use and to make your time using JShell as time-efficient as possible:

  • Tab-completion
  • Auto-completion for end-of-statement semicolons
  • Auto-completion for imports
  • Auto-completion for definitions