Java 9 Modularity in Action

By Sander Mak
Java 9 Modularity
in Action
@Sander_Mak
Today's journey
Modularity matters
Java 9 modules
Services
Migration
Linking
Modularity matters
Modularity is the ultimate
agile tool
Good fences
make good neighbours
Hide your internals!
Service contract
Module
Work in progress,
almost there now.
Java 9: Jigsaw, JSR-376
Goals
‣ Modularise the JDK
‣ Reliable application composition
‣ Strong encapsulation - hide platform internals
‣ Improved security
Current status
‣ JDK 9 modularised
‣ JSR 376 prototype (Jigsaw)
‣ Spec in final draft
History of Jigsaw
JSR-277
Java
Module
System
2005 2006 2011 2014
JSR-294
Improved
Modularity
Support
Java 7:
No Jigsaw
Java 8:
No Jigsaw
JSR-376
Java Platform
Module
System
JSR-291
'OSGi 4.1'
Something happened in May...
Java 9: Jigsaw, JSR-376
Drama, intrigue, politics
Drama, intrigue, politics
JCP
Executive
Committee
Drama, intrigue, politics
JCP
Executive
Committee
JEP 200: The Modular JDK
Goodbye classpath
Reliable configuration
Goodbye classpath
Modules with explicit dependencies
my.module
requires
other.module
Strong encapsulation
Hide your internals
java.base
java.lang
java.time
java.util
com.sun.*
sun.*
jdk.internal.*
my.module
requires
Access checks at VM level (even reflection)
Why not just use OSGi?
‣ OSGi is built on top of the JVM
‣ Can’t be used to modularise the JDK itself
Why not just use OSGi?
‣ OSGi is built on top of the JVM
‣ Can’t be used to modularise the JDK itself
Why not only modularise the JDK?
‣ Fair point :-)
‣ OSGi has never seen mass adoption, Java 9 will
bring modularity to all of us
Demo: EasyText
Analyze text complexity
easytext.cli
easytext.analyis
requires
Contracts & Services
MyInterface i = new MyImpl();
How to use code
that you can’t access?
Contracts & Services
Provider
module
Service
Registry
Consumer
module
Register
service
Lookup
service
Return
service
instance
Use an interface as contract
JSR-376 services
module myApi {
exports com.api;
}
JSR-376 services
module myApi {
exports com.api;
}
module myConsumer {
requires myApi;
uses com.api.MyService;
}
JSR-376 services
module myApi {
exports com.api;
}
‣ Services resolved and wired by modular runtime
‣ Use with 'enhanced' ServiceLoader API
module myConsumer {
requires myApi;
uses com.api.MyService;
}
module myProvider {
requires myApi;
provides com.api.MyService
with myProvider.MyServiceImpl;
}
JSR-376 services
module myApi {
exports com.api;
}
‣ Services resolved and wired by modular runtime
‣ Use with 'enhanced' ServiceLoader API
module myConsumer {
requires myApi;
uses com.api.MyService;
}
module myProvider {
requires myApi;
provides com.api.MyService
with myProvider.MyServiceImpl;
}
Iterable<MyService> services =
ServiceLoader.load(MyService.class);
for(MyService svc: services) {
svc.doSomething();
}
Extensibility
Demo: EasyText
Extensibility
Multiple algorithms:
‣ Flesch-Kincaid
‣ Coleman-Liau
Demo: EasyText
Extensibility
CLI & GUI?
Multiple algorithms:
‣ Flesch-Kincaid
‣ Coleman-Liau
Demo: EasyText
easytext.algorithm.api
easytext.algorithm.kincaid
easytext.algorithm.coleman
easytext.cli
easytext.gui
Demo: EasyText
javafx.controls
JDKApplication
javafx.graphics
easytext.algorithm.api
easytext.algorithm.kincaid
easytext.algorithm.coleman
easytext.cli
easytext.gui
Demo: EasyText
javafx.controls
JDKApplication
ServiceLoader
javafx.graphics
JSR-376 linking
‣ Use a linking tool (jlink) to create a custom 'runtime
image' with only the modules you need
‣ Uses explicit dependencies from module-info.class
‣ Allows for whole-program optimization
Runtime image
java.base
java.desktop
my.mod1
my.mod2
JVM
Demo: EasyText linking
‣ Use jdeps to audit your code
‣ Escape hatch: 

--add-exports java.base/javax.security.auth.x500=mymod
Preparing for Java 9
‣ Use jdeps to audit your code
‣ Escape hatch: 

--add-exports java.base/javax.security.auth.x500=mymod
Preparing for Java 9
‣ Gradual migration possible
‣ Mix classpath & modulepath
‣ Automatic modules
Top down migration
commons.lang3.3.4.jar demonstrator.jar
classpath
java.base module path
package com.javamodularity.demonstrator;
import org.apache.commons.lang3.StringUtils;
public class Demo {
public static void main(String args[]) {
String output = StringUtils.leftPad("Leftpad FTW!", 20);
System.out.println(output);
}
}
Classic classpath
package com.javamodularity.demonstrator;
import org.apache.commons.lang3.StringUtils;
public class Demo {
public static void main(String args[]) {
String output = StringUtils.leftPad("Leftpad FTW!", 20);
System.out.println(output);
}
}
Classic classpath
javac -cp lib/commons-lang3-3.4.jar
-d out $(find src -name '*.java')
java -cp out:lib/commons-lang3-3.4.jar
com.javamodularity.demonstrator.Demo
Compile
Run
Top down migration
commons.lang3.3.4.jar demonstrator.jar
classpath
java.base module path
Top down migration
commons.lang3.3.4.jar
demonstrator.jar
classpath
java.base module path
Can’t reference the classpath
from named modules!
Top down migration
demonstrator.jar
classpath
java.base module path
commons.lang
But this isn’t our code!
Automatic Modules
‣ A plain JAR on the module path becomes an
Automatic Module
‣ Module name derived from JAR name
‣ Exports everything
‣ Reads all other modules
module demonstrator {
requires commons.lang;
}
Using Automatic Modules
module demonstrator {
requires commons.lang;
}
Using Automatic Modules
javac --module-path lib
--module-source-path src
-d mods $(find src -name '*.java')
java --module-path mods:lib
-m demonstrator/com.javamodularity.demonstrator.Demo
Compile
Run
Java 9 release
July 27th 2017
Java 9 release
July 27th 2017
Java 9 release
July 27th 2017
September 21st 2017
No promises :-)
‣ JSR-376 forces module-aware tooling
‣ Modularity throughout all
development phases
Java 9's promise
‣ JSR-376 forces module-aware tooling
‣ Modularity throughout all
development phases
Java 9's promise
Spotlight on modularity == good
Thank you.
bit.ly/java9book
@javamodularity
Thank you.
bit.ly/java9book
@javamodularity
40% discount:
AUTHD
1 of 49

Recommended

Modular JavaScript by
Modular JavaScriptModular JavaScript
Modular JavaScriptSander Mak (@Sander_Mak)
4.1K views38 slides
Java modularity: life after Java 9 by
Java modularity: life after Java 9Java modularity: life after Java 9
Java modularity: life after Java 9Sander Mak (@Sander_Mak)
4.4K views47 slides
Scala & Lift (JEEConf 2012) by
Scala & Lift (JEEConf 2012)Scala & Lift (JEEConf 2012)
Scala & Lift (JEEConf 2012)Sander Mak (@Sander_Mak)
2.5K views33 slides
Java 9 modularity by
Java 9 modularityJava 9 modularity
Java 9 modularityKnoldus Inc.
1.3K views18 slides
Desiging for Modularity with Java 9 by
Desiging for Modularity with Java 9Desiging for Modularity with Java 9
Desiging for Modularity with Java 9Sander Mak (@Sander_Mak)
1.9K views80 slides
Java 9 and Project Jigsaw by
Java 9 and Project JigsawJava 9 and Project Jigsaw
Java 9 and Project JigsawDPC Consulting Ltd
1.7K views27 slides

More Related Content

What's hot

Modular Java by
Modular JavaModular Java
Modular JavaMartin Toshev
3K views69 slides
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016) by
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)Robert Scholte
1.7K views52 slides
Discuss about java 9 with latest features by
Discuss about java 9 with latest featuresDiscuss about java 9 with latest features
Discuss about java 9 with latest featuresNexSoftsys
1.1K views14 slides
Java 9 preview by
Java 9 previewJava 9 preview
Java 9 previewIvan Krylov
873 views55 slides
Java 9 Modularity and Project Jigsaw by
Java 9 Modularity and Project JigsawJava 9 Modularity and Project Jigsaw
Java 9 Modularity and Project JigsawComsysto Reply GmbH
1.5K views62 slides
Java9 and the impact on Maven Projects (JFall 2016) by
Java9 and the impact on Maven Projects (JFall 2016)Java9 and the impact on Maven Projects (JFall 2016)
Java9 and the impact on Maven Projects (JFall 2016)Robert Scholte
1.6K views54 slides

