Home  >  Article  >  Java  >  What are unnamed modules in Java 9?

What are unnamed modules in Java 9?

王林
王林forward
2023-08-18 23:17:07839browse

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>

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>);
   }
}

Output

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

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!

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