Home > Java > javaTutorial > body text

What are unnamed modules in Java 9?

王林
Release: 2023-08-18 23:17:07
forward
874 people have browsed it

Java 9中的未命名模块是什么?

An unnamedmodule is the unnamedpackage concept. It is a module in which a package or class cannot be defined in any named module, but is present in the classpath in a jar file. If our code attempts to load a type from these files, the module system attempts to find the Classpath and load it.

An unnamed module will read all other modules, including all named , built-in platform modules , and export all its packages. Packages in unnamed modules can be ignored, this is also defined in named modules.

Unnamed modules can access:

  • all packages exported by all other modules in the module path.
  • All jar files in the classpath (i.e. all other types present in this unnamed module). The Chinese translation of

Grammar

<strong>java --module-path out -module moduleName/com.tutorialspoint.UnnamedModuleTest</strong>
Copy after login

Example

is:

Example

public class UnnamedModuleTest {
   public static void main(String args[]) {
      <strong>Module </strong>module = UnnamedModuleTest.class.<strong>getModule()</strong>;
      System.out.println("Module: "+ module);
      System.out.println("Name: " + module.<strong>getName()</strong>);
      System.out.println("isNamed: " + module.<strong>isNamed()</strong>);
      System.out.println("Descriptor: " + module.<strong>getDescriptor()</strong>);
   }
}
Copy after login

Output

<strong>Module: unnamed module @c818063
Name: null
isNamed: false
Descriptor: null</strong>
Copy after login

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

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!