Friday, 8 January 2021

Jshell: Save snippets to a file

/save command is used to save the snippet source to a file.

 

Step 1: Open terminal and execute jshell command.

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

jshell>

 

Step 2: Execute below snippet.

public class Employee {

         public int id;

         public String firstName;

         public String lastName;

 

}

 

Employee emp = new Employee()

emp.id = 1

emp.firstName = "Krishna"

emp.lastName = "Ponnam"

 

jshell> public class Employee {
   ...>     public int id;
   ...>     public String firstName;
   ...>     public String lastName;
   ...> 
   ...> }
|  created class Employee

jshell> Employee emp = new Employee()
emp ==> Employee@239963d8

jshell> emp.id = 1
$3 ==> 1

jshell> emp.firstName = "Krishna"
$4 ==> "Krishna"

jshell> emp.lastName = "Ponnam"
$5 ==> "Ponnam"

 

Step 3: Execute the command ‘/save empSnippet.jsh‘ to store all the snippets to empSnippet.jsh.

jshell> /save empSnippet.jsh

jshell>

Step 4: Execute the command /exit to come out of jshell terminal.

 

Step 5: Open the file ‘empSnippet.jsh’ to see the content.

$cat empSnippet.jsh 
public class Employee {
	public int id;
	public String firstName;
	public String lastName;

}
Employee emp = new Employee();
emp.id = 1
emp.firstName = "Krishna"
emp.lastName = "Ponnam"




 

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment