SlideShare a Scribd company logo
1 of 35
Java Module System
for Mortals
MahmoudAnouti / Marc Kassis
Motivation
• Makes it easier for developers to construct and
maintain libraries and large applications
• Improve the security and maintainability of Java SE
Platform Implementations in general, and the JDK
in particular
Motivation
• Enable improved application performance
• Enable the Java SE Platform, and the JDK, to scale
down for use in small computing devices and dense
cloud deployments.
Goals of the Module System
Reliable configuration: solve classpath issues
Strong encapsulation: ability to define public APIs for a
component
Scalable Java SE: ability to assemble custom runtime image
Encapsulate internal APIs (sun.* classes)
Improved performance
What is a module?
A named, self-describing set of program
components consisting of code (Java classes,
interfaces) and data (resources / config files)
What is a module?
classes < packages < modules
Module declaration
module-info.java:
1. Module name
2. Required modules (dependencies)
3. Exported packages
module com.example.myapp {
requires com.example.lib;
exports com.example.foo;
exports com.example.foo.bar;
}
(1)
(2)
(3)
Module declaration
• Dependencies: A module definition can require other modules to compile
and run.
• Exports: A module can export one or more of its packages for use by other
modules.
Code that accesses API in non-exported packages will fail (both compile and
runtime).
Module declaration
• Resources in a module are accessible only by code within that module.
• Services: a module can declare that it uses a service interface whose
implementations may be provided by other modules.
• Resolution:The module system resolves all transitive dependencies
required by an initial module  result is a configuration
module-info.java keywords
module A{
requires transitive B;
exports com.example to D;
opens com.example.beans;
opens com.example.private to E;
}
Services
module com.example.serviceapi {
exports com.example.myservice;
}
module com.example.serviceimpl {
requires com.example.serviceapi;
provides com.example.myservice.MyServiceInterface with
com.example.impl.MyServiceImpl;
}
Services
module com.example.client {
requires com.example.serviceapi;
uses com.example.myservice.MyServiceInterface;
}
DEMO
Module artifacts
• A module can be packaged into a modularJAR file:
META-INF/
META-INF/MANIFEST.MF
module-info.class
com/example/foo/Main.class
com/example/foo/bar/Bar.class
...
Platform modules
java.activation
java.base
java.compiler
java.corba
java.datatransfer
java.desktop
java.instrument
java.logging
java.management
java.management.rmi
java.naming
java.prefs
java.rmi
java.scripting
java.se
java.se.ee
java.security.jgss
java.security.sasl
java.sql
java.sql.rowset
java.transaction
java.xml
java.xml.bind
java.xml.crypto
java.xml.ws
java.xml.ws.annotation
Java SE platform is divided into modules
Platform modules
module java.base {
exports java.io;
exports java.lang;
exports java.lang.annotation;
exports java.lang.invoke;
exports java.lang.module;
exports java.lang.ref;
exports java.lang.reflect;
exports java.math;
exports java.net;
exports java.util;
...
}
Module path
• The module system resolves modules by locating them in a
module path: sequence of elements, where each element is
either:
 a module artifact (e.g. modular JAR), or
 a directory containing module artifacts
Classpath is still there!
DEMO
Reliable configuration
module com.example.myapp {
requires com.example.lib;
requires org.apache.commons.io;
}
module com.example.lib {
requires java.sql;
exports com.example.utils;
}
Reliable configuration
com.example.myapp
com.example.lib
java.sql
java.xml
java.base
org.apache.commons.io
java.logging
Reliable configuration
•Every dependency is fulfilled by precisely one other module
•The module graph is acyclic
•Every module reads at most one module defining a given
package
•Modules defining identically-named packages do not interfere
with each other.
requires transitive
module java.sql {
requires transitive java.logging;
requires transitive java.xml;
exports java.sql;
exports javax.sql;
exports javax.transaction.xa;
}
Implied readability
com.example.myapp
com.example.lib
java.sql
java.xml
java.base
org.apache.commons.io
java.logging
Strong encapsulation
If two types App and Util are defined in different modules,
and Util is public, then code in App can access Util iff:
1. App’s module requires (i.e. reads) Util’s module, and
2. Util’s module exports Util’s package.
public is no longer public!
Migrating to modular code
• An existing classpath app running on Java 8 will continue to run on Java 9, so
long as it only uses standard, non-deprecated Java SE APIs.
• Code that does not belong to a defined module, belongs to the unnamed
module.
The unnamed module
• Contains types that exist on the classpath
• Reads (i.e. depends) all other modules, including platform modules
• Exports all packages, ...
• A explicit named module cannot read the unnamed module
Bottom-up migration
com.example.app
com.example.orm
com.example.utils
java.sql java.base java.logging
Bottom-up migration
com.example.app
com.example.orm
java.sql java.base java.logging
com.example.utils
Bottom-up migration
com.example.app
java.sql java.base java.logging
com.example.utils
com.example.orm
Bottom-up migration
java.sql java.base java.logging
com.example.utils
com.example.orm
com.example.app
DEMO
Top-down migration
com.example.app
com.example.orm
com.example.utils
java.sql java.base java.logging
Top-down migration
java.sql java.base java.logging
com.example.utils
com.example.orm
com.example.app
Automatic modules
Automatic modules
• Its name is derived from Automatic-Module-Name in MANIFEST.MF, or from
the JAR file name
• Non-modular JAR that gets added on the module path
• Exports all its packages
• Reads all other modules
• Reads the unnamed module
DEMO

