SlideShare a Scribd company logo
EXPLORING JAVA9 MODULES
By
Vignesh Ramesh
About Me
• I am Vignesh . Insanely passionate full stack developer with high
proficiency in Java, Scala, Node.js, JavaScript.
Github : https://github.com/vickii
Linkedin : https://www.linkedin.com/in/vickyramesh/
StackOverFlow :
What is a Module ?
• Module is a collection of packages designed for reuse.
• Modular JAR is a regular JAR with a module descriptor[a module-
info.class] in its root folder.
• A key motivation of the module system is strong encapsulation
Why Modules?
Whenever a new JVM is started the bootstrap classloader is
responsible to load key Java classes (from java.lang package) and other
runtime classes to the memory first.
rt.jar is about 64mb in jdk-8. Do we need all the classes runtime
classes?
Depends on the Application right?
Why modules?
There is no way to reuse a behavior defined inside a package in another
package unless and until it is public . But public is too open .
[Developers started using JDK internals which was not supposed to be
used ex: sun.misc.Unsafe Using it, you can create an instance of a class
without invoking it’s constructor code, initialization code, various JVM
security checks and all other low level things. Even if class has private
constructor, then also you can use this method to create new
instance.].
JDk8 contains about 218 packages. This weakens encapsulation. This
was one of the main reason why JDK itself was modularized.
Maven modules vs JPMS
MAVEN MODULES JPMS
Build Time only. Everything is on
classpath during runtime where no
boundaries are available
Compile time, Run Time
Sub-project Packages
Module vs JAR
• A module can decide which classes and interfaces to export to other
modules that require it. A Jar has no such encapsulation mechanism.
• The name is of a JAR can be changed. As long as the JVM classloader
finds the needed class on the classpath (which can be composed of a
single JAR, multiple JARs, or a mix between directories or JARs), the
name of the JAR file can be anything. However, the name of a module
can be explicitly referenced in the declaration of other modules, and
such the name defines it and cannot be changed freely.
JDK Module-graph
Accessibility
Accessibility prior to JAVA 9 Accessibility on java9
public but only to specific modules
public only within a modules
public public to everyone
protected protected
<package> private <package> private
Public is no more an golden switch
• Public no longer means accessible if the package is not exported by
the parent module[module which has that class]
• This is the point of controversy in Java9 due to which many libraries
like Glassfish was failing on JDK-9 because they were using jdk
internals which are no longer exported.
Temporary access : ‘--illegal-access=permit’
Proposal: Allow illegal reflective access by default in JDK 9
http://mail.openjdk.java.net/pipermail/jigsaw-dev/2017-
May/012673.html
Java Platform Module System
JDEPS : Dependency Analyzer
• JDeps is a "Java [static] class dependency analyzer" that is useful
for quickly identifying "static dependencies of applications and
libraries.
• The input can be a path name to a .class file or a JAR File.
• Example : jdeps dependency list for junit-jar. –s option is for summary
Types of Modules In Java
• Named Modules
• Unnamed Module
• Automatic Modules
Named Module
• Contain a module-info.java
• Loaded from the module path.
• Only their exported packages are accessible and they can only require
and thus read other named modules (which excludes the unnamed
module).
Automatic Modules
• Does not contain a module-info.java.
• Loaded from the module path.
• There name is derived from the jar file name by default.
• Explicit naming is recommended by setting the Automatic-Module-
Name variable in MANIFEST.MF.
• They export all packages and requires all modules, including
automatic one’s.
• Automatic, or automatically named, modules are JARs without a
module-info.java that were loaded from the module path. Their name
is derived from the JAR file name, they export every package and read
any module, including other automatic ones.
Un-Named Modules
• Does not contain a module-info.java
• Loaded from classpath.
• Requires all named modules
• All classes within the unnamed module can read all other module
(named or unnamed) without any explicit declaration of any kind.
That also means that older classes (written prior to Java 9) can read
all modules defined by the new Module system
• Exports all packages
• The packages exported by unnamed module can only be read by
another unnamed module. It is not possible that a named module can
read (requires) the unnamed module
Creating an Module
• In Java 9, you need to have a specific file name by convention in order
to define modules with a specific filename. That filename should be
called module-info.java.
Example:
module modulename{}
• Don’t worry module is not a keyword in java
• If your module name is com.example.myapp then the module.info
should be placed at src/com.example.myapp/module-info.java path
Module-info.java
Module com.example.myapp{
exports com.example.myapp.utils;
requires java.base;
}
• This module[com.example.myapp] only needs types from the base
module 'java.base’ because every Java module needs 'java.base', it is
not necessary to explicitly require it.
• This module[com.example.myapp] only exports the package
com.example.myapp.utils for public use to other modules. Classes in
other packages cannot be accessed by other modules.
Module-info.java syntax
module ${module-name} {
requires ${module-name};
exports ${package-name};
exports ${package-name} to ${module-name} , ${module-name};
}
Add screenshot of location
Implied Readability
Module1
Module 2
Module3
Implied Readability
• Let’s look at the java.sql module. It exposes the interface Driver,
which returns a Logger via its public
method getParentLogger(). Logger belongs to java.logging. Because
of that, java.sql requires transitive java.logging, so any module using
Java’s SQL features can also access the logging API.
JDK Example:
module java.sql {
requires transitive java.logging;
requires java.xml;
}
JLINK : The Java Linker
• Jlink is Java’s new command line tool through which we can create
our own customized JRE. It is an best illustration of the concept just
enough runtime.
• Usually, we run our program using the default JRE, but in case if you
want to create your own small customized JRE, then you can go
with the jlink concept.
• This feature is very useful in the era of microservices and
containerization
• jlink takes into account transitive dependencies from the top modules
and generates a custom Java image.
JLINK : Uses
class App {
public static void main(String[]args) {
System.out.prinltn("Hello World");
}
}
To execute this small “hello world” application, we require the
following .class files:
• App.class
• String.class
• System.class
• Object.class
JLINK : USES
• The default JRE contains 4000+ predefined Java .class files.
• If I execute my “hello world” application with the default JRE, then all
the predefined .class files will be executed. But if I only need 3-4 .class
files to execute my “hello world” application, then why I need to
maintain the outer .class files?
• The default JRE's size in jdk-8 is 203 MB. For executing my simple 1 KB
of code, I have to maintain 203 MB of JRE in my machine. It is a
complete waste of memory.
JLINK Commands :
jlink --module-path <modulepath> --add-modules <modules> --limit-
modules <modules> --output <path>
• –module-path specifies where to find the modules for the JDK. These
can be jar files, jmod files (a new file format with JDK 9 which is
similar to the jar format.
• –add-modules adds the modules we need (in this example our app)
• –limit-modules limits to just the modules that we know our
application needs (sometimes when modules are added, further
modules can be added via transitive dependencies. Here we can
specify that we only want certain modules)
• –output is this directory where the run-time image will be generated.
OSGI vs JPMS
OSGI JPMS
Framework Platform Feature. Was used to
modularize the java platform itself
Complex steep learning curve Simple when compared to OSGI
Solves many problems like JAR
Hell(Using classloaders),Circular
Dependency
Not solved/Not supported
Q & A
Links to code : https://github.com/vickii
Links to slide : https://www.slideshare.net/VigneshRamesh8
Linked in : https://www.linkedin.com/in/vickyramesh/
Twitter : https://twitter.com/vickiramesh

More Related Content

What's hot (14)

PDF
JDK versions and OpenJDK
Wolfgang Weigend
 
PPTX
Microservices with Minimal APi and .NET 6
Miguel Angel Teheran Garcia
 
PDF
Serving ML easily with FastAPI - meme version
Sebastián Ramírez Montaño
 
PDF
Big Data - O que é o hadoop, map reduce, hdfs e hive
Flavio Fonte, PMP, ITIL
 
PDF
[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3
Ji-Woong Choi
 
PPTX
Docker intro
Oleg Z
 
PDF
Object Vs Data Structure - Clean code chapter6
Maksud Chowdhury
 
PDF
DevOps 3 - Docker.pdf
GhofraneFerchichi2
 
PDF
Kubernetes GitOps featuring GitHub, Kustomize and ArgoCD
Sunnyvale
 
PDF
PowerDNS with MySQL
I Goo Lee
 
PDF
Introduction to Docker - VIT Campus
Ajeet Singh Raina
 
PDF
Hybrid Cloud Strategy for Big Data and Analytics
DataWorks Summit/Hadoop Summit
 
PDF
Deliver Python Apps with Docker
Anton Egorov
 
PDF
JavaOne 2015: 12 Factor App
Joe Kutner
 
JDK versions and OpenJDK
Wolfgang Weigend
 
Microservices with Minimal APi and .NET 6
Miguel Angel Teheran Garcia
 
Serving ML easily with FastAPI - meme version
Sebastián Ramírez Montaño
 
Big Data - O que é o hadoop, map reduce, hdfs e hive
Flavio Fonte, PMP, ITIL
 
[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3
Ji-Woong Choi
 
Docker intro
Oleg Z
 
Object Vs Data Structure - Clean code chapter6
Maksud Chowdhury
 
DevOps 3 - Docker.pdf
GhofraneFerchichi2
 
Kubernetes GitOps featuring GitHub, Kustomize and ArgoCD
Sunnyvale
 
PowerDNS with MySQL
I Goo Lee
 
Introduction to Docker - VIT Campus
Ajeet Singh Raina
 
Hybrid Cloud Strategy for Big Data and Analytics
DataWorks Summit/Hadoop Summit
 
Deliver Python Apps with Docker
Anton Egorov
 
JavaOne 2015: 12 Factor App
Joe Kutner
 

Similar to Java Platform Module System (20)

PPTX
Java 9
Netesh Kumar
 
PDF
Java SE 9 modules (JPMS) - an introduction
Stephen Colebourne
 
PDF
Java SE 9 modules - an introduction (July 2018)
Stephen Colebourne
 
PPT
Java 9 Module System
Hasan Ünal
 
PPTX
Java 9 Module System Introduction
Dan Stine
 
PDF
Java 9 preview
Ivan Krylov
 
PDF
Java 9, JShell, and Modularity
Mohammad Hossein Rimaz
 
PDF
What we can expect from Java 9 by Ivan Krylov
J On The Beach
 
PPTX
Modern Java Workshop
Simon Ritter
 
PPTX
Java 9 Modularity and Project Jigsaw
Comsysto Reply GmbH
 
PPTX
Apache Maven supports all Java (JokerConf 2018)
Robert Scholte
 
PPTX
Preparing for java 9 modules upload
Ryan Cuprak
 
PDF
Java modules
Rory Preddy
 
PPTX
Java 9: Deep Dive into Modularity and Dealing with Migration Issues
GlobalLogic Ukraine
 
PPTX
Advanced modular development
Srinivasan Raghavan
 
PPTX
Getting started with Java 9 modules
Rafael Winterhalter
 
PPTX
Java modulesystem
Marc Kassis
 
PDF
JDK-9: Modules and Java Linker
Bhanu Prakash Gopularam
 
PDF
Java 9 / Jigsaw - AJUG/VJUG session
Mani Sarkar
 
Java 9
Netesh Kumar
 
Java SE 9 modules (JPMS) - an introduction
Stephen Colebourne
 
Java SE 9 modules - an introduction (July 2018)
Stephen Colebourne
 
Java 9 Module System
Hasan Ünal
 
Java 9 Module System Introduction
Dan Stine
 
Java 9 preview
Ivan Krylov
 
Java 9, JShell, and Modularity
Mohammad Hossein Rimaz
 
What we can expect from Java 9 by Ivan Krylov
J On The Beach
 
Modern Java Workshop
Simon Ritter
 
Java 9 Modularity and Project Jigsaw
Comsysto Reply GmbH
 
Apache Maven supports all Java (JokerConf 2018)
Robert Scholte
 
Preparing for java 9 modules upload
Ryan Cuprak
 
Java modules
Rory Preddy
 
Java 9: Deep Dive into Modularity and Dealing with Migration Issues
GlobalLogic Ukraine
 
Advanced modular development
Srinivasan Raghavan
 
Getting started with Java 9 modules
Rafael Winterhalter
 
Java modulesystem
Marc Kassis
 
JDK-9: Modules and Java Linker
Bhanu Prakash Gopularam
 
Java 9 / Jigsaw - AJUG/VJUG session
Mani Sarkar
 
Ad

Recently uploaded (20)

PPTX
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PPTX
Big Data and Data Science hype .pptx
SUNEEL37
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PPTX
Presentation 2.pptx AI-powered home security systems Secure-by-design IoT fr...
SoundaryaBC2
 
PPTX
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
PPT
Carmon_Remote Sensing GIS by Mahesh kumar
DhananjayM6
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
PPTX
Introduction to Basic Renewable Energy.pptx
examcoordinatormesu
 
PPTX
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PPTX
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
DOCX
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
PDF
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
PPT
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
Big Data and Data Science hype .pptx
SUNEEL37
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
Presentation 2.pptx AI-powered home security systems Secure-by-design IoT fr...
SoundaryaBC2
 
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
Carmon_Remote Sensing GIS by Mahesh kumar
DhananjayM6
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
Introduction to Basic Renewable Energy.pptx
examcoordinatormesu
 
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
Ad

Java Platform Module System

  • 2. About Me • I am Vignesh . Insanely passionate full stack developer with high proficiency in Java, Scala, Node.js, JavaScript. Github : https://github.com/vickii Linkedin : https://www.linkedin.com/in/vickyramesh/ StackOverFlow :
  • 3. What is a Module ? • Module is a collection of packages designed for reuse. • Modular JAR is a regular JAR with a module descriptor[a module- info.class] in its root folder. • A key motivation of the module system is strong encapsulation
  • 4. Why Modules? Whenever a new JVM is started the bootstrap classloader is responsible to load key Java classes (from java.lang package) and other runtime classes to the memory first. rt.jar is about 64mb in jdk-8. Do we need all the classes runtime classes? Depends on the Application right?
  • 5. Why modules? There is no way to reuse a behavior defined inside a package in another package unless and until it is public . But public is too open . [Developers started using JDK internals which was not supposed to be used ex: sun.misc.Unsafe Using it, you can create an instance of a class without invoking it’s constructor code, initialization code, various JVM security checks and all other low level things. Even if class has private constructor, then also you can use this method to create new instance.]. JDk8 contains about 218 packages. This weakens encapsulation. This was one of the main reason why JDK itself was modularized.
  • 6. Maven modules vs JPMS MAVEN MODULES JPMS Build Time only. Everything is on classpath during runtime where no boundaries are available Compile time, Run Time Sub-project Packages
  • 7. Module vs JAR • A module can decide which classes and interfaces to export to other modules that require it. A Jar has no such encapsulation mechanism. • The name is of a JAR can be changed. As long as the JVM classloader finds the needed class on the classpath (which can be composed of a single JAR, multiple JARs, or a mix between directories or JARs), the name of the JAR file can be anything. However, the name of a module can be explicitly referenced in the declaration of other modules, and such the name defines it and cannot be changed freely.
  • 9. Accessibility Accessibility prior to JAVA 9 Accessibility on java9 public but only to specific modules public only within a modules public public to everyone protected protected <package> private <package> private
  • 10. Public is no more an golden switch • Public no longer means accessible if the package is not exported by the parent module[module which has that class] • This is the point of controversy in Java9 due to which many libraries like Glassfish was failing on JDK-9 because they were using jdk internals which are no longer exported. Temporary access : ‘--illegal-access=permit’ Proposal: Allow illegal reflective access by default in JDK 9 http://mail.openjdk.java.net/pipermail/jigsaw-dev/2017- May/012673.html
  • 12. JDEPS : Dependency Analyzer • JDeps is a "Java [static] class dependency analyzer" that is useful for quickly identifying "static dependencies of applications and libraries. • The input can be a path name to a .class file or a JAR File. • Example : jdeps dependency list for junit-jar. –s option is for summary
  • 13. Types of Modules In Java • Named Modules • Unnamed Module • Automatic Modules
  • 14. Named Module • Contain a module-info.java • Loaded from the module path. • Only their exported packages are accessible and they can only require and thus read other named modules (which excludes the unnamed module).
  • 15. Automatic Modules • Does not contain a module-info.java. • Loaded from the module path. • There name is derived from the jar file name by default. • Explicit naming is recommended by setting the Automatic-Module- Name variable in MANIFEST.MF. • They export all packages and requires all modules, including automatic one’s. • Automatic, or automatically named, modules are JARs without a module-info.java that were loaded from the module path. Their name is derived from the JAR file name, they export every package and read any module, including other automatic ones.
  • 16. Un-Named Modules • Does not contain a module-info.java • Loaded from classpath. • Requires all named modules • All classes within the unnamed module can read all other module (named or unnamed) without any explicit declaration of any kind. That also means that older classes (written prior to Java 9) can read all modules defined by the new Module system • Exports all packages • The packages exported by unnamed module can only be read by another unnamed module. It is not possible that a named module can read (requires) the unnamed module
  • 17. Creating an Module • In Java 9, you need to have a specific file name by convention in order to define modules with a specific filename. That filename should be called module-info.java. Example: module modulename{} • Don’t worry module is not a keyword in java • If your module name is com.example.myapp then the module.info should be placed at src/com.example.myapp/module-info.java path
  • 18. Module-info.java Module com.example.myapp{ exports com.example.myapp.utils; requires java.base; } • This module[com.example.myapp] only needs types from the base module 'java.base’ because every Java module needs 'java.base', it is not necessary to explicitly require it. • This module[com.example.myapp] only exports the package com.example.myapp.utils for public use to other modules. Classes in other packages cannot be accessed by other modules.
  • 19. Module-info.java syntax module ${module-name} { requires ${module-name}; exports ${package-name}; exports ${package-name} to ${module-name} , ${module-name}; } Add screenshot of location
  • 21. Implied Readability • Let’s look at the java.sql module. It exposes the interface Driver, which returns a Logger via its public method getParentLogger(). Logger belongs to java.logging. Because of that, java.sql requires transitive java.logging, so any module using Java’s SQL features can also access the logging API. JDK Example: module java.sql { requires transitive java.logging; requires java.xml; }
  • 22. JLINK : The Java Linker • Jlink is Java’s new command line tool through which we can create our own customized JRE. It is an best illustration of the concept just enough runtime. • Usually, we run our program using the default JRE, but in case if you want to create your own small customized JRE, then you can go with the jlink concept. • This feature is very useful in the era of microservices and containerization • jlink takes into account transitive dependencies from the top modules and generates a custom Java image.
  • 23. JLINK : Uses class App { public static void main(String[]args) { System.out.prinltn("Hello World"); } } To execute this small “hello world” application, we require the following .class files: • App.class • String.class • System.class • Object.class
  • 24. JLINK : USES • The default JRE contains 4000+ predefined Java .class files. • If I execute my “hello world” application with the default JRE, then all the predefined .class files will be executed. But if I only need 3-4 .class files to execute my “hello world” application, then why I need to maintain the outer .class files? • The default JRE's size in jdk-8 is 203 MB. For executing my simple 1 KB of code, I have to maintain 203 MB of JRE in my machine. It is a complete waste of memory.
  • 25. JLINK Commands : jlink --module-path <modulepath> --add-modules <modules> --limit- modules <modules> --output <path> • –module-path specifies where to find the modules for the JDK. These can be jar files, jmod files (a new file format with JDK 9 which is similar to the jar format. • –add-modules adds the modules we need (in this example our app) • –limit-modules limits to just the modules that we know our application needs (sometimes when modules are added, further modules can be added via transitive dependencies. Here we can specify that we only want certain modules) • –output is this directory where the run-time image will be generated.
  • 26. OSGI vs JPMS OSGI JPMS Framework Platform Feature. Was used to modularize the java platform itself Complex steep learning curve Simple when compared to OSGI Solves many problems like JAR Hell(Using classloaders),Circular Dependency Not solved/Not supported
  • 27. Q & A Links to code : https://github.com/vickii Links to slide : https://www.slideshare.net/VigneshRamesh8 Linked in : https://www.linkedin.com/in/vickyramesh/ Twitter : https://twitter.com/vickiramesh