O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Open the command prompt and launch JShell.
  2. By default, JShell imports a few libraries. We can check that by issuing the /imports command:
  1. Let's import java.text.SimpleDateForm by issuing the import java.text.SimpleDateFormat command. This imports the SimpleDateFormat class. 
  2. Let's declare an Employee class. We will issue one statement in each line so that it's an incomplete statement, and we'll proceed in the same way as we do in any ordinary editor. The following illustration will clarify this:
        class Employee{          private String empId;          public String getEmpId() {            return empId;          }          public void setEmpId ( String empId ) { this.empId ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required