Page 1 of 1

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

Posted: Wed Sep 04, 2019 12:15 am
by sir_Anduin@yahoo.de
Hi,
Could you give an explanation to
Api.bloggerservice should be defined in serviceapi module
, please?

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

Posted: Wed Sep 04, 2019 12:29 am
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.

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

Posted: Wed Sep 04, 2019 11:44 pm
by sir_Anduin@yahoo.de
but why can´t SimpleBlogger be in another module?
Is it because it would need another requires statement?

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

Posted: Thu Sep 05, 2019 12:01 am
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;".

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

Posted: Wed Apr 29, 2020 3:44 am
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.

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

Posted: Wed Apr 29, 2020 4:02 am
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.

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

Posted: Fri Mar 19, 2021 10:02 am
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)

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

Posted: Fri Mar 19, 2021 10:08 am
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.

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

Posted: Fri Mar 19, 2021 11:04 am
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 ?

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

Posted: Fri Mar 19, 2021 11:16 am
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.

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

Posted: Thu Sep 22, 2022 4:52 pm
by cjgiron
Hi Admin,

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

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

Posted: Fri Sep 23, 2022 12:45 am
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

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

Posted: Mon Apr 22, 2024 1:03 pm
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?

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

Posted: Mon Apr 22, 2024 11:23 pm
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.

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

Posted: Thu Apr 25, 2024 8:40 am
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.

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

Posted: Thu Apr 25, 2024 9:01 am
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.

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

Posted: Fri Apr 26, 2024 3:52 pm
by likejudo
You need to check with the author of the book.
boyarsky-services.png
boyarsky-services.png (42.54 KiB) Viewed 864 times