1. How to run Jshell
get a command prompt windows key + R --> type cmd
2. Check java version, should be higher than 9
java -version
3. type "jshell"
4. Now you can write syntax and check validity , edit and play on with this
5. /help --> help command
6. /list --> will list the command typed/executed
7. edit use edit command with command number, number you can select using /list . Once you use edit, it will prompt with shell to edit.
/edit 2
Below you I have attached series of commands i tried with all mistakes
----------------------------------------------------------------------------------------------------------------------
Microsoft Windows [Version 10.0.22621.2715]
(c) Microsoft Corporation. All rights reserved.
C:\Users\USR>java -version
openjdk version "21" 2023-09-19
OpenJDK Runtime Environment Zulu21.28+85-CA (build 21+35)
OpenJDK 64-Bit Server VM Zulu21.28+85-CA (build 21+35, mixed mode, sharing)
C:\Users\USR>jshell
| Welcome to JShell -- Version 21
| For an introduction type: /help intro
jshell> System.out.println("Hello");
Hello
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
| /drop <name or id>
| delete a source entry
| /save [-all|-history|-start] <file>
| Save snippet source to a file
| /open <file>
| open a file as source input
| /vars [<name or id>|-all|-start]
| list the declared variables and their values
| /methods [<name or id>|-all|-start]
| list the declared methods and their signatures
| /types [<name or id>|-all|-start]
| list the type declarations
| /imports
| list the imported items
| /exit [<integer-expression-snippet>]
| exit the jshell tool
| /env [-class-path <path>] [-module-path <path>] [-add-modules <modules>] ...
| view or change the evaluation context
| /reset [-class-path <path>] [-module-path <path>] [-add-modules <modules>]...
| reset the jshell tool
| /reload [-restore] [-quiet] [-class-path <path>] [-module-path <path>]...
| reset and replay relevant history -- current or previous (-restore)
| /history [-all]
| history of what you have typed
| /help [<command>|<subject>]
| get information about using the jshell tool
| /set editor|start|feedback|mode|prompt|truncation|format ...
| set configuration information
| /? [<command>|<subject>]
| get information about using the jshell tool
| /!
| rerun last snippet -- see /help rerun
| /<id>
| rerun snippets by ID or ID range -- see /help rerun
| /-<n>
| rerun n-th previous snippet -- see /help rerun
|
| For more information type '/help' followed by the name of a
| command or a subject.
| For example '/help /list' or '/help intro'.
|
| Subjects:
|
| intro
| an introduction to the jshell tool
| keys
| a description of readline-like input editing
| id
| a description of snippet IDs and how use them
| shortcuts
| a description of keystrokes for snippet and command completion,
| information access, and automatic code generation
| context
| a description of the evaluation context options for /env /reload and /reset
| rerun
| a description of ways to re-evaluate previously entered snippets
jshell>
/list
1 : System.out.println("Hello");
jshell> void printMessage(){
...> System.out.print;n("Hello")
...> }
| Error:
| not a statement
| System.out.print;n("Hello")
| ^--------------^
| Error:
| ';' expected
| System.out.print;n("Hello")
| ^
jshell> printMessage()
| Error:
| cannot find symbol
| symbol: method printMessage()
| printMessage()
| ^----------^
jshell> /lsit
| Invalid command: /lsit
| Type /help for help.
jshell> /list
1 : System.out.println("Hello");
jshell>
void printMessage(){
...> System.out.print;n("Hello");
...> }
| Error:
| not a statement
| System.out.print;n("Hello");
| ^--------------^
| Error:
| cannot find symbol
| symbol: method n(java.lang.String)
| System.out.print;n("Hello");
| ^
jshell> void printMessage(){
...> System.out.println("Hello");
...> }
| created method printMessage()
jshell> printMessage
| Error:
| cannot find symbol
| symbol: variable printMessage
| printMessage
| ^----------^
jshell> printMessage()
Hello
jshell> /list
1 : System.out.println("Hello");
2 : void printMessage(){
System.out.println("Hello");
}
3 : printMessage()
jshell> edit 2
| Error:
| ';' expected
| edit 2
| ^
| Error:
| cannot find symbol
| symbol: variable edit
| edit 2
| ^--^
jshell> /edit 2
| modified method printMessage()
jshell> printMessage()
Hello Edited
jshell>
No comments:
Post a Comment