JShell Guide

This guide covers most aspects of the jshell. I distilled it from playing around with jshell and poking around in the jshell source code. Some parts of this guide, especially the section ‘feedback mode’ and searching through the history, draw on Robert Field’s JShell Manual, which is definitely worth checking out. The link to it is in the ‘reference’ section.

JShell guide

intro

created onJanuary 28, 2022
The jshell is a great tool for exploring libraries, testing new features of Java and for explorative programming in general....

JShell guide

snippets

created onJanuary 28, 2022
jshell accepts the following JLS syntax: Statements Expressions Variable, Method, Class and Interface...

JShell guide

history

created onJanuary 28, 2022
history jshell maintains a history that includes all previously entered commands and snippets...

JShell guide

variables

created onJanuary 28, 2022
Variables can be explicitly declared. For expression that don’t have a named variable, an implicit variable...

JShell guide

imports

created onJanuary 28, 2022
On startup, jshell imports a bunch of Java packages by default. Imported packages can be listed with...

JShell guide

methods, classes and interfaces

created onJanuary 28, 2022
Inside methods, classes and interfaces, statements have to end with a semicolon...

JShell guide

working with the classpath

created onJanuary 28, 2022
In order to be able to access classes in libs or class files that are not part of the JDK, the classpath must be set...

JShell guide

modules

created onJanuary 28, 2022
In order to be able to access modules that are not part of the JDK, the module path must be set according to the...

JShell guide

exception handling

created onJanuary 28, 2022
If a snippet throws an exception, jshell prints the exception together with the snippet id that caused the exception...

JShell guide

tab completion

created onJanuary 28, 2022
Tab completion works for commands, command parameters, variables, methods, classes and interfaces...

JShell guide

feedback modes

created onJanuary 28, 2022
available feedback modes JShell comes with four built-in feedback modes, listed in the table below...

JShell guide

script files

created onJanuary 28, 2022
A jshell script file is a sequence of jshell commands and/or snippets, one command or snippet per line...

JShell guide

configuration

created onJanuary 28, 2022
the jshell configuration file On Linux systems, the startup configuration is written to the file ~/....

JShell guide

reference

created onJanuary 28, 2022
last modified onMarch 26, 2022
some of the information presented in this series JShell guide stems from the following references:...