The Java Platform Module System (JPMS), introduced in Java 9, modularizes the Java platform and applications. Understanding the behavior of named and unnamed modules is crucial.
Correct. The unnamed module, which includes all code on the classpath, exports all of its packages. This means that any code can access the public types in these packages. However, the unnamed module cannot be explicitly required by named modules.
C. If a package is defined in both a named module and the unnamed module, then the package in the unnamed module is ignored.
Correct. In cases where a package is present in both a named module and the unnamed module, the version in the named module takes precedence. The package in the unnamed module is ignored to maintain module integrity and avoid conflicts.
F. If a request is made to load a type whose package is not defined in any known module, then the module system will attempt to load it from the classpath.
Correct. When the module system cannot find a requested type in any known module, it defaults to searching the classpath (i.e., the unnamed module) to locate the type.
Incorrect Options:
Incorrect. Named modules cannot access types in the unnamed module. The unnamed module can read from named modules, but the reverse is not allowed to ensure strong encapsulation.
D. We must add a module descriptor to make an application developed using a Java version prior to SE9 run on Java 11.
Incorrect. Adding a module descriptor (module-info.java) is not mandatory for applications developed before Java 9 to run on Java 11. Such applications can run in the unnamed module without modification.
Incorrect. The unnamed module can access all packages exported by all named modules, in addition to its own packages.