
- 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
What are the different "/edit" commands in JShell in Java 9?
JShell is a command-line tool introduced in Java 9 that evaluates declarations, statements, and expressions without the main() method. JShell can set up a text editor called JShell Edit Pad, which allows us to modify the code very easily, and it can be launched using the "/edit" command.
Below are the different "/edit" commands used in Jshell.
/edit /edit [ID] /edit [Code_Name]
- /edit: This command can be used without an argument, the "/edit" command displays all the active code in the text editor.
- /edit [ID]: This command displays in the text editor the code corresponding to the ID entered.
- /edit [Code_Name]: This comamnd displays in the text editor the code corresponding to the name entered.
jshell> int i = 10 i ==> 10 jshell> double j = 20.0 j ==> 20.0 jshell> public int sum(int x, int y) { ...> return x + y; ...> } | created method sum(int,int) jshell> /edit
In the above, we create integer i, double y along with a method called “sum”. By entering the "/edit" command, it displays "JShell Edit Pad" as below.
We can use the editor to add or modify code and validate the set with the Accept button. We can add a new divide() method and modify the value of the variable "y" as below
jshell> int i = 10 i ==> 10 jshell> double j = 20 j ==> 20.0 jshell> public int sum(int x, int y) { ...> return x + y; ...> } | created method sum(int,int) jshell> /edit j ==> 50.0 | created method divide(double,double)
If we want to display only the variable "i" in JShell Edit Pad, just type the command "/edit i", and it displays 10. In the same way, if we want to modify only the text of "ID 2" (corresponding to the variable y), just enter the command "/edit 2", and it displays 20.
- Related Articles
- What are the different "/types" commands in JShell in Java 9?
- What are the different "/vars" commands in JShell in Java 9?
- What are the useful commands in JShell in Java 9?
- How to display different list commands in JShell in Java 9?
- What are the different shortcut keys in JShell in Java 9?
- What are the different feedback modes in JShell in Java 9?
- What are the different startup scripts in JShell in Java 9?
- How to save, edit, and drop a snippet in JShell in Java 9?
- What are the rules for external declarations in JShell in Java 9?
- JShell in Java 9?
- What are the different commands used in MySQL?
- What are the rules we need to follow in JShell in Java 9?
- What are the different module types in Java 9?
- What is a forward reference in JShell in Java 9?
- What is the use of the Tab key in JShell in Java 9?
