title | description | created | updated |
---|---|---|---|
JShell |
JShell cheatsheet contains useful code syntax with examples which is handy while coding. |
2020-04-26 |
2020-04-26 |
Jshell is Java’s first official REPL (READ-EVAL-PRINT-LOOP) tool which provides interactive use of Java Programming Language elements.
When you evaluate any valid java expression, the result will be stored in the system defined variables.
datatype variable name = value;
-
To launch Jshell tool
jshell
-
To exit Jshell
exit
-
To list all the declared variables.
/vars /vars <variableName> /vars <variableSnippetId> /vars -start /vars -all
jshell> /vars | String name = "OneCompiler" | int id = 1
-
To list all the declared Methods
/methods /methods <methodName> /methods <methodSnippetId> /methods -start /methods -all
jshell> /methods | double sum(int,int)
-
To displays classes, interfaces, and enums
/types /types <typeName> /types <typeSnippetId> /types -start /types -all
-
To see a list all the snippets
/list /list -all /list -start /list <snippetName> /list <snippetId>
-
To save your snippets
/save
-
To personalize your startup entries
/set start
-
To get help about the list of the JShell commands.
/help
-
To edit code of a method
/edit method-name
-
To load Code from External Java File into REPL:
/open filename.java
You can also provide directory information along wwith filename.java if the file is present in different directory like
/open c:\\Documents\\filename.java
-
To Drop a Snippet
/drop <snippetName> /drop <snippetId>