Java 21 Certification Guide - Part 6
Welcome to the sixth article in my series on preparing for the Java 21 certification.
Over the next several posts, we’ll walk through the most important language changes, APIs, and tricky details you’ll need to know for the exam.
In this article, we’ll focus on modules, introduced on Java 9. These concepts aren’t something most developers use in their daily work, so they can feel a bit tricky.
To make things practical, we’ll analyze a question in the style of the certification exam.
❓ Question
Select 3 correct statements below:
A) A named module must have a module-info.java
file that explicitly declares its name and dependencies.
B) An unnamed module includes all the classes on the classpath that are not part of any named module.
C) An automatic module is created when you place a JAR without a module-info.java
on the module path, and its name is derived from the JAR filename.
D) A named module can read from the unnamed module only if the requires
directive is present.
🔎 Explanation
A) A named module is explicitly defined with a module-info.java
. It must declare its own name and any requires
dependencies. Without it, the compiler won’t recognize it as a named module.
B) The unnamed module is a special catch-all for classes and JARs on the classpath. It does not have a module-info.java
and serves as a bridge for legacy applications that still use the classpath.
C) An automatic module is created when you place a traditional JAR (without module-info.java
) on the module path. Its name is derived from the JAR filename (e.g., mylib-1.2.jar
→ module mylib
).
D) ❌ Incorrect
A named module cannot require the unnamed module via requires
. This is a one-way relationship: the unnamed module can access named modules, but not vice versa.
✅ Correct Answer
A, B, C
⚡ Next in this series: we’ll dive into Virtual Threads.
📬 Stay tuned:
If you don’t want to miss the upcoming parts of this Java 21 Certification series, hit the Subscribe button below.