Home >Java >javaTutorial >What rules do we need to follow in JShell in Java 9?
Java 9 introduces an interactive REPL (Read-Evaluate-Print-Loop) tool: JShell , which allows us to execute code snippets and get results immediately. A snippet is a directive that can use standard Java syntax. It represents a single expression, statement or statement.
When using the JShell tool, we need to follow some of the following rules.
In the following sample code snippet, we have created an Employee class with necessary getter methods and Instantiate using the new operator.
<strong>jshell> class Employee { ...> private String firstName; ...> private String lastName; ...> private String designation; ...> public Employee(String firstName, String lastName, String designation) { ...> this.firstName = firstName; ...> this.lastName = lastName; ...> this.designation = designation; ...> } ...> public String getFirstName() { ...> return firstName; ...> } ...> public String getLastName() { ...> return lastName; ...> } ...> public String getDesignation() { ...> return designation; ...> } ...> public String toString() { ...> return "Name = " + firstName + ", " + lastName + " | " + ...> "designation = " + designation; ...> } ...> } | created class Employee jshell> Employee emp = new Employee("Sai", "Adithya", "Content Developer"); emp ==> Name = Sai, Adithya | designation = Content Developer</strong>
The above is the detailed content of What rules do we need to follow in JShell in Java 9?. For more information, please follow other related articles on the PHP Chinese website!