Define modules and their dependencies, expose module content including for reflection. Define services, producers, and consumers.
Compile Java code, produce modular and non-modular jars, runtime images, and implement migration using unnamed and automatic modules.
1. The correct answers are A and C.
Explanation:
module-info.java). The module system infers a module name from the JAR file name and exports all packages in the JAR.2. The correct answer is D.
Explanation:
module com.example { export com.example.api; }
exportsis missing an “s”. The correct syntax to export a package would be exports com.example.api;.declare module com.example { }
declare keyword used in the JPMS for defining a module.create module com.example { requires java.base; }
create keyword for module declaration.module com.example { }
com.example without any additional requirements.module com.example requires java.base;
{ } to define the module body.3. The correct answer is A.
Explanation:
module com.example { exports com.example.internal to com.example.client; }
exports directive with the to clause restricts the export of the com.example.internal package to only the specified module com.example.client.module com.example { opens com.example.internal to com.example.client; }
opens directive is used for reflection purposes, not for compile-time access control.module com.example { requires com.example.internal; }
requires directive is used to specify module dependencies, not to control package accessibility.module com.example { provides com.example.internal to com.example.client; }
provides directive is used to specify service providers in the module system, not for restricting package access.module com.example { uses com.example.internal; }
uses directive is used to specify service consumers in the module system, not for restricting package access.4. The correct answer is B.
Explanation:
com.example.client module can access the com.example.api package for deep reflection.
com.example.api package is exported, not opened, meaning it is available for use but not for deep reflection by other modules.com.example.client module cannot access the com.example.api package for deep reflection.
com.example.api package is not opened for deep reflection; it is only exported for use by other modules.com.example.api package is opened to all modules for deep reflection.
com.example.api package is exported to all modules, but it is not opened for deep reflection to any module.com.example.internal package is exported to the com.example.client module.
com.example.internal package is opened to com.example.client for deep reflection but not exported.com.example.api package is exported to the com.example.client module for deep reflection.
com.example.api package is exported to the com.example.client module, but exporting does not include deep reflection capabilities.5. The correct answer is D.
Explanation:
java.base module provides the Swing and AWT libraries for building graphical user interfaces.
java.base module does not provide the Swing and AWT libraries. These libraries are provided by the java.desktop module.java.logging module is responsible for handling collections, including lists, sets, and maps.
java.logging module is responsible for the logging framework in Java, not for handling collections. The collections framework is part of the java.base module.java.desktop module provides the classes for implementing standard input and output streams.
java.desktop module includes classes for building graphical user interfaces (Swing and AWT), not for standard input and output streams. Standard I/O is part of the java.base module.java.xml module includes the classes for processing XML documents.
java.xml module includes classes for processing XML documents, such as those for parsing and transforming XML using APIs like DOM, SAX, and StAX.java.naming module provides APIs for accessing and processing annotations.
java.naming module provides APIs for accessing naming and directory services (JNDI), not for processing annotations. Annotations are part of the java.base module.6. The correct answer is C.
Explanation:
javac -d out src/com.example/module-info.java src/com.example/com/example/*.java
--module-source-path option and does not specify the module name with -m.javac -sourcepath src -d out com.example/module-info.java com.example/com/example/*.java
-sourcepath option is not used for module compilation. The correct option should be --module-source-path.javac -d out --module-source-path src -m com.example
javac -d out --module-source-path src -m com.example command correctly compiles the module com.example located in the src directory and outputs the compiled classes to the out directory.javac -modulepath out -d src src/com.example/module-info.java src/com.example/com/example/*.java
-modulepath option is incorrectly placed, and the source and destination directories are swapped.javac --module-path src --module com.example -d out
--module-path instead of --module-source-path and the module name is specified with --module instead of -m.7. The correct answer is A.
Explanation:
javac --module-source-path src -d out $(find src -name "*.java")
javac --module-source-path src -d out $(find src -name "*.java") correctly compiles both modules by specifying the module source path and finding all Java files in the source directory.javac -d out --module com.foo,com.bar --module-source-path src
--module option does not accept multiple modules separated by commas in this context.javac -sourcepath src -d out src/com.foo/module-info.java src/com.foo/com/foo/*.java src/com.bar/module-info.java src/com.bar/com/bar/*.java
--module-source-path option and is unnecessarily verbose.javac -modulepath src -d out src/com.foo/*.java src/com.bar/*.java
-modulepath option is misused, and the path should point to the directory containing the module source code.javac --module-source-path src/com.foo,src/com.bar -d out
--module-source-path option should point to the base directory (src), not individual module directories.8. The correct answer is C.
Explanation:
requires com.example.Service with com.provider.ServiceImpl;
requires keyword is used to declare dependencies on other modules, not for specifying service providers.exports com.example.Service with com.provider.ServiceImpl;
exports keyword is used to make packages accessible to other modules, not for specifying service providers.provides com.example.Service with com.provider.ServiceImpl;
provides com.example.Service with com.provider.ServiceImpl; statement correctly specifies that the com.provider module provides an implementation of the com.example.Service.uses com.example.Service with com.provider.ServiceImpl;
uses keyword is used to declare that the module relies on a service but does not provide an implementation.9. The correct answer is D.
Explanation:
java --describe-module com.example/module-info.java
--describe-module option is not used with a specific file path like module-info.java; it requires a module name.javac --describe-module com.example
--describe-module option is not valid for the javac command; it is used with the java command.jar --describe-module com.example
--describe-module option is not valid for the jar command; it is used with the java command.java --describe-module com.example
java --describe-module com.example command correctly describes the module com.example using the --describe-module option.10. The correct answers are B and C.
Explanation:
jdeps --list-deps example.jar
--list-deps option does not exist for jdeps.jdeps -verbose example.jar
-verbose is a valid option, it provides more information.jdeps -s example.jar
-s option with jdeps provides a summary of the dependencies of the example.jar file.jdeps --check example.jar
--check option does not exist for jdeps.11. The correct answer is A.
Explanation:
jmod create --class-path mods/com.example --output com.example.jmod
jmod command to create a JMOD file. The create operation is specified, followed by the --class-path option to indicate the source directory, and finally the name of the output JMOD file. This command will create a JMOD file named com.example.jmod using the contents of the mods/com.example directory.jmod --create --class-path mods/com.example --output com.example.jmod
create operation in the jmod command should not be prefixed with --. The correct format is jmod create, not jmod --create. The rest of the command is correct, but this syntax error makes the entire command invalid.jmod --create --dir mods/com.example --output com.example.jmod
--create instead of create. Second, it uses the --dir option, which is not used for creating JMOD files, but for specifying the output directory when extracting files from a JMOD. When creating a JMOD file, we use --class-path to specify the source directory. The --output option is also not a valid option for the jmod command.jmod create --dir mods/com.example --output com.example.jmod
--dir option instead of --class-path for specifying the source directory, and it incorrectly includes an --output option, which is not valid for the jmod command. When creating a JMOD file, the output file name is simply specified as the last argument, not with an --output option.12. The correct answer is B.
Explanation:
jlink --module-path java.base:com.example --output myimage
--module-path option should specify the directory containing the modules, not the module names directly.jlink --module-path mods --add-modules java.base,com.example --output myimage
jlink --module-path mods --add-modules java.base,com.example --output myimage correctly specifies the module path and adds the necessary modules, outputting the custom runtime image to the myimage directory.jlink --add-modules java.base,com.example --image myimage
--image option is not valid; the correct option is --output.jlink --modules java.base,com.example --dir myimage
--modules option is incorrect; the correct option is --add-modules, and --dir should be --output.13. The correct answer is D.
Explanation:
module-info.java file to be placed on the module path.
module-info.java file. Their module name is inferred from the JAR file name.module-info.java.
module-info.java.module-info.java is placed on the module path, and it can read all other modules.
module-info.java on the module path. This automatic module can read all other modules, both named and unnamed.Do you like what you read? Would you consider?
Do you have a problem or something to say?