About Question enthuware.ocpjp.i.v11.2.3007 :
Moderator: admin
-
- Posts: 3
- Joined: Sun Nov 22, 2020 12:08 pm
- Contact:
About Question enthuware.ocpjp.i.v11.2.3007 :
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?
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?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3007 :
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
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.
-
- Posts: 3
- Joined: Sun Nov 22, 2020 12:08 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3007 :
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.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3007 :
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.
-
- Posts: 3
- Joined: Sun Nov 22, 2020 12:08 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3007 :
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.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3007 :
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.
-
- Posts: 17
- Joined: Sun Sep 23, 2018 4:10 am
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3007 :
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.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3007 :
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.
-
- Posts: 2
- Joined: Fri Apr 09, 2021 4:22 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3007 :
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.
"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.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3007 :
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.
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.
-
- Posts: 6
- Joined: Mon Sep 06, 2021 1:13 am
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3007 :
just to add-on. Here is another learner how did not select "must not be empty" due to studying the sybex book before.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3007 :
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.
-
- Posts: 28
- Joined: Sun Sep 11, 2022 3:55 am
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3007 :
More Knowledge, is curse again?
I too came after reading the book.
Let's hope the exams, does not do this to us.
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
I too came after reading the book.
Let's hope the exams, does not do this to us.
-
- Posts: 26
- Joined: Thu Aug 24, 2023 4:33 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3007 :
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?
module module.name{ }
Without any exports or requires?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.3007 :
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.
Who is online
Users browsing this forum: No registered users and 106 guests