Friday 8 January 2021

Jshell: /edit: Edit a source entry

/edit command is used to edit a source entry.

 

Step 1: Open terminal and execute the command ‘jshell’.

$jshell
|  Welcome to JShell -- Version 10.0.2
|  For an introduction type: /help intro

jshell>

 

Step 2: Execute following statements.

System.out.println("Hello")

System.out.println("Are")

System.out.println("You")

System.out.println("There")

jshell> System.out.println("Hello")
Hello

jshell> System.out.println("Are")
Are

jshell> System.out.println("You")
You

jshell> System.out.println("There")
There

Step 3: Execute the command /list to see all the executed snippets.

jshell> /list

   1 : System.out.println("Hello")
   2 : System.out.println("Are")
   3 : System.out.println("You")
   4 : System.out.println("There")


Step 4: Now execute the command /edit 2 to update the snippet with id 2.

 

Once you execute the command, it opens ‘JShell Edit Pad’ like below.




 

Update the statement line below.

System.out.println("I am updated using Edit Pad");

 




Click on Accept button.

Click on Exit button.

 

You will see below messages in console.

 

jshell> /edit 2
I am updated using Edit Pad


Execute the command /list to see all the snippets executed. Now you can confirm that snippet 5 is added to the list.

jshell> /list

   1 : System.out.println("Hello")
   2 : System.out.println("Are")
   3 : System.out.println("You")
   4 : System.out.println("There")
   5 : System.out.println("I am updated using Edit Pad");


You can execute a snippet using id (/snippetId). For example, /2 execute a snippet with id 2.

jshell> /2
System.out.println("Are")
Are

jshell> /list

   1 : System.out.println("Hello")
   2 : System.out.println("Are")
   3 : System.out.println("You")
   4 : System.out.println("There")
   5 : System.out.println("I am updated using Edit Pad");
   6 : System.out.println("Are")

jshell>



Previous                                                    Next                                                    Home

No comments:

Post a Comment