On my ubuntu system the installation was quite easy:
# apt-get install openjdk-9-jdk-headlessand you can find
$ ls /usr/lib/jvm/java-9-openjdk-amd64/bin/(in the third column, sixth row: jshell)
idlj jcmd jmap jstatd schemagen
jar jdb jmod keytool serialver
jarsigner jdeps jps orbd servertool
java jhsdb jrunscript pack200 tnameserv
javac jimage jsadebugd policytool unpack200
javadoc jinfo jshell rmic wsgen
javah jjs jstack rmid wsimport
javap jlink jstat rmiregistry xjc
After a startup jshell comes up with this prompt:
$ /usr/lib/jvm/java-9-openjdk-amd64/bin/jshellThe most important command is
| Welcome to JShell -- Version 9-internal
| For an introduction type: /help intro
->
/exitto leave the jshell (Strg-C works also, but i think /exit should be used).
There is no syntax highlighting but this does not matter.
The following builtin commands are allowed:
-> /helpWith /list the source code, which you provided, is shown:
| Type a Java language expression, statement, or declaration.
| Or type one of the following commands:
| /list [all|start|] -- list the source you have typed
| /edit-- edit a source entry referenced by name or id
| /drop-- delete a source entry referenced by name or id
| /save [all|history|start]-- Save snippet source to a file.
| /open-- open a file as source input
| /vars -- list the declared variables and their values
| /methods -- list the declared methods and their signatures
| /classes -- list the declared classes
| /imports -- list the imported items
| /exit -- exit jshell
| /reset -- reset jshell
| /reload [restore] [quiet] -- reset and replay relevant history -- current or previous (restore)
| /classpath-- add a path to the classpath
| /history -- history of what you have typed
| /help [| ] -- get information about jshell
| /set editor|start|feedback|newmode|prompt|format ... -- set jshell configuration information
| /? [| ] -- get information about jshell
| /! -- re-run last snippet
| /-- re-run snippet by id
| /--- re-run n-th previous snippet
|
| For more information type '/help' followed by the name of command or a subject.
| For example '/help /list' or '/help intro'. Subjects:
| intro -- an introduction to the jshell tool
| shortcuts -- a description of shortcuts
-> /list 5
5 : class MyClass {
private int a;
public MyClass(){a=0;}
int getA() {return a;};
void setA(int var) {a=var; return;}
}
Everytime you create an Object, you will see the following:
-> ZZ = new MyClass();With /vars the variables are shown:
| Variable ZZ has been assigned the value MyClass@28d25987
-> ZZ.getA();
| Expression value is: 0
| assigned to temporary variable $8 of type int
-> ZZ.setA(200);
-> ZZ.getA();
| Expression value is: 200
| assigned to temporary variable $10 of type int
-> /varsListing the classes (ok it is getting boring):
| MyClass ZZ = MyClass@28d25987
| int $8 = 0
| int $10 = 200
-> /classesand last but not least /methods:
| class MyClass
-> /methods
| printf (String,Object...)void
| getA ()int
No comments:
Post a Comment