What are the different module types in Java 9?

JavaObject Oriented ProgrammingProgramming

Module System is a new feature introduced in Java 9. A module is a set of packages and divided into two types: Exported packages and Concealed packages. Exported packages can be used outside of this package. Concealed packages can't be used outside of this module, only the code of this module can use these packages.

There are four types of modules in Java 9 listed below

  • Application Modules: This module has been created to achieve functionality. All third-party dependencies belong to this category.
  • Automated Modules: The jars that can be placed in a module path without module descriptors belong to automated modules. The main benefit of this module is to use pre-Java 9 build jars.
  • Unnamed Modules: Any jar or class on the classpath belongs to the unnamed module. Since it doesn't have any name, it can read and export all the modules.
  • Platform Modules: The JDK has been transformed into a modular structure, these are called platform modules.
module <Module-Name> {
   requires moduleName;
   exports packageName;
}
raja
Published on 26-Mar-2020 08:19:58
Advertisements