Home  >  Article  >  Java  >  What are the advantages of modules in Java 9?

What are the advantages of modules in Java 9?

WBOY
WBOYforward
2023-09-10 11:37:02828browse

Java 9中模块的优势是什么?

##Module is a software package container designed for reuse. Each module contains a module descriptor, which contains information about the module name , module dependencies (the names of other modules it depends on) and the names of the packages it exports , these Packages can only be used by dependent modules

Advantages of modules

  • Strong encapsulation is one of the main advantages of the module system because "public " access specifier is no longer accessible to everyone. By using the module system, we can allow external applications to access a limited set of packages.
  • It makes our application
  • lightweight so it can be run on a greater number of devices. Since it is lightweight, it improves the performance of the application.
  • This architecture allows us to separate the application into
  • external and hidden packages, making it easy to follow the separation of concerns principle. Some internal classes in
  • packages such as
  • sun.security.*, com.sun .crypto.* are no longer accessible because these packages are now Hidden, thus increasing security.

p>Modules can be declared in a file named "

module-info.java", which is the module descriptor .

<strong>module com.tutorialspoint.app{
   // Modules upon which the module "com.tutorialspoint.app" depends on 
   requires com.tutorialspoint.services;
   // Packages exposed by this module that can be used by other modules 
   exports com.tutorialspoint.app.util;
}</strong>

The above is the detailed content of What are the advantages of modules in Java 9?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete