English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java Basic Tutorial

Java Flow Control

Java Array

Java Object-Oriented (I)

Java Object-Oriented (II)

Java Object-Oriented (III)

Java Exception Handling

Java List

Java Queue (queue)

Java Map collection

Java Set collection

Java Input/Output (I/O)

Java Reader/Writer

Other Java topics

Java 9 Module system

Java 9 New Features

Java 9 One of the biggest changes is the introduction of the module system (Jigsaw project).

A module is a package of code and data. The code of the module is organized into multiple packages, each containing Java classes and interfaces; the data of the module includes resource files and other static information.

Java 9 An important feature of the module is that it contains a module description in the root directory of its artifact.-info.class file. The format of the artifact can be a traditional JAR file or a Java 9 Newly added JMOD file. This file is generated from the source code file module-info.java compiled. This module declaration file can describe different features of the module.

In module-In the info.java file, we can use the new keyword module to declare a module, as shown below. The following is a basic module declaration for a module com.mycompany.mymodule.

module com.w3codebox.mymodule {
{}

Create a module

Next, we create a com.w3codebox.greetings module.

Step 1

Create a folder C:\>JAVA\src, and then create a folder with the same name as the module name com.w under this directory3codebox.greetings.

Step 2

In C:\>JAVA\src\com.w3Create a module under the codebox.greetings directory-The code of info.java file is as follows:

module com.w3codebox.greetings { }

module-info.java is used to create modules. In this step, we created com.w3codebox.greetings module.

Step 3

Add source code files in the module, in the directory C:\>JAVA\src\com.w3codebox.greetings\com\w3Create a file Java in the directory codebox\greetings9Tester.java, the code is as follows:

package com.w3codebox.greetings;
public class Java9Tester {
   public static void main(String[] args) {
      System.out.println("Hello World!");
   {}
{}

Step 4

Create the folder C:\>JAVA\mods and then create com.w in this directory3Compile the module to this directory: codebox.greetings folder

C:/>JAVA> javac -d mods/com.w3codebox.greetings 
   src/com.w3codebox.greetings/module-info.java 
   src/com.w3codebox.greetings/com/w3codebox/greetings/Java9Tester.java

Step 5

Execute the module and view the output results:

C:/>JAVA> java --module-path mods -m com.w3codebox.greetings/com.w3codebox.greetings.Java9Tester
Hello World!

module-path Specify the path where the module is located.

-m  Specify the main module.

Java 9 New Features