How modules fit into the Java landscape

As you can see from the following diagram, packages are comprised of classes and interfaces, and modules are comprised of packages. Modules are a container of packages. This is the basic premise, at a very high level, of Java's modular system. It is important to view modules as part of the modular system and not simply as a new level of abstraction above packages, as the following diagram suggests:

So, modules are new to Java 9 and as you would expect, they require declaration before they can be used. A module's declaration includes names of other modules in which it has a dependency. It also exports packages for other modules that have dependencies to it. Modular declarations are arguably the most important modular issue to address as you start developing with Java. Here is an example:

module com.three19.irisScan {
// modules that com.three19.irisScan depends upon
requires com.three19.irisCore;
requires com.three19.irisData;

// export packages for other modules that are
// dependent upon com.three19.irisScan
exports com.three19.irisScan.biometric;
}

When programming a Java application, your module declarations will be placed in a module-info.java file. Once this file is completed, you simply run Javac, the Java compiler, to generate the module-info.class Java class file. You accomplish this task in the same manner that you currently compile your .java files into .class files. 

You can also create modular JAR files that have your module-info.class file at its root. This represents a great level of flexibility.

Next, let's review three important concepts regarding Java modules:

  • Base module
  • Reliable configuration
  • Strong encapsulation
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset