How to instruct jshell
to terminate at the end of the script similarly to interpreters of other languages like for example python3
or node
?
Following command
./jshell -q /tmp/shell.java
with script /tmp/shell.java
System.out.println("Hello world");
prints
Hello world jshell>
and waits for further commands. I'd like it to stop immediately at the end of the file.
I'm looking for something more elegant than System.exit(0);
at the end of the script.
To exit JShell, type /exit .
To start JShell, enter the jshell command on the command line. JDK 9 must be installed on your system. If your path doesn't include java-home/jdk-9/bin , start the tool from within that directory.
Using MethodsA method is declared in JShell just as it is in a Java application, with a few differences, which are also discussed in this section. As an example, declare a method triple(int) that takes an int argument and returns an int value. Run the code snippet in JShell and a method gets created.
Inside the script, use the jshell command /exit
. This will exit jshell at the end of your script.
Check this reference https://docs.oracle.com/javase/9/jshell/introduction-jshell.htm#JSHEL-GUID-465BA4F5-E77D-456F-BCB7-D826AC1E18AE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With