4. Scope
Task module descriptor
module descriptor
deployment descriptor
build execution descriptor
API for custom tasks
runtime
compile-time
build-time
Enforcement
obligatory
(with opt-out)
optional
(provided/optional dependency)
Unit Java package (sub-)project
5. api/Foo.class internal/Qux.class api/Bar.class internal/Baz.class
api/Foo.class internal/Qux.class api/Bar.class internal/Baz.class
class path (system class loader)
Modularity prior to Java 9 is emulated by class loader hierarchies. By tweaking class
loaders to define multiple parents, it is also possible to run several versions of the
same module (e.g. OSGi).
6. api/Foo.class internal/Qux.class api/Bar.class internal/Baz.class
api/Foo.class internal/Qux.class api/Bar.class internal/Baz.class
module loader
example.foo
example.bar
“example.bar reads example.foo”
The integrity of the module graph is verified by the Java 9 runtime. Jars without a
module-info.class are bundled in an unnamed module that reads all modules (fallback).
7. try {
Class<?> pluginType = Class.forName("example.Foo");
runAppWithPlugin(pluginType);
} catch(ClassNotFoundException exception) {
runAppWithoutPlugin();
}
void runAppWithPlugin(Class<?> pluginType) {
activate(pluginType.newInstance());
// and run the app...
}
When code is bundled as a module, looking up a class is still possible but any
execution of foreign code is no longer permitted.
In order to overcome this, a new reflection API for modules is introduced that allows
for the dynamic attachment of “read edges” at runtime. At compile time, the current
draft does however not foresee a possibility of defining optional dependencies.
8. module example.overview {
exports pkg.name;
exports pkg.other.name to example.friend, example.other;
requires mdl.name;
requires public mdl.name.exposed;
provides service.type.name with service.impl.name;
uses service.other.type.name;
}
Jigsaw recommends crossing of module boundaries by using service interfaces.
Implementations of such interfaces can then be retreived by the ServiceLoader API.
Finally, modules can – similarly to class loaders – be organized in layers. This allows
The migration of class loader hierarchy systems into a modularized formats. Layers
can be created programmatically via a reflection API.
9.
10.
11. Java 9: more than Jigsaw! (biased selection)
• New process API
• HTTP2 client
• Improved contended locking
• Unified JVM logging
• Compiler control
• Variable handles
• Segmented code cache
• Smart Java compilation, phase 2
• Project Coin extensions
(private interface methods)
• Unicode 7.0/8.0
• Convenience collection factories
• Annotation pipeline enhancements
• Multi-version jar files
• Compact strings
• “Indifying” string concatenation
• Stack-walking API
• Currency and money API
• Enhanced method handles
• Platform specific desktop features
• javac performance (sjavac, type inference)
• Jshell
• javadoc improvements (HTML5, search)
• Improved concurrency