J.VIII · Java 25 practice question

In a module declaration, what is the purpose of a `provides ... with ...` directive?

Choose one answer
Check answer and explanation

Correct answer: It specifies a service and one or more service providers for java.util.ServiceLoader

Explanation

The provides directive pairs a service type with one or more service provider implementations via its with clause for discovery by java.util.ServiceLoader.

Common trap

Qualified exports use `exports ... to ...`, not `provides ... with ...`. The Java module system does not perform annotation-based dependency injection; it integrates with java.util.ServiceLoader.

Source: JLS SE 25 §7.7.4. Service Provision
Checked against the cited text on 2026-11-25.

Report an error in this question