Java Magazine, July/August 2017
ORACLE COM JAVAMAGAZINE JULY AUGUST 2017 33 java 9 and so on You can also list all the variables methods and classes that are in the code Heres an example of listing all the variables vars String firstname Wolfgang String lastname Mozart double grade 00 If you decide to change the values of variables or edit a specific snippet you run edit with the snippet identifier for example edit 6 A dialog box as shown in Figure 2 appears to allow you to modify the value If I use the editor to change lastname to my last name I get the following result response lastname Drabo If I change the firstname to my first name then I can rerun the print out function by simply referring to the snippet identifier in this case 7 7 System out println Hello getStudentFullName firstname lastname Hello Constantin Drabo You can use the save command to save your snippets to a file and the open command allows you to open and run the file save StudentName jsh open StudentName jsh Hello Wolfgang Mozart Hello Constantin Drabo JShell also offers some keyboard shortcuts You can obtain the navigation history by using the up and down arrow keys And you can use the tab key to show you the options you have for the text youve typed so far a kind of IntelliSense feature Conclusion JShell has many possible uses The first is for beginners to try out Java code without having to write a full program In this sense it is a terrific learning tool Its also a great tool for trying out small functions validating that a web service is available and seeing what it returns and so on In addition its an excellent tool for trying out some quick layouts in JavaFX Whether it is used from the command line or programmatically JShell is likely to become one of the most widely used features of JDK 9 article Constantin Drabo is a software engineer living in Burkina Faso He is a NetBeans Dream Teamer and a Fedora Ambassador for the Fedora Project Drabo is also the founder of FasoJUG the first Java user group in Burkina Faso the former Upper Volta This article is a substantially updated version of the JShell 9 tutorial that appeared in the July August 2016 issue Ed Figure 2 The built in snippet editor
You must have JavaScript enabled to view digital editions.