nerdexam
Oracle

1Z0-819 · Question #152

Which command line runs the main class com.acme.Main from the module com.example?

The correct answer is D. java --module-path example.jar -m com.example/com.acme.Main. Option D is correct because it combines two required elements: the -m flag (or --module) to specify the module, and the module/mainclass format (com.example/com.acme.Main), with the module packaged as example.jar on the module path. A is wrong because it omits the -m flag…

Java Platform Module System

Question

Which command line runs the main class com.acme.Main from the module com.example?

Options

  • Ajava --module-path mods com.example/com.acme.Main
  • Bjava --module-path mods com.acme.Main
  • Cjava --module-path mods -m com.example/com.acme.Main
  • Djava --module-path example.jar -m com.example/com.acme.Main

How the community answered

(27 responses)
  • A
    4% (1)
  • B
    7% (2)
  • C
    15% (4)
  • D
    74% (20)

Explanation

Option D is correct because it combines two required elements: the -m flag (or --module) to specify the module, and the module/mainclass format (com.example/com.acme.Main), with the module packaged as example.jar on the module path.

  • A is wrong because it omits the -m flag entirely - without it, Java treats com.example/com.acme.Main as a class name, which is invalid syntax.
  • B is wrong for the same reason: no -m flag, and com.acme.Main without a module qualifier is just an unqualified class name, which won't resolve correctly in the module system.
  • C has the correct syntax structure (-m com.example/com.acme.Main) but uses mods (a directory) as the module path instead of the actual JAR file example.jar - the module can't be found if the path doesn't point to where it lives.

Memory tip: Think of -m as "module mode" - you always need it when launching from the module system, and the argument always follows the pattern moduleName/fullyQualifiedMainClass. If you see a command with --module-path but no -m, it's broken.

Topics

#module path#module execution#java command#JPMS

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice