What are the advantages of Modules in Java 9?
A module is a container of packages designed for reuse, and each module contains a module descriptor that includes the information about module name, module dependencies (name of the other modules which it depends on) and name of the packages it exports that can be used only by modules which depend on it.
Advantages of Modules
- Strong encapsulation is one of the major advantages of a module system as the “public” access specifier is no longer accessible to everyone. By using a module system, we can able to allow a limited set of packages to be accessible to outside applications.
- It makes our application lightweight, so it can be run on more number of devices. As it is lightweight, it improves the performance of an application.
- An architecture that allows us to split our application into external and concealed packages, hence easy to follow separation of concern principle.
- Some internal classes in packages, for instance, sun.security.*, com.sun.crypto.* is no longer accessible as these packages are now concealed, therefore improves security.
A module can be declared inside the file named "module-info.java", which is the module descriptor.
// Modules upon which the module "com.tutorialspoint.app" depends on
// Packages exposed by this module that can be used by other modules
Published on 08-Apr-2020 17:30:52