What's hot(20)

Java 9 and the impact on Maven Projects (ApacheCon Europe 2016) by Robert Scholte
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
Robert Scholte1.7K views
Discuss about java 9 with latest features by NexSoftsys
Discuss about java 9 with latest featuresDiscuss about java 9 with latest features
Discuss about java 9 with latest features
NexSoftsys1.1K views
Java9 and the impact on Maven Projects (JFall 2016) by Robert Scholte
Java9 and the impact on Maven Projects (JFall 2016)Java9 and the impact on Maven Projects (JFall 2016)
Java9 and the impact on Maven Projects (JFall 2016)
Robert Scholte1.6K views
Developing modular Java applications by Julien Dubois
Developing modular Java applicationsDeveloping modular Java applications
Developing modular Java applications
Julien Dubois11.9K views
Modular Java applications with OSGi on Apache Karaf by Ioan Eugen Stan
Modular Java applications with OSGi on Apache KarafModular Java applications with OSGi on Apache Karaf
Modular Java applications with OSGi on Apache Karaf
Ioan Eugen Stan1.9K views
Java SE 9 modules (JPMS) - an introduction by Stephen Colebourne
Java SE 9 modules (JPMS) - an introductionJava SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introduction
Stephen Colebourne6.5K views
Polygot Java EE on the GraalVM by Ryan Cuprak
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVM
Ryan Cuprak1K views
Java 9 and the impact on Maven Projects (JavaOne 2016) by Robert Scholte
Java 9 and the impact on Maven Projects (JavaOne 2016)Java 9 and the impact on Maven Projects (JavaOne 2016)
Java 9 and the impact on Maven Projects (JavaOne 2016)
Robert Scholte7.4K views
Why jakarta ee matters (ConFoo 2021) by Ryan Cuprak
Why jakarta ee matters (ConFoo 2021)Why jakarta ee matters (ConFoo 2021)
Why jakarta ee matters (ConFoo 2021)
Ryan Cuprak221 views
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron... by VMware Tanzu
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
VMware Tanzu689 views
Java 9 and the impact on Maven Projects (Devoxx 2016) by Robert Scholte
Java 9 and the impact on Maven Projects (Devoxx 2016)Java 9 and the impact on Maven Projects (Devoxx 2016)
Java 9 and the impact on Maven Projects (Devoxx 2016)
Robert Scholte667 views
Java EE 8 Update by Ryan Cuprak
Java EE 8 UpdateJava EE 8 Update
Java EE 8 Update
Ryan Cuprak9.6K views
Java 9 Module System Introduction by Dan Stine
Java 9 Module System IntroductionJava 9 Module System Introduction
Java 9 Module System Introduction
Dan Stine786 views

Similar to Java 9 Modularity in Action

JavaFX Enterprise (JavaOne 2014) by
JavaFX Enterprise (JavaOne 2014)JavaFX Enterprise (JavaOne 2014)
JavaFX Enterprise (JavaOne 2014)Hendrik Ebbers
13.8K views55 slides
Haj 4344-java se 9 and the application server-1 by
Haj 4344-java se 9 and the application server-1Haj 4344-java se 9 and the application server-1
Haj 4344-java se 9 and the application server-1Kevin Sutter
170 views37 slides
VueJs Workshop by
VueJs WorkshopVueJs Workshop
VueJs WorkshopUnfold UI
763 views35 slides
Introduction to Lagom Framework by
Introduction to Lagom FrameworkIntroduction to Lagom Framework
Introduction to Lagom FrameworkKnoldus Inc.
2.1K views21 slides
MongoDB for Java Devs with Spring Data - MongoPhilly 2011 by
MongoDB for Java Devs with Spring Data - MongoPhilly 2011MongoDB for Java Devs with Spring Data - MongoPhilly 2011
MongoDB for Java Devs with Spring Data - MongoPhilly 2011MongoDB
6.9K views44 slides
A Glance At The Java Performance Toolbox.pdf by
 A Glance At The Java Performance Toolbox.pdf A Glance At The Java Performance Toolbox.pdf
A Glance At The Java Performance Toolbox.pdfAna-Maria Mihalceanu
20 views42 slides

Similar to Java 9 Modularity in Action(20)

JavaFX Enterprise (JavaOne 2014) by Hendrik Ebbers
JavaFX Enterprise (JavaOne 2014)JavaFX Enterprise (JavaOne 2014)
JavaFX Enterprise (JavaOne 2014)
Hendrik Ebbers13.8K views
Haj 4344-java se 9 and the application server-1 by Kevin Sutter
Haj 4344-java se 9 and the application server-1Haj 4344-java se 9 and the application server-1
Haj 4344-java se 9 and the application server-1
Kevin Sutter170 views
VueJs Workshop by Unfold UI
VueJs WorkshopVueJs Workshop
VueJs Workshop
Unfold UI763 views
Introduction to Lagom Framework by Knoldus Inc.
Introduction to Lagom FrameworkIntroduction to Lagom Framework
Introduction to Lagom Framework
Knoldus Inc.2.1K views
MongoDB for Java Devs with Spring Data - MongoPhilly 2011 by MongoDB
MongoDB for Java Devs with Spring Data - MongoPhilly 2011MongoDB for Java Devs with Spring Data - MongoPhilly 2011
MongoDB for Java Devs with Spring Data - MongoPhilly 2011
MongoDB6.9K views
Java @ Cloud - Setor Público SP by Ilan Salviano
Java @ Cloud - Setor Público SPJava @ Cloud - Setor Público SP
Java @ Cloud - Setor Público SP
Ilan Salviano234 views
MongoDB for Java Developers with Spring Data by Chris Richardson
MongoDB for Java Developers with Spring DataMongoDB for Java Developers with Spring Data
MongoDB for Java Developers with Spring Data
Chris Richardson5.4K views
IBM Impact session CICS & java a tale of liberty by nick_garrod
IBM Impact session CICS & java a tale of libertyIBM Impact session CICS & java a tale of liberty
IBM Impact session CICS & java a tale of liberty
nick_garrod1.9K views
Elastic and Cloud-ready Applications with Payara Micro by Payara
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro
Payara85 views
Elastic and Cloud-ready Applications with Payara Micro by Payara
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro
Payara311 views
Elastic and Cloud-ready Applications with Payara Micro by Ondrej Mihályi
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro
Ondrej Mihályi107 views
Great cup of java by CIB Egypt
Great  cup of javaGreat  cup of java
Great cup of java
CIB Egypt999 views
Dynamic Languages Web Frameworks Indicthreads 2009 by Arun Gupta
Dynamic Languages Web Frameworks Indicthreads 2009Dynamic Languages Web Frameworks Indicthreads 2009
Dynamic Languages Web Frameworks Indicthreads 2009
Arun Gupta1.3K views
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2 by Vladimir Bacvanski, PhD
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
Running your Java EE 6 applications in the Cloud (FISL 12) by Arun Gupta
Running your Java EE 6 applications in the Cloud (FISL 12)Running your Java EE 6 applications in the Cloud (FISL 12)
Running your Java EE 6 applications in the Cloud (FISL 12)
Arun Gupta1.8K views
Java 40 versions_sgp by michaelisvy
Java 40 versions_sgpJava 40 versions_sgp
Java 40 versions_sgp
michaelisvy49 views
The Java EE 7 Platform: Developing for the Cloud (FISL 12) by Arun Gupta
The Java EE 7 Platform: Developing for the Cloud  (FISL 12)The Java EE 7 Platform: Developing for the Cloud  (FISL 12)
The Java EE 7 Platform: Developing for the Cloud (FISL 12)
Arun Gupta1.5K views

More from Sander Mak (@Sander_Mak)

Scalable Application Development @ Picnic by
Scalable Application Development @ PicnicScalable Application Development @ Picnic
Scalable Application Development @ PicnicSander Mak (@Sander_Mak)
239 views20 slides
Coding Your Way to Java 13 by
Coding Your Way to Java 13Coding Your Way to Java 13
Coding Your Way to Java 13Sander Mak (@Sander_Mak)
414 views80 slides
Coding Your Way to Java 12 by
Coding Your Way to Java 12Coding Your Way to Java 12
Coding Your Way to Java 12Sander Mak (@Sander_Mak)
2K views69 slides
Java Modularity: the Year After by
Java Modularity: the Year AfterJava Modularity: the Year After
Java Modularity: the Year AfterSander Mak (@Sander_Mak)
913 views109 slides
Modules or microservices? by
Modules or microservices?Modules or microservices?
Modules or microservices?Sander Mak (@Sander_Mak)
5.9K views117 slides
Provisioning the IoT by
Provisioning the IoTProvisioning the IoT
Provisioning the IoTSander Mak (@Sander_Mak)
4.4K views38 slides

More from Sander Mak (@Sander_Mak)(20)

Recently uploaded

Techstack Ltd at Slush 2023, Ukrainian delegation by
Techstack Ltd at Slush 2023, Ukrainian delegationTechstack Ltd at Slush 2023, Ukrainian delegation
Techstack Ltd at Slush 2023, Ukrainian delegationViktoriiaOpanasenko
8 views4 slides
Introduction to Gradle by
Introduction to GradleIntroduction to Gradle
Introduction to GradleJohn Valentino
8 views7 slides
Playwright Retries by
Playwright RetriesPlaywright Retries
Playwright Retriesartembondar5
7 views1 slide
Automated Testing of Microsoft Power BI Reports by
Automated Testing of Microsoft Power BI ReportsAutomated Testing of Microsoft Power BI Reports
Automated Testing of Microsoft Power BI ReportsRTTS
13 views20 slides
.NET Deserialization Attacks by
.NET Deserialization Attacks.NET Deserialization Attacks
.NET Deserialization AttacksDharmalingam Ganesan
7 views50 slides
Introduction to Git Source Control by
Introduction to Git Source ControlIntroduction to Git Source Control
Introduction to Git Source ControlJohn Valentino
9 views18 slides

Recently uploaded(20)

Automated Testing of Microsoft Power BI Reports by RTTS
Automated Testing of Microsoft Power BI ReportsAutomated Testing of Microsoft Power BI Reports
Automated Testing of Microsoft Power BI Reports
RTTS13 views
Introduction to Git Source Control by John Valentino
Introduction to Git Source ControlIntroduction to Git Source Control
Introduction to Git Source Control
John Valentino9 views
predicting-m3-devopsconMunich-2023-v2.pptx by Tier1 app
predicting-m3-devopsconMunich-2023-v2.pptxpredicting-m3-devopsconMunich-2023-v2.pptx
predicting-m3-devopsconMunich-2023-v2.pptx
Tier1 app14 views
Mobile App Development Company by Richestsoft
Mobile App Development CompanyMobile App Development Company
Mobile App Development Company
Richestsoft 6 views
Electronic AWB - Electronic Air Waybill by Freightoscope
Electronic AWB - Electronic Air Waybill Electronic AWB - Electronic Air Waybill
Electronic AWB - Electronic Air Waybill
Freightoscope 7 views
University of Borås-full talk-2023-12-09.pptx by Mahdi_Fahmideh
University of Borås-full talk-2023-12-09.pptxUniversity of Borås-full talk-2023-12-09.pptx
University of Borås-full talk-2023-12-09.pptx
Mahdi_Fahmideh13 views
Advanced API Mocking Techniques Using Wiremock by Dimpy Adhikary
Advanced API Mocking Techniques Using WiremockAdvanced API Mocking Techniques Using Wiremock
Advanced API Mocking Techniques Using Wiremock
Dimpy Adhikary5 views
Bootstrapping vs Venture Capital.pptx by Zeljko Svedic
Bootstrapping vs Venture Capital.pptxBootstrapping vs Venture Capital.pptx
Bootstrapping vs Venture Capital.pptx
Zeljko Svedic17 views
tecnologia18.docx by nosi6702
tecnologia18.docxtecnologia18.docx
tecnologia18.docx
nosi67026 views
How to build dyanmic dashboards and ensure they always work by Wiiisdom
How to build dyanmic dashboards and ensure they always workHow to build dyanmic dashboards and ensure they always work
How to build dyanmic dashboards and ensure they always work
Wiiisdom18 views

Java 9 Modularity in Action