Tuesday, September 24, 2019

Java 9 Features


JShell:
Jshell which stands for Java shell is interactive tool for learning the Java programming language.
Jshell is standard component of JDK 9.
Jshell can be started by simply executing “jshell” command.
e.g.
$jshell
To display the “Hello, World” in jshell all you have to write is this:
jshell>System.out.println(“Hello, World!!!”);
Hello, World!!!
Main advantage of jshell is that you can test your individual statements, methods etc.
Jshell can be stopped by executing “/exit” command.

Private methods in interfaces:
Since Java 9, it is possible to include private methods in interfaces.
Now encapsulation is possible in interfaces using private methods.
Java 9 private interface methods can be instance or static.
The private method cannot inherited by sub-interfaces or implementations.
Private methods in interfaces are mainly there to improve code re-usability within interface only: thus improving encapsulation.