> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Java Requires Directive

The `requires` directive is a module declaration statement within a `module-info.java` file used to specify a dependency on another module. Introduced in the Java Platform Module System (JPMS), it establishes a formal "reads" relationship. This dictates that the declaring module depends on the target module to successfully compile and execute.

## Syntax

```java theme={"dark"}
module <module.name> {
    requires [modifiers] <target.module.name>;
}
```

## Mechanics and Resolution

When the Java compiler or the JVM encounters a `requires` directive, it searches the module path for the specified target module. If the target module is found, the module system grants the requiring module readability of the target module. This allows the requiring module to access public types in packages that the target module exports unconditionally, or exports specifically to the requiring module via a qualified `exports ... to` directive.

If a required module is missing from the module path, the compiler emits an error, and the JVM throws a `java.lang.module.FindException` at startup. Other graph resolution failures, such as cyclic dependencies or split packages, result in a `java.lang.module.ResolutionException`.

By default, the `java.base` module is implicitly required by all other Java modules. Explicitly declaring `requires java.base;` is permitted but redundant. Furthermore, the JPMS strictly prohibits cyclic dependencies; if module A requires module B, module B cannot require module A (neither directly nor transitively).

## Modifiers

The `requires` directive accepts specific modifiers that alter the strictness and propagation of the dependency.

### Standard `requires`

A standard `requires` statement without modifiers creates a strict, encapsulated dependency required at both compile-time and runtime. Modules that depend on the declaring module do not inherit readability of this required module.

```java theme={"dark"}
module com.example.core {
    requires java.sql;
}
```

### `requires transitive`

The `transitive` modifier establishes "implied readability." If Module A declares `requires transitive` on Module B, any Module C that requires Module A will automatically be granted readability of Module B. This is mechanically necessary when types from the required module are exposed in the public API signatures of the declaring module.

```java theme={"dark"}
module com.example.api {
    requires transitive java.xml;
}
```

### `requires static`

The `static` modifier creates a compile-time dependency that is strictly optional at runtime. The module system mandates the presence of the target module during compilation but does not require it for runtime resolution. If the target module is absent at runtime, the JVM starts normally without throwing a `FindException`. However, if the target module is present and resolved at runtime (for example, because it is required by another module in the resolved graph or added manually via `--add-modules`), the reads relationship is actively established, and the requiring module can use its types normally without reflection.

```java theme={"dark"}
module com.example.utils {
    requires static java.compiler;
}
```

### `requires transitive static`

Modifiers can be combined to create a dependency that is optional at runtime but transitively propagated to dependent modules at compile-time. The order of the modifiers does not matter (`requires static transitive` is also valid).

```java theme={"dark"}
module com.example.framework {
    requires transitive static java.desktop;
}
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Java Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
