- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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?
85 Lectures 6 hours
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";
- How to save the current JShell session in Java 9?
- How to load a file into the JShell session in Java 9?
- JShell in Java 9?
- How to debug JShell in Java 9?
- How to get JShell documentation in Java 9?
- How to implement the encapsulation concept in JShell in Java 9?
- How to implement the Fibonacci series in JShell in Java 9?
- How to create JShell instance programmatically in Java 9?
- How to implement java.time.LocalDate using JShell in Java 9?
- How to implement JShell using JavaFX in Java 9?
- How to modify the default editor of JShell in Java 9?
- How JShell tool works internally in Java 9?
- How to import external libraries in JShell in Java 9?
- How to handle an exception in JShell in Java 9?
- How to create scratch variables in JShell in Java 9?