CKTIS / Java
module — JPMS module declaration
module — JPMS module declaration: module is a contextual keyword that begins a module declaration in module-info.java; outside that context it may be an ordinary identifier.
Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Syntax
modulemodule is a contextual keyword that begins a module declaration in module-info.java; outside that context it may be an ordinary identifier.
Use a JPMS module to name a component and explicitly state requires, exports, opens, uses, and provides at the deployment boundary.
exports exposes public types for ordinary access but does not open private members to deep reflection; opens controls that access.
Named modules cannot form a requires cycle; code run only on the class path belongs to an unnamed module whose Module.isNamed returns false.
A variable with the contextual name module legally stores 21 and prints module=21; class-path execution confirms the unnamed module with named=false.
Examples
public class Main {
public static void main(String[] args) {
int module = 21;
Module owner = Main.class.getModule();
System.out.println("module=" + module);
System.out.println("named=" + owner.isNamed());
}
}
Result
module=21 named=false
A variable with the contextual name module legally stores 21 and prints module=21; class-path execution confirms the unnamed module with named=false.