Page 1 of 1

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

Posted: Sun Nov 22, 2020 12:26 pm
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?

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

Posted: Sun Nov 22, 2020 6:41 pm
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

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

Posted: Mon Nov 23, 2020 2:26 am
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.

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

Posted: Mon Nov 23, 2020 5:51 am
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.

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

Posted: Mon Nov 23, 2020 6:21 am
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.

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

Posted: Mon Nov 23, 2020 8:40 am
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.

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

Posted: Mon Aug 30, 2021 12:56 pm
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.

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

Posted: Mon Aug 30, 2021 9:24 pm
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?

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

Posted: Thu Sep 09, 2021 6:49 am
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.

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

Posted: Thu Sep 09, 2021 7:40 am
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.

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

Posted: Sun Oct 03, 2021 3:07 pm
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.

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

Posted: Sun Oct 03, 2021 9:23 pm
by admin
Again, you really need to tell the author of the book about this because that is where the issue exists.

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

Posted: Fri Sep 30, 2022 7:10 am
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.

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

Posted: Sun Dec 24, 2023 10:01 am
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?

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

Posted: Sun Dec 24, 2023 10:11 am
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.