One of Java 9\'s largest features will be a module system defined by Project Jigsaw. When reading slides from the Project Jigsaw: Under the Hood at JavaOne 2015, I noticed the f
moduleis a new keyword introduced to define the interdependencies between packages. Why we need modules? Because earlier
the encapsulation was not immaculate. With the help of reflection and with similar techniques we could access even the private field.
All classes in all jars were publicly accessible.
If the Classloader does not get the class it had to look into a lot of areas and load a lot of related files and even after that if the Class is not found, it would throw NoClassDefFoundErrors at run time.
So for all the above reasons we need a mechanism which lets JVM to know this at runtime. For implementing module, you need to define module-info.java
. in that package
module com.exporter{
exports com.a;
provides com.b.M;
with com.b.MImpl; }
In some other package,
module com.consume {
requires com.a;
}
Other attributes used are "exports" and "requires" for making an inter dependency(transitive dependency only), "provides" and "with" for exposing interface and mentioning implementation. So it a strong encapsulation, may be, that is why java 9 is more inclined to better Object Oriented feature.