JShell has a great collection of commands, descriptions available from the ‘/help’ command. However, sometimes the terse descriptions given in JShell itself are not quite enough. So, here is a somewhat complete list of JShell commands with descriptions for your viewing pleasure. For detailed knowledge of JShell please refer JShell with Example

/help or /? Command

Help command will give us details of available commands.

We can also get detailed help of particular command by typing /help /<keyword>

/list Command

List command will list all available resources followed with id.

/drop Command

Drop command delete a source entry referenced by name or id. As per example in /list command, Let’s delete first entry.

/save Command

Save all snippets source to a file.

Content of Test.txt file.

12+1 12+1 int y=8; void printHelloWorld(){System.out.println(“Hello World !!”);}
/open Command

We can also use txt file to load snippet in JShell, Open commad opens a file as source input

Content of Test.txt file

int z=10; int y=20;
/var Command

Var command list the declared variables and their values.

/method Command

Method command list the declared methods and their signatures.

/imports Command

Imports command will list all imports available in JShell.

/type Command

Type command list the declared types.

/exit Command
/env and /reset Command

Env command view or change the evaluation context. The evaluation context is the class path.

Using env command we can add third party libraries to classpath and can be used for further execution. Reset command unsets context.

/history Command

Hisory command shows what we have typed before.

/!, /<id> and /-<n> Commands

/! re-run last snippet, /<id> re-run snippet by id, /-<n> re-run n-th previous snippet

/edit Command

Edit a snippet or snippets of source in an external editor.

The editor to use is set with /set editor.If no editor has been set, a simple editor will be launched.

It's good to share...Share on FacebookTweet about this on TwitterShare on LinkedInPin on PinterestShare on Google+Email this to someone

One Thought on “Useful Commands in JShell – Java 9”

  • My brother recommended I might like this website. He was totally right.
    This post truly made my day. You can not imagine simply how much time I had spent
    for this information! Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *