Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Java 9 modularity

966 views

Published on

Modularization is the act of decomposing a system into self contained modules. It possibly makes you think of component-based development.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Java 9 modularity

  1. 1. By: Harmeet Singh (Taara) Software Consultant
  2. 2. Agenda 1. Before Java 9 2. Modules. 3. Java 9 Modules 4. Compilation, Packaging & Linking 5. Demo. 6. Leftover's
  3. 3. Before Java 9 ➔Encapsulation ➔ private, protected or public
  4. 4. Before Java 9 ➔Classpath
  5. 5. Modules ➔ Modularization is the act of decomposing a system into self contained modules. ➔ It possibly makes you think of component-based development
  6. 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
  7. 7. Java 9 Modules
  8. 8. Java 9 Modules
  9. 9. Java 9 Modules - How to create modules module com.dept {   exports com.dept.info } module com.account {   exports com.account.info; } module com.user {   requires com.dept;   requires com.account;   exports com.user.info; }
  10. 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. 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; }
  12. 12. Compilation/ Execution ➔ javac ­d <target­dir> <source­file> <module­file> ­ javac ­d target src/com.user/com/user/info/Launcher.java  src/com.user/module­info.java ➔ javac ­d <target­dir> ­­modules­source­path <all­source­ files> ­ javac ­d target ­­module­source­path src $(find ­name  "*.java") ➔ java –module­path <target­dir> ­­module <module­ name>/<full­package­name­main­class> ­ java ­p target ­m com.user/com.user.info.Launcher
  13. 13. Packaging ➔ jar ­­create –file=<target­dir­path> ­C <compiled­module­ path> <class­files­dir>  ­ jar ­­create ­­file=libs/account­module.jar ­C  target/com.account . ➔ jar ­­create –file=<target­dir­path> ­­main­class=<full­ package­name­main­class> ­C <compiled­module­path> <class­ files­dir> ­ jar ­­create ­­file=libs/user­module.jar ­­main­ class=com.user.info.Launcher ­C target/com.user . ➔ java ­p libs ­m com.user
  14. 14. Linking - Run Time Image ➔ What if, we required special distribution of the Java Runtime containing the bare minimum to run our application ??? ➔ Jlink ­­module­path $JAVA_HOME/jmods:<compiled­ modules> ­­add­modules <module1>:<module2> ­­output  <image­name> ➔ jlink ­­module­path $JAVA_HOME/jmods:target ­­add­ modules com.user ­­output app ➔ bin/java <absolute­name­of­main­class>
  15. 15. Java 9 Module DEMO
  16. 16. Leftovers ➔ Module Path ➔ Modules using Reflection ➔ Types of Modules ➔ Service Loader ➔ JMOD ➔ Java Shell ➔ Process API ➔ Reactive Streams
  17. 17. References: ✔ http://openjdk.java.net/projects/jigsaw/quick-start ✔ Java9 Modularity: Patternsand Practices ✔ https://blog.knoldus.com/2016/09/23/kick-off-java-9-project-jigsaw-part-i/ ✔ Graph Theory for Geeksby Oliver Widder, CC-BY

×