module $module_name {
requires $other_module;
exports $api_package;
}
interacting parts
parts have
names
dependencies
capabilities
creates a graph
parts are packaged as JARs
to the JVM JARs
have no names
dependencies are unexpressed
have no coherent surface
JVM rolls them into one big ball of mud
unexpressed, transitive dependencies
shadowing, version conflicts
complex class loading
slow
unsecure
maintenance nightmare
first discussions about modularity in JDK
Project Jigsaw is created
exploratory phase; ends with JSR 376
prototype is released
Java 9 gets released with Jigsaw
all is based on a prototype
everything can change
this is the time for community feedback
Reliable Configuration
Strong Encapsulation
Scalable Systems (esp. the JDK)
Security
Performance
Maintainability
Introducing modules, which
have a name
express dependencies
encapsulate internals
Everything else follows from here!
Modules, Readability, Accessibility
Implied Readability, Qualified Exports
Modular JARs, Module Path, Module Graph
Services
Unnamed Modules, Automatic Modules
Reflection, Layers
Runtime Images
These are the nodes in our graph.
Modules
have a unique name
express their dependencies
export specific packages
(and hide the rest)
Modules are JARs with a module-info.class
(aka Modular JAR)
gets generated from module-info.java
:
module $module_name {
requires $other_module;
exports $api_package;
}
this is called a Module Declaration or a
Module Descriptor
Readability brings edges into our graph.
It is the basis for Reliable Configuration.
For two modules A
and B
with
module A {
requires B;
}
we say
A
requires B
A
depends on B
A
reads B
B
is readable by A
Java will only compile/launch when
every dependency is fulfilled
there are no cycles
there is no ambiguity
Accessibility governs which types a module can see.
It builds on top of Readability.
It is the basis for Strong Encapsulation.
A type in one module is only accessible
by code in another module if
the type is public
the package is exported
the second module reads the first
public
is no longer public
even reflection doesn’t work
command line provides escape hatches
great boost for maintainability
also the major reason for community unrest
it looks like critical APIs will survive until Java 10
(e.g. sun.misc.Unsafe
— see JEP 260)
All examples are based on this toy project.
Find it on GitHub!
public static void main(String[] args) {
List<SurpriseF_> fac = asList(
new ChocolateF_(), new QuoteF_());
Calendar cal = Calendar.create(fac);
println(cal.asText());
}
module advent {
// java.base is implicitly required
// requires no other modules
// exports no API
}
(Boring...)
module surprise {
// requires no other modules
exports org.codefx.demo.advent.surprise;
}
module calendar {
requires surprise;
exports org.codefx.demo.advent.calendar;
}
module factories {
requires surprise;
exports org.codefx.demo.advent.factories;
}
module main {
requires calendar;
requires factories;
requires surprise;
}
# First compile/package the other modules
# ('surprises', 'calendar', 'factories')
# into folder 'mods'.
# Compile/package 'main':
javac -mp mods -d classes/advent ${*.java}
jar -c --file=mods/advent.jar
--main-class=org.codefx.demo.advent.Main
${*.java}
# Launch the application:
java -mp mods -m advent
what could possibly go wrong?
what happens then?
what about migration?
…?
Some internal changes can break existing code!
Just by running on JDK 9
(i.e. even without modularizing the application)
Reliable Configuration
exported packages should have a unique origin
no module must read the same package
from two modules
i.e. no "split packages"
Strong Encapsulation
Modular Run-Time Images (JEP 220)
new JDK/JRE layout
unavailability of internal JARs (e.g. rt.jar
)
new URL schema for runtime image content
removal of Endorsed Standards Override Mechanism
removal of Extension Mechanism
disy-landscape
© Disy Informationssysteme GmbH
binary-code: Christiaan Colen (CC-BY-SA 2.0)
ball-of-mud-2: Andi Gentsch (CC-BY-SA 2.0)
jar-hell: Wellcome Library, London (CC-BY 4.0)
puzzle-cubed: David Singleton (CC-BY 2.0)
flag-amsterdam: George Rex (CC-BY-SA 2.0)
puzzle-piece-green: StockMonkeys.com (CC-BY 2.0)
puzzle-pieces-put-together:
Ken Teegardin
(CC-BY-SA 2.0)
iceberg: NOAA’s National Ocean Service (CC-BY 2.0)
class and module diagrams:
Nicolai Parlog
(CC-BY-NC 4.0)
question-mark: Milos Milosevic (CC-BY 2.0)