Courseiva
What is JavahardMultiple ChoiceObjective-mapped

1Z0-811 What is Java Practice Question

A development team is building a modular Java application using Java 17. They have defined a module named com.myapp with a module-info.java that includes 'requires com.thirdparty.lib;'. The com.thirdparty.lib module is a third-party library packaged as a modular JAR with its own module-info.class. The application compiles successfully using javac with the module path pointing to the directory containing the JAR. However, when starting the application with java --module-path <path> --module com.myapp, a NoClassDefFoundError occurs for a class from com.thirdparty.lib. The error message indicates the class is not found. The team has confirmed that the JAR file is present in the specified module path and that the class exists in the JAR. No other errors or warnings are displayed. The team is puzzled because the code compiles without issues. What is the most likely cause of this runtime error?

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

The module com.thirdparty.lib does not export the package containing the required class in its module-info.java.

In modular Java, a module must explicitly export a package using the 'exports' directive in its module-info.java for that package to be accessible by other modules. If com.thirdparty.lib does not export the package containing the required class, the class is present in the module but not accessible at runtime, leading to a NoClassDefFoundError even though compilation succeeded. Option D is correct because the missing exports directive causes this issue. Option A is incorrect because module path order affects module resolution, not accessibility of exported packages; if the module is resolved, the correct JAR is used. Option B is incorrect because if the library were incompatible with Java 17, compilation would typically fail or generate different errors (e.g., UnsupportedClassVersionError). Option C is incorrect because version requirements in 'requires' are optional and generally produce compile-time warnings/errors, not a runtime NoClassDefFoundError for a class that exists.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The module path order is incorrect, causing a different version of the library to be loaded.

    Why it's wrong here

    Module path order affects resolution, but the error would typically be a resolution error, not NoClassDefFoundError for a particular class.

  • The library is not compatible with Java 17.

    Why it's wrong here

    If the library were incompatible, the error would likely occur during compilation or manifest as a linkage error (e.g., UnsupportedClassVersionError).

  • The application's module requires the wrong version of the library.

    Why it's wrong here

    Version requirements would cause a resolution error at startup, not a NoClassDefFoundError for a specific class that exists.

  • The module com.thirdparty.lib does not export the package containing the required class in its module-info.java.

    Why this is correct

    Even though the module is on the module path, its packages are not accessible without an 'exports' directive.

Visual reference

Client Recursive Resolver Root DNS (13 root servers) TLD DNS (.com, .org, …) Authoritative example.com query IP addr answer

About these practice questions

One of 481 original 1Z0-811 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.