What is the Java 9 Module System?

  • Name of the module
  • Services offered by this module
  • Services consumed by this module
  • The reflection it allows to other modules
  • Dependencies it has on other modules
  • Specification of the list of packages that are publicly exported to other modules as module APIs
  • Strong Encapsulation: Java has no mechanism to establish encapsulation at the package level. Java 9 establishes that packages in a module are accessible only to other modules if and only if the said module explicitly exports them.
  • Reliable Configuration: With Java 9, a module configuration can be established that can be walked through to determine the subset of dependent modules both at compile time and execution time by a Java application.
  • Scalable: The days of JRE as a monolithic artefact is a day of the past. JRE is modularized into several modules. One can pick the required modules and create a sleek custom runtime according to the specific need of a particular application. Therefore, the Java platform is itself now scalable.
  • Improved Performance: Java 9 has been improved
module moduleA{

requires moduleB;
requires transitive moduleC;
requires static moduleD;

exports moduleE;
exports moduleF to moduleG, moduleH;

opens package1;
opens package1 to package2,package3;

uses MyInterfaceImpl;

provides MyClassService1 with MyClassService2;

A Quick Look at the Module Declaration Directives

  • The requires directive establishes dependency relationship. Here, it means that moduleA is dependent on moduleB. The transitive directive specifies a transitive dependency relationship, such as in the previous example, moduleA states a transitive dependency with moduleC; this means that any module that reads moduleA will also be able to read implicitly moduleC. The static directive states that the module is required at the time of compilation but is optional at the time of execution.
  • The exports module directive states that the module’s public type in the packages is accessible to all other modules. The exports…to module directive is used to specify exclusive accessibility to a comma-separated list of modules.
  • With the open directive, it is possible to specify the packages and its content types are accessible via reflection. The opens…todirective is used for the same purpose but exclusively to the selected list of modules. If, however, all the modules should be accessible at runtime via reflection, one may write:
open module mymodule{

// ... Module directives
  • The uses directive is used to specify the services consumed by this module. A service in Java is provided by an instance of a class that extends an abstract class or implements an interface.
  • The provides…with directive is a juxtaposed directive of the uses directive in the sense that it specifies the services provided by this module

A Glimpse into Changes in JRE





Research Data Scientist @Altimetrik, Linkedin: https://www.linkedin.com/in/venkatesh-nagilla/ , Github: https://github.com/nagilla748

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Are there no good video editing software on Linux?

Learning 4.0.1

Deploying a Steam dedicated server on Kubernetes

mtr — My Traceroute Replacement

Scrum Day Europe

Standardization Process of Cellular Technologies within 3GPP

Earn page test net

Piping Design Tokens from Figma

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nagilla Venkatesh

Nagilla Venkatesh

Research Data Scientist @Altimetrik, Linkedin: https://www.linkedin.com/in/venkatesh-nagilla/ , Github: https://github.com/nagilla748

More from Medium

Apple and Orange | HackerRank Problem | Java Solution

Basics of the Clean Code

Know about Rest API’s in Software Engineering

Version Controlling and NoSql