About Question enthuware.ocpjp.i.v11.2.3007 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
dorescanin
Posts: 3
Joined: Sun Nov 22, 2020 12:08 pm
Contact:

About Question enthuware.ocpjp.i.v11.2.3007 :

Post by dorescanin »

Question:

Identify correct statements about java modules.

One of the provided answers is "module-info.java must not be empty." Provided explanation: "At a minimum, it must specify the module name."

Technically, this doesn't need to be always true. It is possible to compile module-info.java without it having any content - it can be a 0-byte file. Of course, when it is compiled, it is not really usable as a module-info file for a named module and the corresponding source code that is present and packed into a jar file can be used as an unnamed module - you can run a main class in a jar file with that compiled (but useless) module-info.class also present in the jar.

I was wondering if my explanation makes sense, or am I mistaken somewhere? Or does the question refer exclusively to named modules?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3007 :

Post by admin »

Not sure how you checked it but I tried compiling the example given in the book with an empty module-info.java and it didn't compile:
C:\ocp11\moduletest>javac -d out --module-source-path src --module calculators
src\calculators\module-info.java:1: error: expected 'module'
1 error
If you like our products and services, please help us by posting your review here.

dorescanin
Posts: 3
Joined: Sun Nov 22, 2020 12:08 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3007 :

Post by dorescanin »

I took a different route - tried to just compile everything as usual using javac - both module-info and the rest of the source files: "javac src/module-info.java src/**/*.java". After that, packing the compiled classes into a jar file will still provide a workable unnamed module.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3007 :

Post by admin »

OK, that is not the right route. What you are doing is compiling a class, not a module. In your case, module-info.java would be inferred as just a java source file containing type definitions, not a module definition. You can have an empty java source file containing no type definition.
If you like our products and services, please help us by posting your review here.

dorescanin
Posts: 3
Joined: Sun Nov 22, 2020 12:08 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3007 :

Post by dorescanin »

Ok, thanks for the clarification. I was studying from a resource that didn't mention "--module-source-path" but used conventional javac compilation instead. It also mentioned that module-info.java can be completely empty and this is why I was somewhat surprised to see that my answer to this question wasn't correct. This is why it's great to have multiple resources for study at disposal.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3007 :

Post by admin »

Yes, I understand your concern. But the problem statement set the context of the question very clearly when it says, "Identify correct statements about java modules.". So, the question and options are about java modules. You need to pick the options accordingly.
If you like our products and services, please help us by posting your review here.

floryan
Posts: 17
Joined: Sun Sep 23, 2018 4:10 am
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3007 :

Post by floryan »

I feel this question is too vage and can be misunderstood very easily. The module-info.java file obviously relates to modules and hence is "about java modules". I feel the question should ask about the "correct usage of java modules" or something along those lines.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3007 :

Post by admin »

Not sure I understand your point. If it is already clear that the question is about modules, then what is the issue? Why do you think it is vague? How else would you interpret the question?
If you like our products and services, please help us by posting your review here.

runforrestrun
Posts: 2
Joined: Fri Apr 09, 2021 4:22 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3007 :

Post by runforrestrun »

It is maybe because in the "OCP Oracle Certified Professional Java SE 11 Developer Complete Study Guide", it states:

"CAN A MODULE-INFO.JAVA FILE BE EMPTY?
Yes. As a bit of trivia, it was legal to compile any empty file with a .java extension even before modules. The compiler sees there isn’t a class in there and exits without creating a .class file."

So if a person read this once, and gets this question later. You might interpret the question like the above title: "Can a module-info.java file be empty". One be inclined to say no.

I get the confusion and agree with Floryan.

If the question would be indeed something like "correct usage of java modules" I would easily state there should be something in the module-info.java or you still be having an unnamed module.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3007 :

Post by admin »

Well, if the book says that "A MODULE-INFO.JAVA FILE BE EMPTY" then that book is wrong. The question clearly says that it is about modules and if you put an empty module-info.java in the module root directory, you will get a compilation error. Therefore, the issue is with the book for being vague and not with this question/option.

You might want to report this to the concerned author.
If you like our products and services, please help us by posting your review here.

samba2
Posts: 6
Joined: Mon Sep 06, 2021 1:13 am
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3007 :

Post by samba2 »

just to add-on. Here is another learner how did not select "must not be empty" due to studying the sybex book before.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3007 :

Post by admin »

Again, you really need to tell the author of the book about this because that is where the issue exists.
If you like our products and services, please help us by posting your review here.

sohamdatey22
Posts: 28
Joined: Sun Sep 11, 2022 3:55 am
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3007 :

Post by sohamdatey22 »

More Knowledge, is curse again? :D
I too came after reading the book.
Let's hope the exams, does not do this to us.

Badem48
Posts: 26
Joined: Thu Aug 24, 2023 4:33 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3007 :

Post by Badem48 »

I am little bit confused when it says "module-info.java must not be empty" is this mean the file to be empty or is this mean it has a format like this:
module module.name{ }
Without any exports or requires?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.i.v11.2.3007 :

Post by admin »

It says module-info.java not just module-info. module-info.java implies that it is talking about the file being empty and not about the logical module-info.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: marpiva and 41 guests