More Related Content

What's hot

Common Client Rich Client Platforms
Common Client   Rich Client PlatformsCommon Client   Rich Client Platforms
Common Client Rich Client Platforms
Geertjan Wielenga
 
The Brainify App - JavaFx
The Brainify App - JavaFxThe Brainify App - JavaFx
The Brainify App - JavaFx
Mohd Shamweel
 
Web Technologies in Java EE 7
Web Technologies in Java EE 7Web Technologies in Java EE 7
Web Technologies in Java EE 7
Lukáš Fryč
 
Enabling modularization through OSGi and SpringDM
Enabling modularization through OSGi and SpringDMEnabling modularization through OSGi and SpringDM
Enabling modularization through OSGi and SpringDM
mukulobject
 

What's hot (19)

How to Expand Anypoint Platform's Capabilities by Developing Custom Connectors
How to Expand Anypoint Platform's Capabilities by Developing Custom ConnectorsHow to Expand Anypoint Platform's Capabilities by Developing Custom Connectors
How to Expand Anypoint Platform's Capabilities by Developing Custom Connectors
 
Mule esb munit
Mule esb munitMule esb munit
Mule esb munit
 
Osgi
OsgiOsgi
Osgi
 
Features of java
Features of javaFeatures of java
Features of java
 
Experience and Content Fragment
Experience and Content FragmentExperience and Content Fragment
Experience and Content Fragment
 
Common Client Rich Client Platforms
Common Client   Rich Client PlatformsCommon Client   Rich Client Platforms
Common Client Rich Client Platforms
 
Learn Java Part 1
Learn Java Part 1Learn Java Part 1
Learn Java Part 1
 
The Brainify App - JavaFx
The Brainify App - JavaFxThe Brainify App - JavaFx
The Brainify App - JavaFx
 
Introduction to java technology
Introduction to java technologyIntroduction to java technology
Introduction to java technology
 
Web Technologies in Java EE 7
Web Technologies in Java EE 7Web Technologies in Java EE 7
Web Technologies in Java EE 7
 
JavaFX in Action Part I
JavaFX in Action Part IJavaFX in Action Part I
JavaFX in Action Part I
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
 
Java
JavaJava
Java
 
Springboot introduction
Springboot introductionSpringboot introduction
Springboot introduction
 
Enabling modularization through OSGi and SpringDM
Enabling modularization through OSGi and SpringDMEnabling modularization through OSGi and SpringDM
Enabling modularization through OSGi and SpringDM
 
Introduction to Java Programming
Introduction to Java Programming Introduction to Java Programming
Introduction to Java Programming
 
JVM, JRE and Javac are the main part for the java program
 JVM, JRE and Javac are the main part for the java program JVM, JRE and Javac are the main part for the java program
JVM, JRE and Javac are the main part for the java program
 
Mule security - saml
Mule  security - samlMule  security - saml
Mule security - saml
 
Mule security
Mule securityMule security
Mule security
 

Similar to Java modulesystem

Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Martin Toshev
 

Similar to Java modulesystem (20)

JavaScript Module Loaders
JavaScript Module LoadersJavaScript Module Loaders
JavaScript Module Loaders
 
Java 9 Jigsaw HackDay
Java 9 Jigsaw HackDayJava 9 Jigsaw HackDay
Java 9 Jigsaw HackDay
 
Eclipse plug in development
Eclipse plug in developmentEclipse plug in development
Eclipse plug in development
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
Modules all the way down: OSGi and the Java Platform Module System
Modules all the way down: OSGi and the Java Platform Module SystemModules all the way down: OSGi and the Java Platform Module System
Modules all the way down: OSGi and the Java Platform Module System
 
Java Platform Module System
Java Platform Module SystemJava Platform Module System
Java Platform Module System
 
unit1.pptx
unit1.pptxunit1.pptx
unit1.pptx
 
Java 9: Deep Dive into Modularity and Dealing with Migration Issues
Java 9: Deep Dive into Modularity and Dealing with Migration IssuesJava 9: Deep Dive into Modularity and Dealing with Migration Issues
Java 9: Deep Dive into Modularity and Dealing with Migration Issues
 
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
 
Java9
Java9Java9
Java9
 
Java 9 Module System
Java 9 Module SystemJava 9 Module System
Java 9 Module System
 
Java modularization
Java modularizationJava modularization
Java modularization
 
Java 9 / Jigsaw - AJUG/VJUG session
Java 9 / Jigsaw - AJUG/VJUG  sessionJava 9 / Jigsaw - AJUG/VJUG  session
Java 9 / Jigsaw - AJUG/VJUG session
 
Desiging for Modularity with Java 9
Desiging for Modularity with Java 9Desiging for Modularity with Java 9
Desiging for Modularity with Java 9
 
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
 
An overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-endAn overview of Scalable Web Application Front-end
An overview of Scalable Web Application Front-end
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
A Journey through the JDKs (Java 9 to Java 11)
A Journey through the JDKs (Java 9 to Java 11)A Journey through the JDKs (Java 9 to Java 11)
A Journey through the JDKs (Java 9 to Java 11)
 
Require.JS
Require.JSRequire.JS
Require.JS
 
Java 9, JShell, and Modularity
Java 9, JShell, and ModularityJava 9, JShell, and Modularity
Java 9, JShell, and Modularity
 

Recently uploaded

Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
Tonystark477637
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 

Recently uploaded (20)

The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 

Java modulesystem

Editor's Notes

  1. Mention JMOD artifact format