Module System
Module System
Java Module System is a major change in Java 9 version. Java added this
feature to collect Java packages and code into a single unit called module.
To deal with situation, Java 9 restructured JDK into set of modules so that
we can use only required module for our project.
Apart from JDK, Java also allows us to create our own modules so that we
can develop module based application.
The module system includes various tools and options that are given below.
o Includes various options to the Java tools javac, jlink and java where we
can specify module paths that locates to the location of module.
o Modular JAR file is introduced. This JAR contains module-info.class file
in its root folder.
o JMOD format is introduced, which is a packaging format similar to JAR
except it can include native code and configuration files.
o The JDK and JRE both are reconstructed to accommodate modules. It
improves performance, security and maintainability.
o Java defines a new URI scheme for naming modules, classes and
resources.
Java 9 Modularized JDK
Java 9 Module
Module name
What does it export
What does it require
Module Name
ADVERTISEMENT
1. module com.javatpoint{
2.
3. }
Leave module body empty, if it does not has any module dependency. Save
this file inside src/com.javatpoint with module-info.java name.
Now, create a Java file to compile and execute module. In our example, we
have a Hello.java file that contains the following code.
After compiling, it will create a new directory that contains the following
structure.
Run Module
ADVERTISEMENT
Output:
ADVERTISEMENT
1.