Author here. Java 9 adds a new module system where module descriptors are introduced to explicitly demarcate the public API of a module, and to express its dependencies on other modules. Example of a module descriptor:
module mymodule {
exports mymodule.pkga;
exports mymodule.pkgb;
requires someothermodule;
}
What happens is that every package except the ones exported are accessible to other modules. Non-exported packages are encapsulated, not even reflection can break through that barrier. The requires statements are used by the Java compiler and runtime to verify the current configuration of modules resolves correctly.Obviously there's lots of more detail to go into. Of course I recommend you check out my upcoming book (early release available) for that: http://shop.oreilly.com/product/0636920049494.do
In short, Java makes a great step forward wrt. modularity. When regular JARs transition to modular JARs (adding a module descriptor), many more checks and balances are in place than are currently possible with the classpath.
Re:Modules vs Microservices
by gravity_123 on Sunday March 26, 2017 @10:29PM
(#13964694)
>What happens is that every package except the ones exported are accessible to other modules.
I think you meant inaccessible :)
Whoops, you're right!
Re:Modules vs Microservices
by empthought on Sunday March 26, 2017 @03:49PM
(#13962799)
Java packages are namespaces for code. Java modules are deployable bundles of code. The units of deployment (JAR, WAR, EAR files) pre-Java 9 do not have a consistent model of specifying dependencies and exports needed at runtime.
In other word, packages help the compiler, but give no information to the runtime or deployment as far as how, when, and from where to deploy or load code.
I mean when OOP was new people talked as if (a) no one had been trying to seperate out modules before OOP, and (b) the class was the natural boundary between modules. Both are false.
BTW: what does that article mean about that [in] "Java 9 a native module system is added..."; presumably this is something distinct from the package system it always had. What are the differences?