JSHELL(1) JDK Commands JSHELL(1) (NAME) jshell - Java -- (REPL) (SYNOPSIS) jshell [options] [load-files] options . Options for jshell . load-files . JShell . : DEFAULT import . JAVASE Java SE (import) . PRINTING print println printf jshell . TOOLING javac jar JDK jshell . . . . JShell /open . / (-) load-files . jshell (pipe chains) . JShell Java API . Java import . (snippet) . . . . verbose . JShell . JShell . JShell . . . JSHELL (OPTIONS FOR JSHELL) --add-exports module/package (exported) . --add-modules module[,module...] (resolve) . -Cflag . . --class-path path . CLASSPATH . . Linux macOS (:) . Windows - (;) . --enable-preview (preview features) . --execution specification specification ExecutionControl . jdk.jshell.spi . --feedback mode . /set feedback mode . normal . mode : verbose . . (prompt) . normal . . concise . . silent . . custom . JShell /set mode . --help -h -? . --help-extra -X . . -Jflag (runtime) . . --module-path modulepath . Linux macOS (:) . Windows - (;) . --no-startup JShell . JShell JShell ( ) . --startup . -q concise --feedback concise . -Rflag . . -s silent --feedback silent . --show-version . --startup file . . : DEFAULT import . JAVASE Java SE import . PRINTING print println printf jshell . TOOLING javac jar JDK jshell . . JShell /reset /reload /env . . --no-startup . -v verbose --feedback verbose . --version ..SH " JSHELL (JSHELL COMMANDS)" jshell . /drop {name|id|startID-endID} [{name|id|startID-endID}...] (ID) . . . /list . /edit [option] . . : {name|id|startID-endID} [{name|id|startID-endID}...] . . . /list . -all . -start JShell . -wait (prompt) . /set editor . : JSHELLEDITOR VISUAL EDITOR. JShell . /env [options] (session) . . : o . o . o . o ( ) . /drop jshell /open . /reset /env /reload option . : --add-modules module[,module...] (resolve) . --add-exports source-module/package=target-module[,target-module]* (export) package source-module target-module . --class-path path . CLASSPATH . . Linux macOS (:) . Windows (;) . --module-path modulepath . Linux macOS (:) . Windows (;) . /exit [integer-expression-snippet] . . . . /history . /help [command|subject] . . . . subject : context . intro . shortcuts . Input Shortcuts . /imports (imports) JShell . /list [option] . . : {name|id|startID-endID} [{name|id|startID-endID}...] . . . -all . s . e . -start JShell . /methods [option] . . : {name|id|startID-endID} [{name|id|startID-endID}...] . . . /list . -all JShell ..TP -start JShell . /open file . : DEFAULT (imports) . JAVASE Java SE . PRINTING print println printf jshell . TOOLING javac jar JDK jshell . /reload [options] : o ( ) . o . o . o . /drop jshell /open . /reset /env /reload option . : --add-modules module[,module...] . --add-exports source-module/package=target-module[,target-module]* (export) package source-module target-module . --class-path path . CLASSPATH . . Linux macOS (:) . Windows (;) . --module-path modulepath . Linux macOS (:) . Windows (;) . -quiet . . -restore /reset /reload /env . . JShell . /reset [options] : o ( ) . o . o . . . /reset /env /reload option . : --add-modules module[,module...] . --add-exports source-module/package=target-module[,target-module]* (export) package source-module target-module . --class-path path . CLASSPATH . . Linux macOS (:) . Windows (;) . --module-path modulepath . Linux macOS (:) . Windows (;) . /save [options] file . . : {name|id|startID-endID} [{name|id|startID-endID}...] (ID) . . . /list . -all . -history . -start . . /set [setting] (feedback mode) . (prompt) (truncation) . . setting : editor [options] [command] /edit . . . : -default JShell . ..TP -delete . -retain : JSHELLEDITOR VISUAL EDITOR. . . -retain . . -wait . JShell . . . feedback [mode] . . : concise normal silent verbose /set mode. format mode field "format-string" selector . . . . : mode . /set mode . field . /help /set format JShell . "format-string" (selector) . /help /set format JShell . selector . /help /set format JShell . mode [mode-name] [existing-mode] [options] . (prompt) (truncation) . . : -command|-quiet . . -command . -quiet . -delete . . -retain . . -retain . . /set prompt /set format /set truncation . /set feedback . prompt mode "prompt-string" "continuation-prompt-string" JShell . . . : mode . /set mode . "prompt-string" . "continuation-prompt-string" . start [-retain] [file [file...]|option] /reset /reload /env . . . : DEFAULT (imports) . JAVASE Java SE . PRINTING print println printf jshell . TOOLING javac jar JDK jshell . : -default . -none . -retain . truncation mode length selector . . . (truncation) : mode (feedback mode) . /set mode . length (selector) . selector (context) . JShell /help /set truncation . /types [option] (interfaces) (enums) . . : {name|id|startID-endID} [{name|id|startID-endID}...] (ID) . . (space) . /list (snippets) . -all JShell . -start JShell . /vars [option] . . : {name|id|startID-endID} [{name|id|startID-endID}...] . . . /list . -all JShell . -start JShell . /? /help . /! . /{name|id|startID-endID} [{name|id|startID-endID}...] . . . . /list . /-n -n . /-4 . ..SH " (INPUT SHORTCUTS)" JShell . (Tab completion) Tab . . Tab . . Tab . Tab . Shift+ V (variable declaration) . Shift+ M (method declaration) . . Shift+ I (resolve) (imports) (class path) . (Command abbreviations) . /l /list . /s /set /save. /se /set /sa /save . . /m -a . (History navigation) . . Ctrl . (History search) Ctrl+R . . Ctrl+R . Ctrl+S . (INPUT EDITING) JShell . . Ctrl Meta . Meta Alt Meta . -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Return . . . Ctrl+A . Ctrl+E . Meta+B . Meta+F . Delete . Backspace . Ctrl+K . Meta+D . Ctrl+W (white space) . Ctrl+Y (paste). Meta+Y Ctrl+Y . " JSHELL (EXAMPLE OF STARTING AND STOPPING A JSHELL SESSION)" JShell JDK . jshell . . % jshell | Welcome to JShell -- Version 9 | For an introduction type: /help intro jshell> JShell /list -start . import . (ID) s (startup) . jshell> /list -start s1 : import java.io.*; s2 : import java.math.*; s3 : import java.net.*; s4 : import java.nio.file.*; s5 : import java.util.*; s6 : import java.util.concurrent.*; s7 : import java.util.function.*; s8 : import java.util.prefs.*; s9 : import java.util.regex.*; s10 : import java.util.stream.*; jshell> /exit . jshell> /exit | Goodbye % " (EXAMPLE OF ENTERING SNIPPETS)" Java import (expressions) . (semicolon) . . (scratch variable) . jshell> int a=4 a ==> 4 jshell> int b=8 b ==> 8 jshell> int square(int i1) { ...> return i1 * i1; ...> } | created method square(int) jshell> square(b) $5 ==> 64 " (EXAMPLE OF CHANGING SNIPPETS)" . : jshell> String grade(int testScore) { ...> if (testScore >= 90) { ...> return "Pass"; ...> } ...> return "Fail"; ...> } | created method grade(int) jshell> grade(88) $3 ==> "Fail" grade 80 . if . : jshell> String grade(int testScore) { ...> if (testScore >= 80) { ...> return "Pass"; ...> } ...> return "Fail"; ...> } | modified method grade(int) jshell> grade(88) $5 ==> "Pass" /edit . JShell . . /list 85 . jshell> /edit grade | modified method grade(int) jshell> /list grade 6 : String grade(int testScore) { if (testScore >= 85) { return "Pass"; } return "Fail"; } " (EXAMPLE OF CREATING A CUSTOM FEEDBACK MODE)" (feedback mode) (prompt) . . . /set mode . mymode normal : jshell> /set mode mymode normal -command | Created new feedback mode: mymode normal . . JShell . . jshell> /set prompt mymode | /set prompt mymode "\njshell> " " ...> " jshell> /set prompt mymode "\nprompt$ " " continue$ " (truncation) . . 72 500 : jshell> /set truncation mymode 72 jshell> /set truncation mymode 500 varvalue (format) . normal created . defined : jshell> /set format mymode action "defined" added-primary /set feedback . : jshell> /set feedback mymode | Feedback mode: mymode prompt$ int square (int num1){ continue$ return num1*num1; continue$ } | defined method square(int) prompt$ JDK 21 2023 JSHELL(1)