The main purpose of the
JLink function is to create our own customized JRE. Typically, we use the default JRE provided by Oracle Corporation to run the program, with a size of 214 MB .
For example, the 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 1 KB size program, we need 4 – 5 classes, for exampleString, System, Object and HelloWorldModuleTest.class files. So why do we need to use the default JRE to load a 214 MB JRE? This is a waste of memory and not suitable for any IoT device as these small devices cannot fit hundreds of memory.
We need to create our own custom JRE using JLink in the command below.
<strong>jlink –module-path out –add-modules {add modules} –output {jre name}</strong>
JLink is a powerful feature implemented with the help of JPMS to reduce the size of the JRE. JLink has the concept of compression, and we specify the compression level when executing the JLink command. JLink also provides an option called Launcher that allows the user to execute a program from anywhere on the computer by simply calling the program name from the Command Line Prompt without having to specify java or javac.
The above is the detailed content of What is the purpose of using JLink in Java 9?. For more information, please follow other related articles on the PHP Chinese website!