Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

requires

Example

Employ the requires keyword within a module’s module-info.java file to specify dependencies on other modules.

module mymodule {
 requires module1;
  requires transitive module2;
  requires static module3;
}

Definition and Usage

The requires keyword, as a module directive, indicates another module on which the current module relies.

Additionally, two modifiers, transitive and static, can be appended to the requires directive.

The transitive modifier enables other modules to utilize the current module without needing to explicitly declare the same dependency.

The static modifier renders the requirement optional at runtime, allowing the current module to function even if the dependent module is absent.

Note: The requires keyword is a module directive intended for use within a module’s module-info.java file.

The introduction of the requires keyword occurred in Java 9.