Friday 8 January 2021

Jshell: open snippet from a file

/open command is used to open a file as source input.

 

Step 1: Create ‘empSnippet.jsh’ file with below content.

empSnippet.sh

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"

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

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

jshell>


Step 3: Execute the command ‘/open empSnippet.jsh’ to load the contents of empSnippet.jsh file.

jshell> /open empSnippet.jsh

jshell> 


Step 4: Execute below commands to see Employee instance details.

emp.id

emp.firstName

emp.lastName


jshell> emp.id
$6 ==> 1

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

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






 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment