SlideShare ist ein Scribd-Unternehmen logo
1 von 27
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

Weitere ähnliche Inhalte

Was ist angesagt?

Java Virtual Machine (JVM), Difference JDK, JRE & JVM
Java Virtual Machine (JVM), Difference JDK, JRE & JVMJava Virtual Machine (JVM), Difference JDK, JRE & JVM
Java Virtual Machine (JVM), Difference JDK, JRE & JVMshamnasain
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architectureAnurag
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Javaparag
 
Introduction à spring boot
Introduction à spring bootIntroduction à spring boot
Introduction à spring bootAntoine Rey
 
[11]Android DataBinding : 기초에서 고급까지
[11]Android DataBinding : 기초에서 고급까지[11]Android DataBinding : 기초에서 고급까지
[11]Android DataBinding : 기초에서 고급까지NAVER Engineering
 
Curso de Java Persistence API (JPA) (Java EE 7)
Curso de Java Persistence API (JPA) (Java EE 7)Curso de Java Persistence API (JPA) (Java EE 7)
Curso de Java Persistence API (JPA) (Java EE 7)Helder da Rocha
 
OCA Java SE 8 Exam Chapter 6 Exceptions
OCA Java SE 8 Exam Chapter 6 ExceptionsOCA Java SE 8 Exam Chapter 6 Exceptions
OCA Java SE 8 Exam Chapter 6 Exceptionsİbrahim Kürce
 
Curso de Enterprise JavaBeans (EJB) (JavaEE 7)
Curso de Enterprise JavaBeans (EJB) (JavaEE 7)Curso de Enterprise JavaBeans (EJB) (JavaEE 7)
Curso de Enterprise JavaBeans (EJB) (JavaEE 7)Helder da Rocha
 
Java 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgradeJava 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgradeSimone Bordet
 
Java 9 New Features
Java 9 New FeaturesJava 9 New Features
Java 9 New FeaturesAli BAKAN
 
Java Virtual Machine - Internal Architecture
Java Virtual Machine - Internal ArchitectureJava Virtual Machine - Internal Architecture
Java Virtual Machine - Internal Architecturesubnesh
 
Clean Code II - Dependency Injection
Clean Code II - Dependency InjectionClean Code II - Dependency Injection
Clean Code II - Dependency InjectionTheo Jungeblut
 
Interview preparation full_stack_java
Interview preparation full_stack_javaInterview preparation full_stack_java
Interview preparation full_stack_javaMallikarjuna G D
 
SpringBoot with MyBatis, Flyway, QueryDSL
SpringBoot with MyBatis, Flyway, QueryDSLSpringBoot with MyBatis, Flyway, QueryDSL
SpringBoot with MyBatis, Flyway, QueryDSLSunghyouk Bae
 

Was ist angesagt? (20)

Support distributed computing and caching avec hazelcast
Support distributed computing and caching avec hazelcastSupport distributed computing and caching avec hazelcast
Support distributed computing and caching avec hazelcast
 
Java Virtual Machine (JVM), Difference JDK, JRE & JVM
Java Virtual Machine (JVM), Difference JDK, JRE & JVMJava Virtual Machine (JVM), Difference JDK, JRE & JVM
Java Virtual Machine (JVM), Difference JDK, JRE & JVM
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architecture
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
 
Introduction à spring boot
Introduction à spring bootIntroduction à spring boot
Introduction à spring boot
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
 
[11]Android DataBinding : 기초에서 고급까지
[11]Android DataBinding : 기초에서 고급까지[11]Android DataBinding : 기초에서 고급까지
[11]Android DataBinding : 기초에서 고급까지
 
Curso de Java Persistence API (JPA) (Java EE 7)
Curso de Java Persistence API (JPA) (Java EE 7)Curso de Java Persistence API (JPA) (Java EE 7)
Curso de Java Persistence API (JPA) (Java EE 7)
 
OCA Java SE 8 Exam Chapter 6 Exceptions
OCA Java SE 8 Exam Chapter 6 ExceptionsOCA Java SE 8 Exam Chapter 6 Exceptions
OCA Java SE 8 Exam Chapter 6 Exceptions
 
Curso de Enterprise JavaBeans (EJB) (JavaEE 7)
Curso de Enterprise JavaBeans (EJB) (JavaEE 7)Curso de Enterprise JavaBeans (EJB) (JavaEE 7)
Curso de Enterprise JavaBeans (EJB) (JavaEE 7)
 
Java 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgradeJava 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgrade
 
Java 9 New Features
Java 9 New FeaturesJava 9 New Features
Java 9 New Features
 
Core java
Core javaCore java
Core java
 
Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
 
Java Virtual Machine - Internal Architecture
Java Virtual Machine - Internal ArchitectureJava Virtual Machine - Internal Architecture
Java Virtual Machine - Internal Architecture
 
Clean Code II - Dependency Injection
Clean Code II - Dependency InjectionClean Code II - Dependency Injection
Clean Code II - Dependency Injection
 
Interview preparation full_stack_java
Interview preparation full_stack_javaInterview preparation full_stack_java
Interview preparation full_stack_java
 
SpringBoot with MyBatis, Flyway, QueryDSL
SpringBoot with MyBatis, Flyway, QueryDSLSpringBoot with MyBatis, Flyway, QueryDSL
SpringBoot with MyBatis, Flyway, QueryDSL
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
React hooks
React hooksReact hooks
React hooks
 

Ähnlich wie 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 uploadRyan Cuprak
 
Java 9 Module System
Java 9 Module SystemJava 9 Module System
Java 9 Module SystemHasan Ünal
 
Java 9 / Jigsaw - AJUG/VJUG session
Java 9 / Jigsaw - AJUG/VJUG  sessionJava 9 / Jigsaw - AJUG/VJUG  session
Java 9 / Jigsaw - AJUG/VJUG sessionMani Sarkar
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java WorkshopSimon 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 yongjbossug
 
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 IssuesGlobalLogic 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
 
Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011njbartlett
 
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 BartlettJAX London
 
Java modulesystem
Java modulesystemJava modulesystem
Java modulesystemMarc 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
 
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 SystemTim Ellison
 
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
 
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 KrylovJ On The Beach
 

Ähnlich wie 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)
 
Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011
 
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
 
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
 

Kürzlich hochgeladen

The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
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
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
(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...ranjana rawat
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
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 EscortsCall Girls in Nagpur High Profile
 
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 projectTonystark477637
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
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.pptxAsutosh Ranjan
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
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.pptxupamatechverse
 

Kürzlich hochgeladen (20)

The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
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, ...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
(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...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
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
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
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
 
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
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.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
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
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
 

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