visit
Starting JShell
Once you are on NetBeans head over to the tab called Tools. Select Open Java Platform Shell from it./
help
This will enlist a number of commands that you can type with their usage. You can type in :/list -start
This will enlist all the packages that are imported by default as soon as you start a JShell. You can simply import all the other packages if you want to use them. Similarly, one can declare variables simply as it is done in a simple Java code snippet. System.out.println statement can be used to print the values of the variables. A thing to note here would be that a variable type has to be declared by the user and will not be declared automatically by JShell.
Implicit variables
Implicit variables are variables automatically defined by JShell and this is a unique JShell feature. In a simple Java code, you cannot implicitly declare variables. Howevr, in JShell if you simply write ‘1’, it will create a variable $1 implicitly. Also, when you operate, JShell implicitly creates a variable to store the result of the operation. For example, if you write ‘1 + 2’, JShell will implicitly create a variable $4 ==> 3. You can also use implicit variables normally, for example $1 + $4 is allowed. A string literal like “Hello World” will also invoke implicit variables and the variable can be used in another code snippet to be printed or used. Adding integers with decimals and such operations where widening of data types comes into picture, implicit variables play an important role. Remember how /list lists all the code snippets? Similarly /vars lists all the variables. A tip to remember would be that JShell does not allow the top level variables to be static or final. If you try to do so, a warning will be generated. While the variable will be nevertheless created, it won’t be static or final in nature.JShell is not an IDE
So that is all for the very basics. Once you start using JShell, you will get the gist of how to make the most of it. It’s a powerful tool for agile development and is a boon to all Java Developers. However, one should never confuse it for an IDE (Integrated Development Environment). To simulate a complete project, or to develop an application one can never rely on JShell. It is only a tool that aids a developer. Here, Netbeans is an IDE and JShell is an ‘application/command’ on its own. JShell is a new feature in JDK9 and NetBeans 9. If you wish to use it, update your NetBeans to the latest version and get started. There isn’t much to learn afresh when dealing with JShell – just a few no-nos to keep in mind and a couple of new and exciting features to explore – and that is what makes JShell so much fun and useful. Sources: