Skip to content

Instantly share code, notes, and snippets.

jshell> /help
| Type a Java language expression, statement, or declaration.
| Or type one of the following 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>
jshell> /drop sayHello
| dropped method sayHello(String)
jshell> /edit HelloPrinter
| modified class HelloPrinter
jshell> String sayHello(String name) {return "hello "+ name;}
| created method sayHello(String)
jshell> sayHello("readers of the blog")
$2 ==> "hello readers of the blog"
jshell> /methods
| String sayHello(String)
jshell> class HelloPrinter{ public static void sayHello(){System.out.println("hello readers of the blog");}}
jshell> /l
1 : 1+1
2 : int x = 1+1;
3 : System.out.println(x)
4 : Thread.sleep(5000)
5 : import java.time.*;
6 : ZonedDateTime.now()
jshell> /vars
| int $1 = 2
| int x = 2
| ZonedDateTime $7 = 2017-10-12T14:55:59.309666-04:00[America/Toronto]
jshell> /list
1 : 1+1
2 : int x = 1+1;
3 : System.out.println(x)
jshell> ZonedDateTime.now()
| Error:
| cannot find symbol
| symbol: variable ZonedDateTime
| ZonedDateTime.now()
| ^-----------^
jshell> import java.time.*
jshell> ZonedDateTime.now()
jshell> /imports
| import java.io.*
| import java.math.*
| import java.net.*
| import java.nio.file.*
| import java.util.*
| import java.util.concurrent.*
| import java.util.function.*
| import java.util.prefs.*
| import java.util.regex.*
jshell> Thread.sleep(5000)
@mcupak
mcupak / statement-jshell.out
Created October 13, 2017 21:29
Evaluating a simple statement in JShell.
jshell> System.out.println(x)
2
@mcupak
mcupak / explicit-variable-jshell.out
Created October 13, 2017 21:28
Using explicit variables in JShell.
jshell> int x = 1+1
x ==> 2