What is the purpose of using JLink in Java 9?


The main purpose of the JLink feature is to create our own Customized JRE. Usually, we run a program with the default JRE that has been provided by Oracle Corporation with 214 MB of size.

For instance, a user wants to print a simple "Hello World" message as shown below

public class HelloWorldModuleTest {
   public static void main(String args[[]) {
      System.out.println("Hello World!");
   }
}

To run the above program of 1 KB size, we need 4 – 5 classes like String, System, Object, and HelloWorldModuleTest.class files. Then why do we need to load 214 MB of JRE using default JRE? It's a waste of memory and not suitable for any IoT devices because these small devices can't hold hundreds of memory. 

We need to create our own Customized JRE using JLink in the below command.

jlink –module-path out –add-modules {add modules} –output {jre name}

JLink is a powerful feature that has implemented with the help of JPMS to reduce the size of JRE. JLink comes with the concept of Compress, where we specify the compress level while executing the JLink command. JLink also provides an option called Launcher that enables the user to execute programs from anywhere on the machine by just calling program name from command-line prompt without specifying java or javac.

Updated on: 26-Mar-2020

92 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements