Oracle Java OCP Modules and Packaging Quiz

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Thames
T
Thames
Community Contributor
Quizzes Created: 11982 | Total Attempts: 187,298
| Questions: 20 | Updated: Aug 15, 2026
Please wait...
Question 1 / 21
🏆 Rank #-- ▾
0 %
0/100
Score 0/100

1. What does the 'opens' statement do in a module declaration?

Explanation

In Java’s module system, an `opens` directive permits code in other modules to use reflection to access a package’s types and members at runtime, including non-public members when access checks allow it. Unlike `exports`, it does not grant ordinary compile-time access to the package.

Submit
Please wait...
About This Quiz
Oracle Java OCP Modules and Packaging Quiz - Quiz

This quiz tests your understanding of Java modules and packaging, core topics for the Oracle Java SE Developer OCP certification. You'll be evaluated on module declarations, exports, requires statements, packaging conventions, and the Java Platform Module System (JPMS). Master these concepts to build scalable, maintainable applications and prepare for the... see moreOCP exam. see less

2.

What first name or nickname would you like us to use?

You may optionally provide this to label your report, leaderboard, or certificate.

2. True or False: A package can be exported from multiple modules in the same application.

Explanation

An application may contain several modules, but each export package is tied to a single module. It cannot be generated jointly from multiple modules in that application. If you need to transfer more than one module, export them individually and manage the resulting packages separately. Thus, the statement is false.

Submit

3. Which command-line option lists all available modules in the JDK?

Explanation

The `--list-modules` option displays the modules available in the JDK’s runtime image, including their names and versions. Run it with the `java` command to see the module inventory. The other options are not the standard command-line flag for listing all available JDK modules.

Submit

4. What does 'module encapsulation' refer to in the Java Platform Module System?

Explanation

Module encapsulation limits access to a module’s packages. By explicitly declaring which packages it exports, a module makes its public API available while keeping other implementation details inaccessible to code outside the module.

Submit

5. True or False: An unnamed module can access all exported packages from named modules.

Explanation

In Java’s module system, an unnamed module (such as code on the classpath) reads all named modules. It can therefore access their packages when those packages are exported; packages that are not exported remain inaccessible.

Submit

6. Which statement pairs with 'uses' to provide a service implementation?

Explanation

In Java’s module system, `uses` declares a service that a module consumes, while `provides` declares that the module supplies an implementation of a service. The `provides` directive is followed by `with` and the implementation class name.

Submit

7. What is the purpose of the 'uses' statement in module-info.java?

Explanation

In Java’s module system, a `uses` directive declares that a module consumes a service through a specified service interface, typically using `ServiceLoader`. It tells the runtime that implementations of this service may be supplied by other modules. It does not import a class, export a package, or define a regular compile-time dependency.

Submit

8. True or False: You can have multiple module declarations in a single module-info.java file.

Explanation

A `module-info.java` file can contain only one module declaration. That declaration defines a single module and its dependencies, exports, and other directives. Declaring multiple modules in the same file is invalid; each module must have its own `module-info.java` file.

Submit

9. In the Java Platform Module System, what is a 'named module'?

Explanation

A named module declares its identity and dependencies explicitly in a `module-info.java` file. This descriptor can also specify which packages the module exports and which other modules it requires.

Submit

10. Which naming convention is recommended for Java package names?

Explanation

Java package names are typically written in all lowercase to avoid confusion with class names and maintain consistency. Dots separate parts of the package hierarchy, often reflecting an organization’s domain name and project structure, such as `com.example.app`.

Submit

11. What keyword is used to declare a module in Java?

Explanation

Java modules are declared using the `module` keyword, typically in a `module-info.java` file. The declaration names the module and can specify its dependencies and which packages it makes available to other modules.

Submit

12. True or False: All modules automatically depend on java.base.

Explanation

Under the Java Platform Module System’s mandated-dependence rule, every named module except `java.base` implicitly depends on `java.base`. The foundational `java.base` module does not depend on itself. Therefore, although other modules automatically depend on it, the statement’s use of “all” makes it inaccurate.

Submit

13. What is the 'java.base' module in the Java Platform Module System?

Explanation

The `java.base` module provides the fundamental classes and APIs used by the Java platform, including packages such as `java.lang` and `java.util`. It is the base dependency for nearly all other Java modules and is automatically available to every Java application, so it is not optional or a third-party module.

Submit

14. Which of the following is NOT a valid module statement?

Explanation

In Java’s module descriptor, valid directives include `requires` to declare dependencies, `exports` to make a package accessible to other modules, and `opens` to allow reflective access. `imports` is not a module directive; imports belong in ordinary Java source files, not in `module-info.java`.

Submit

15. What does 'requires static' mean in a module declaration?

Explanation

In a Java module declaration, `requires static` makes a dependency available for compilation but does not require it to be present at runtime. This is useful when the module uses a library during compilation, such as for annotations, but can operate without that library when running. The dependency is therefore optional at runtime.

Submit

16. True or False: A module can export a package that contains only internal classes.

Explanation

An `exports` directive can name any package in a module, even if it contains only package-private or internal classes. The directive remains valid, but other modules generally cannot access those classes directly because they are not public. Exporting a package does not require it to contain publicly accessible API types.

Submit

17. Which keyword allows a module to depend on another module transitively?

Explanation

In Java’s module system, `requires transitive` declares a dependency that is re-exported to modules depending on the declaring module. This means clients of that module can access the required module’s exported packages without declaring their own direct `requires` statement. By contrast, plain `requires` keeps the dependency visible only to the declaring module.

Submit

18. What is the purpose of the 'requires' statement in module-info.java?

Explanation

The `requires` statement declares that a module depends on another module. This lets the Java module system resolve the dependency and make the required module’s accessible packages available during compilation and runtime.

Submit

19. In a module declaration, what does the 'exports' statement do?

Explanation

The `exports` statement in a module declaration makes a package accessible to other modules that depend on it. It controls which packages are exposed as part of the module’s public API.

Submit

20. Which file contains module declarations in a Java project?

Explanation

In Java’s module system, `module-info.java` declares a module’s name and its dependencies and defines which packages it exports or opens. It is typically placed at the root of the module’s source directory. The other options serve different purposes or belong to other tools and frameworks.

Submit
×
Saved
Thank you for your feedback!
View My Results
Cancel
  • All
    All (20)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What does the 'opens' statement do in a module declaration?
True or False: A package can be exported from multiple modules in the...
Which command-line option lists all available modules in the JDK?
What does 'module encapsulation' refer to in the Java Platform Module...
True or False: An unnamed module can access all exported packages from...
Which statement pairs with 'uses' to provide a service implementation?
What is the purpose of the 'uses' statement in module-info.java?
True or False: You can have multiple module declarations in a single...
In the Java Platform Module System, what is a 'named module'?
Which naming convention is recommended for Java package names?
What keyword is used to declare a module in Java?
True or False: All modules automatically depend on java.base.
What is the 'java.base' module in the Java Platform Module System?
Which of the following is NOT a valid module statement?
What does 'requires static' mean in a module declaration?
True or False: A module can export a package that contains only...
Which keyword allows a module to depend on another module...
What is the purpose of the 'requires' statement in module-info.java?
In a module declaration, what does the 'exports' statement do?
Which file contains module declarations in a Java project?
play-Mute sad happy unanswered_answer up-hover down-hover success oval cancel Check box square blue
Alert!