
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
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";
- Related Articles
- How to save the current JShell session in Java 9?
- How to load a file into the JShell session in Java 9?
- How to debug JShell in Java 9?
- JShell in Java 9?
- How to get JShell documentation 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 the encapsulation concept in JShell in Java 9?
- How to implement the Fibonacci series in JShell in Java 9?
- How to modify the default editor of JShell in Java 9?
- How to create a thread in JShell 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?
- How to implement a String in JShell in Java 9?

Advertisements