What are the characteristics of a module in Java 9?

JavaObject Oriented ProgrammingProgramming

The module is a collection of code, data, and resources. It is a set of related packages and types like classes, abstract classes, and interfaces with code, data files, and some static resources.

Below are some of the characteristics of a module.

Characteristics of a module:

  • A module must define an interface for communication with other modules.
  • A module defines the separation between a module interface and module implementation.
  • A module presents a set of properties that contains information.
  • Two or more modules have nested together.
  • A module has a clear, defined responsibility. Each function implemented by only one module.
  • A module must able to tested independently from other modules.
  • An error in a module can't propagate to other modules.

If we have two modules: M1 and M2 and one package in a module. M2 called Pkg2 that we want to be accessible in module M1, then the following conditions have to meet:

  • Module M1 depends on module M2, then module M1 can specify in its declaration that "requires” module M2.
  • Module M2 export the package Pkg2 in order to make it available to modules that depend on it. In the declaration of the module M2, we can specify that it “exports” package Pkg2.
Updated on 26-Feb-2020 05:01:28