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

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

Moderator: admin

Post Reply
sir_Anduin@yahoo.de
Posts: 62
Joined: Fri Aug 07, 2015 2:16 pm
Contact:

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

Post by sir_Anduin@yahoo.de »

Hi,
Could you give an explanation to
Api.bloggerservice should be defined in serviceapi module
, please?

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

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

Post by admin »

From the two lines in the definition of abc.blogger module :
requires serviceapi; <----- This means api.BloggerService is in serviceapi module
provides api.BloggerService with abc.SimpleBlogger; <---- This means abc.SimpleBlogger implements api.BloggerService.
If you like our products and services, please help us by posting your review here.

sir_Anduin@yahoo.de
Posts: 62
Joined: Fri Aug 07, 2015 2:16 pm
Contact:

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

Post by sir_Anduin@yahoo.de »

but why can´t SimpleBlogger be in another module?
Is it because it would need another requires statement?

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

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

Post by admin »

sir_Anduin@yahoo.de wrote:
Wed Sep 04, 2019 11:44 pm
but why can´t SimpleBlogger be in another module?
Is it because it would need another requires statement?
Correct. The existing requires statement is "requires serviceapi;".
If you like our products and services, please help us by posting your review here.

wakedeer
Posts: 3
Joined: Tue Apr 21, 2020 7:04 am
Contact:

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

Post by wakedeer »

abc.blogger module should be on --module-path while executing author module but is not required while compiling.
In my view, it is not necessary. We can run author module without abc.blogger module. In this case, ServiceLoader returns nothing, but it is not an error.

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

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

Post by admin »

That's why the problem statement says "should" and not "must". From the problem statement, it is clear that the idea is to be able to use the abc.blogger module.
If you like our products and services, please help us by posting your review here.

minajev3
Posts: 18
Joined: Fri Feb 05, 2021 3:37 am
Contact:

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

Post by minajev3 »

Sorry But how can "author module" use api.BloggerService if there is no "requires abc.blogger" in module-info? (and also exports statement in module abc.blogger module-info)

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

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

Post by admin »

The author module already has "requires serviceapi;"
and that is why option 3 "api.BloggerService should be defined in serviceapi module." is a correct option.
If you like our products and services, please help us by posting your review here.

minajev3
Posts: 18
Joined: Fri Feb 05, 2021 3:37 am
Contact:

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

Post by minajev3 »

Yes, sorry I expressed my question wrongly somehow))

Real question was - why do author module even need abc.blogger module while executing?
It can be on module path, but there will be no use of it for author right ?

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

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

Post by admin »

Well, the serviceapi module only contains the service interface. No implementation. It is the abc.blogger module that contains the implementation. Observe the line "provides api.BloggerService with abc.SimpleBlogger;" in abc.blogger's module info.
When you run the author module, you need abc.blogger module on the path, so that an implementation for the BloggerService can be availed by the classes of the author module.
If you like our products and services, please help us by posting your review here.

cjgiron
Posts: 14
Joined: Fri Sep 09, 2022 5:03 pm
Contact:

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

Post by cjgiron »

Hi Admin,

Could you please explain how to determine which modules are needed for compilation vs. executing the application?

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

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

Post by admin »

The process is same for regular packages/classes. If you are directly using a class name in your code (for example, for a variable type or in extends/implements/throw clause and so on), the compiler will need to read that class and so that is a compile time dependency. If a class is loaded only at run time without getting referenced directly in code, then it is a runtime dependency. For example, you do Class.forName("a.b.c.MyClass"), here MyClass is not being referenced directly in the code (as far as the compiler is concerned, "a.b.c.MyClass" is just a string. But the forName method will try to load this class at runtime. So, this class will be required only at runtime.

Modules also work similarly. If you have a requires clause that refers to a module then you will need that module at compile time. Otherwise, only at runtime.

For complete details, you may go through this document: https://openjdk.org/jeps/261
If you like our products and services, please help us by posting your review here.

likejudo
Posts: 25
Joined: Sun Feb 18, 2024 7:21 pm
Contact:

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

Post by likejudo »

This seems different from the Boyarsky book.

abc.blogger module is the provider of the service. Agreed.
From the explanation on the last option, are you saying that author is a consumer?
From Boyarsky's book, it would be a service locator.

Code: Select all

module author {   
requires serviceapi;   
uses api.BloggerService; 
}
Java 17. page 682. Creating a Service Locator

Code: Select all

module zoo.tours.reservations {
   exports zoo.tours.reservations;
   requires zoo.tours.api;
   uses zoo.tours.api.Tour;
}
Consumer

Code: Select all

module zoo.visitor {
   requires zoo.tours.api;
   requires zoo.tours.reservations;
}
Perhaps I misunderstood?

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

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

Post by admin »

The author module says it "uses" BloggerService. So it is a consumer of that service. Where is the confusion?
BloggerService does not depend on author module so abc.blogger module doesn't need the author module. That is why the last option is wrong.

Service locators are higher level abstractions, which an application may or may not use. Modules have nothing to do with it.
If you like our products and services, please help us by posting your review here.

likejudo
Posts: 25
Joined: Sun Feb 18, 2024 7:21 pm
Contact:

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

Post by likejudo »

admin wrote:
Mon Apr 22, 2024 11:23 pm
The author module says it "uses" BloggerService. So it is a consumer of that service. Where is the confusion?
BloggerService does not depend on author module so abc.blogger module doesn't need the author module. That is why the last option is wrong.

Service locators are higher level abstractions, which an application may or may not use. Modules have nothing to do with it.
According to Boyarsky's book, the Consumer only has "requires", the Service Locator has "uses". author would be a ServiceLocator, according to the book.

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

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

Post by admin »

You need to check with the author of the book. As explained above, the modules functionality doesn't know or care about service locator or any other design pattern.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 111 guests