 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to reset the JShell session in Java 9?
Java 9 has introduced JShell for Java, and it allows us to evaluate code snippets such as declarations, statements, and expressions.
During the JShell session, we need to reset it without closing and re-opening JShell then we can use the internal command: "/reset". By using this command, code entered during the current session has erased. It can be useful when we want to test new classes, create new variables, etc. while keeping the names previously used.
In the below snippet, we have created variables x, y, and str. We can able to see all entered code snippets using the "/list" command. After that, we can apply the "/reset" command to reset the current session.
jshell> int a = 25 a ==> 25 jshell> double y = 30 y ==> 30.0 jshell> String str = "Tutorialspoint" str ==> "Tutorialspoint" jshell> /list 1 : int a = 25; 2 : double y = 30; 3 : String str = "Tutorialspoint"; jshell> /reset | Resetting state. jshell> /list jshell> x | Error: | cannot find symbol | symbol: variable x | x | ^ jshell> str | Error: | cannot find symbol | symbol: variable str | str | ^-^ jshell> int x = 15 x ==> 15 jshell> String str = "reset" str ==> "reset" jshell> /list 1 : int x = 15; 2 : String str = "reset";
Advertisements
 