5. Modules
➔ Modularization is the act of decomposing a system into self
contained modules.
➔ It possibly makes you think of component-based
development
6. Java 9 Modules
- By using module
➔ Reliable Configuration ->
The system checks all dependencies before compiling
or running code.
➔ Strong Encapsulation ->
Modules explicitly choose what to expose to other
modules.
➔ Modular JDK/JRE
10. Java 9 Modules
- Points to remember
➔ requires keyword indicates a dependency.
➔ exports keyword only export defined package to other modules.
➔ Modules name must be a unique.
➔ Module descriptor always start with module keyword.
➔ The implicit dependency java.base automatically added to a
module descriptor.
➔ Only explicitly exported packages can be access from other
modules
➔ Modules dependencies are not transitive.
11. Java 9 Modules
Q. How we achieve transitive dependency ???
module java.sql {
requires public java.logging;
requires public java.xml
}
Module com.knoldus {
requires java.sql;
}
14. Linking
- Run Time Image
➔ What if, we required special distribution of the Java
Runtime containing the bare minimum to run our
application ???
➔ Jlink modulepath $JAVA_HOME/jmods:<compiled
modules> addmodules <module1>:<module2> output
<imagename>
➔ jlink modulepath $JAVA_HOME/jmods:target add
modules com.user output app
➔ bin/java <absolutenameofmainclass>