bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java requires Keyword

Flash cards

Review the key moves

1/4
Core idea

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.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ mymodule {
3Order

Put the learning moves in the order that makes the concept easiest to apply.

Use requires in a module's module-info.
Definition and Usage
Java requires Keyword

❮ 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

Previous

Java return Keyword

Next

Java short Keyword