Java Features by Version- Java 9

Java9 Features (2017)

JShell: The Java Shell (REPL)

It is an interactive Java Shell tool, it allows us to execute Java code from the shell and shows output immediately. JShell is a REPL (Read Evaluate Print Loop) tool and run from the command line.

Module System (Project Jigsaw)

In earlier versions of Java, there was no concept of module to create modular Java applications, that why size of application increased and difficult to move around. Even JDK itself was too heavy in size, in Java 8, rt.jar file size is around 64MB.

To deal with situation, Java 9 restructured JDK into set of modules so that we can use only required module for our project

Create a file module-info.java, inside this file, declare a module by using module identifier and provide module name same as the directory name that contains it. In our case, our directory name is com.javatpoint.

Interface Private Methods

In Java 9, we can create private methods inside an interface. Interface allows us to declare private methods that help to share common code between non-abstract methods / Default methods.

interface Sayable{  
    default void say() {  
        saySomething();  
    }  
    // Private method inside interface  
    private void saySomething() {  
        System.out.println("Hello... I'm private method");  
    }  
}  
public class PrivateInterface implements Sayable {  
    public static void main(String[] args) {  
        Sayable s = new PrivateInterface();  
        s.say();  
    }  
}

Multi-Release JAR Files

Previously, you had to package all classes into a jar file and drop in the classpath of the another application, which wish to use it.

Using multi-release feature, now a jar can contains different versions of a class – compatible to different JDK releases. The information regarding different versions of a class, and in which JDK version which class shall be picked up by class loaded, is stored in MANIFEST.MF file.