Flash cards
Review the key moves
What is the main idea behind Java requires Keyword?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
Which statement best captures the main point of this lesson?
Complete the missing token from the example code.
___ mymodule {Put the learning moves in the order that makes the concept easiest to apply.
❮ Java Keywords
Example
Use requires in a module's module-info.java file:
module mymodule {
requires module1;
requires transitive module2;
requires static module3;
}Definition and Usage
The requires keyword is a module directive that specifies a different module which this module depends on.
There are two modifiers which can be added to the requires directive: transitive and static
The transitive modifier allows other modules to use this module without also having to declare this same requirement.
The static modifier makes the requirement optional during runtime. It allows this module to run even if the other module is not present.
Note
The requires keyword is a module directive meant to be used in the module-info.java file of a module.
The requires keyword was new in Java 9.
❮ Java Keywords