

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
What are the different "/edit" commands in JShell in Java 9?
<p><strong>JShell </strong>is a command-line tool introduced in <strong>Java 9</strong> that evaluates declarations, statements, and expressions without the <strong>main()</strong> method. JShell can set up a text editor called <strong>JShell Edit Pad</strong>, which allows us to modify the code very easily, and it can be launched using the "<strong>/edit</strong>" command.</p><p>Below are the different "<strong>/edit</strong>" commands used in Jshell.</p><pre class="prettyprint notranslate"><strong>/edit /edit [ID] /edit [Code_Name]</strong></pre><ul class="list"><li><strong>/edit:</strong> This command can be used without an argument, the "/edit" command displays all the active code in the text editor.</li><li><strong>/edit [ID]:</strong> This command displays in the text editor the code corresponding to the ID entered.</li><li><strong>/edit</strong> <strong>[Code_Name]:</strong> This comamnd displays in the text editor the code corresponding to the name entered.</li></ul><pre class="prettyprint notranslate" style=""><strong>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</strong></pre><p>In the above, we create integer i, double y along with a method called “<strong>sum</strong>”. By entering the "<strong>/edit</strong>" command, it displays "<strong>JShell Edit Pad</strong>" as below.</p><p><img src="https://www.tutorialspoint.com/assets/questions/media/37354/jshell_edit1.PNG" class="fr-fic fr-dib" style="width:527px;height:277px" width="527" height="277"></p><p>We can use the editor to <strong>add </strong>or <strong>modify </strong>code and validate the set with the <strong>Accept </strong>button. We can add a new <strong>divide()</strong> method and modify the value of the variable <strong>"y"</strong> as below</p><p><img src="https://www.tutorialspoint.com/assets/questions/media/37354/jshell_edit2.PNG" class="fr-fic fr-dib" style="width:527px;height:273px" width="527" height="273"></p><pre class="prettyprint notranslate" style=""><strong>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)</strong></pre><p style="">If we want to display only the variable "<strong>i</strong>" in <strong>JShell Edit Pad,</strong> just type the command "<strong>/edit i</strong>", and it displays 10. In the same way, if we want to modify only the text of "<strong>ID 2"</strong> (corresponding to the variable y), just enter the command "<strong>/edit 2</strong>", and it displays 20.</p>
- Related Questions & Answers
- 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?
- JShell in Java 9?
- What are the different commands used in MySQL?
- What are the rules for external declarations in JShell in Java 9?
- What are the different module types in Java 9?
- How to save, edit, and drop a snippet in JShell in Java 9?
- What are the rules we need to follow in JShell in Java 9?
- What are the different status states of REPL in Java 9?
- What are the different Http/2 Client classes in Java 9?
Advertisements