About Question enthuware.ocpjp.ii.v11.2.3428 :

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

Moderator: admin

Post Reply
dongyingname
Posts: 18
Joined: Sat Jun 22, 2019 4:10 pm
Contact:

About Question enthuware.ocpjp.ii.v11.2.3428 :

Post by dongyingname »

Code: Select all

module abc.myapp{   
	requires com.abc.datalayer;
}
Could some one explain why this is not the option?
I am assuming myapp.jar and datalayer.jar are in the same folder and is that why com.abc is omitted?
Why is the application module called abc.myapp while the dependency is called datalayer not abc.datalayer?

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

Re: About Question enthuware.ocpjp.ii.v11.2.3428 :

Post by admin »

myapp.jar is being modularized, so, its module name can be anything that you want. From the options, it looks like it is being named abc.myapp.

datalayer.jar is not being modularized. This jar is being used as an automaric module, so, its module name will be datalayer.
If you like our products and services, please help us by posting your review here.

teodorj
Posts: 33
Joined: Tue Jun 19, 2018 10:27 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3428 :

Post by teodorj »

Note: There are two possible ways for an automatic module to get its name:
1. When an Automatic-Module-Name entry is available in the manifest, its value is the name of the automatic module.
2. Otherwise, a name is derived from the JAR filename (see the ModuleFinder JavaDoc for the derivation algorithm) -
Basically, hyphens are converted into dots and the version number part is ignored.
So, for example, if you put mysql-connector-java-8.0.11.jar on module path, its module name would be mysql.connector.java
If I am modularizing my application and dependent on other jars i.e analytics and added in module path as automatic module..

1) Can I provide automatic module name programatically in module-info.java (using ModuleDescriptor.name() method ) of my app?
2) I will just use ModuleFinder to get the name and manually add the name in my appplication's module-info.java?

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

Re: About Question enthuware.ocpjp.ii.v11.2.3428 :

Post by admin »

Sometimes, a provider may want to modularize their jar in near future but hasn't completed that task. In that case, they may add a Automatic-Module-Name entry in their jar's manifest. So, if you put that jar in your module-path, it will still be an automatic module (because there will be no module-info.class file in that jar), but the name of that automatic module will be the name that the provider specified in the Automatic-Module-Name entry.

If you are modularizing your application and are dependent on third party analytics jar, you can directly add it to module-path. You don't add module-info to that jar because it is not your jar.

Regarding Module finder, it is not on for the exam. You are overthinking.
If you like our products and services, please help us by posting your review here.

teodorj
Posts: 33
Joined: Tue Jun 19, 2018 10:27 am
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.3428 :

Post by teodorj »

I am just thinking about the application of the concept regarding adding name in requires directive in my app's module-info(getting automatic module name of third party)

Yes this is not in exam coverage. Im just applying the theories in real project. :D

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

Re: About Question enthuware.ocpjp.ii.v11.2.3428 :

Post by admin »

Name of an automatic module is always known at compile time. It is either the same as the jar file name (without the dashes and version number) or it is what is specified in Automatic-Module-Name entry in the jar's manifest.
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.ii.v11.2.3428 :

Post by floryan »

datalayer will be able to access mysql classes if you simply put the mysql jar on the classpath.
It would also work, if we put the mysql jar on the module path as automatic module too, right?

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

Re: About Question enthuware.ocpjp.ii.v11.2.3428 :

Post by admin »

yes, automatic modules can access any class anywhere. But, of course, you don't want to put anything on module-path unless you really need to because you don't want anything to have access to everything else.
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 28 guests