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
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

The monk who sold his ferrari. summary
The monk who sold his ferrari. summaryThe monk who sold his ferrari. summary
The monk who sold his ferrari. summary
Sandeep Bhat
 
The monk who sold his ferrari
The monk who sold his ferrariThe monk who sold his ferrari
The monk who sold his ferrari
Vivek Kumar
 
LIFE IS FULL OF IFS AND BUTS
LIFE IS FULL OF IFS AND BUTSLIFE IS FULL OF IFS AND BUTS
LIFE IS FULL OF IFS AND BUTS
kratika rajawat
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
Manav Prasad
 
Building with Gradle
Building with GradleBuilding with Gradle
Building with Gradle
Kaunas Java User Group
 
गौतम बुद्ध के अनमोल वचन
गौतम बुद्ध के अनमोल वचनगौतम बुद्ध के अनमोल वचन
गौतम बुद्ध के अनमोल वचन
Shakti Prasad Tiwari
 
Contributor personality developement
Contributor personality developementContributor personality developement
Contributor personality developement
Alka Sanghani
 
Spring framework core
Spring framework coreSpring framework core
Spring framework core
Taemon Piya-Lumyong
 
Design solution
Design solutionDesign solution
Design solution
Rohan Patel
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
Manav Prasad
 
Inspirational Stories About Life - "The Story About The Boulder"
Inspirational Stories About Life -  "The Story About The Boulder"Inspirational Stories About Life -  "The Story About The Boulder"
Inspirational Stories About Life - "The Story About The Boulder"
Michelle Grigsby
 
Nothing is impossible
 Nothing is impossible  Nothing is impossible
Nothing is impossible
gepoteriko
 
Java Spring
Java SpringJava Spring
Java Spring
AathikaJava
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
Solution4Future
 
Jasper Reports.pptx
Jasper Reports.pptxJasper Reports.pptx
Jasper Reports.pptx
Aayush Chimaniya
 
Java EE and Spring Side-by-Side
Java EE and Spring Side-by-SideJava EE and Spring Side-by-Side
Java EE and Spring Side-by-Side
Reza Rahman
 
Java logging
Java loggingJava logging
Java logging
Jumping Bean
 
The JVM is your friend
The JVM is your friendThe JVM is your friend
The JVM is your friend
Kai Koenig
 
Introduction to Hibernate
Introduction to HibernateIntroduction to Hibernate
Introduction to Hibernate
Krishnakanth Goud
 
Spring andspringboot training
Spring andspringboot trainingSpring andspringboot training
Spring andspringboot training
Mallikarjuna G D
 

What's hot (20)

The monk who sold his ferrari. summary
The monk who sold his ferrari. summaryThe monk who sold his ferrari. summary
The monk who sold his ferrari. summary
 
The monk who sold his ferrari
The monk who sold his ferrariThe monk who sold his ferrari
The monk who sold his ferrari
 
LIFE IS FULL OF IFS AND BUTS
LIFE IS FULL OF IFS AND BUTSLIFE IS FULL OF IFS AND BUTS
LIFE IS FULL OF IFS AND BUTS
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Building with Gradle
Building with GradleBuilding with Gradle
Building with Gradle
 
गौतम बुद्ध के अनमोल वचन
गौतम बुद्ध के अनमोल वचनगौतम बुद्ध के अनमोल वचन
गौतम बुद्ध के अनमोल वचन
 
Contributor personality developement
Contributor personality developementContributor personality developement
Contributor personality developement
 
Spring framework core
Spring framework coreSpring framework core
Spring framework core
 
Design solution
Design solutionDesign solution
Design solution
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Inspirational Stories About Life - "The Story About The Boulder"
Inspirational Stories About Life -  "The Story About The Boulder"Inspirational Stories About Life -  "The Story About The Boulder"
Inspirational Stories About Life - "The Story About The Boulder"
 
Nothing is impossible
 Nothing is impossible  Nothing is impossible
Nothing is impossible
 
Java Spring
Java SpringJava Spring
Java Spring
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
 
Jasper Reports.pptx
Jasper Reports.pptxJasper Reports.pptx
Jasper Reports.pptx
 
Java EE and Spring Side-by-Side
Java EE and Spring Side-by-SideJava EE and Spring Side-by-Side
Java EE and Spring Side-by-Side
 
Java logging
Java loggingJava logging
Java logging
 
The JVM is your friend
The JVM is your friendThe JVM is your friend
The JVM is your friend
 
Introduction to Hibernate
Introduction to HibernateIntroduction to Hibernate
Introduction to Hibernate
 
Spring andspringboot training
Spring andspringboot trainingSpring andspringboot training
Spring andspringboot training
 

Similar to Java Platform Module System

Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
Ryan Cuprak
 
Java 9 Module System
Java 9 Module SystemJava 9 Module System
Java 9 Module System
Hasan Ünal
 
Java 9 / Jigsaw - AJUG/VJUG session
Java 9 / Jigsaw - AJUG/VJUG  sessionJava 9 / Jigsaw - AJUG/VJUG  session
Java 9 / Jigsaw - AJUG/VJUG session
Mani Sarkar
 
Java modules
Java modulesJava modules
Java modules
Rory Preddy
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java Workshop
Simon Ritter
 
As7 jbug j_boss_modules_yang yong
As7 jbug j_boss_modules_yang yongAs7 jbug j_boss_modules_yang yong
As7 jbug j_boss_modules_yang yong
jbossug
 
OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)
mfrancis
 
OSGi and Java 9+
OSGi and Java 9+OSGi and Java 9+
OSGi and Java 9+
bjhargrave
 
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
GlobalLogic Ukraine
 
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Mihail Stoynov
 
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil BartlettJava Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
JAX London
 
Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011
njbartlett
 
Java modulesystem
Java modulesystemJava modulesystem
Java modulesystem
Marc Kassis
 
Java SE 9 modules - an introduction (July 2018)
Java SE 9 modules - an introduction (July 2018)Java SE 9 modules - an introduction (July 2018)
Java SE 9 modules - an introduction (July 2018)
Stephen Colebourne
 
Java9
Java9Java9
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
Tim Ellison
 
Java 9 overview
Java 9 overviewJava 9 overview
Java 9 overview
Michel Schudel
 
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)
Martin Toshev
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
NexThoughts Technologies
 
What we can expect from Java 9 by Ivan Krylov
What we can expect from Java 9 by Ivan KrylovWhat we can expect from Java 9 by Ivan Krylov
What we can expect from Java 9 by Ivan Krylov
J On The Beach
 

Similar to Java Platform Module System (20)

Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
Java 9 Module System
Java 9 Module SystemJava 9 Module System
Java 9 Module System
 
Java 9 / Jigsaw - AJUG/VJUG session
Java 9 / Jigsaw - AJUG/VJUG  sessionJava 9 / Jigsaw - AJUG/VJUG  session
Java 9 / Jigsaw - AJUG/VJUG session
 
Java modules
Java modulesJava modules
Java modules
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java Workshop
 
As7 jbug j_boss_modules_yang yong
As7 jbug j_boss_modules_yang yongAs7 jbug j_boss_modules_yang yong
As7 jbug j_boss_modules_yang yong
 
OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)
 
OSGi and Java 9+
OSGi and Java 9+OSGi and Java 9+
OSGi and Java 9+
 
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
 
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
 
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil BartlettJava Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
 
Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011
 
Java modulesystem
Java modulesystemJava modulesystem
Java modulesystem
 
Java SE 9 modules - an introduction (July 2018)
Java SE 9 modules - an introduction (July 2018)Java SE 9 modules - an introduction (July 2018)
Java SE 9 modules - an introduction (July 2018)
 
Java9
Java9Java9
Java9
 
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 9 overview
Java 9 overviewJava 9 overview
Java 9 overview
 
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)
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
What we can expect from Java 9 by Ivan Krylov
What we can expect from Java 9 by Ivan KrylovWhat we can expect from Java 9 by Ivan Krylov
What we can expect from Java 9 by Ivan Krylov
 

Recently uploaded

CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
Madan Karki
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
UReason
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
GauravCar
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
RamonNovais6
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
Las Vegas Warehouse
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
architagupta876
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
ydzowc
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
gowrishankartb2005
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 

Recently uploaded (20)

CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 

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
  • 11.
  • 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