exam questions

Exam 1z0-819 All Questions

View all questions & answers for the 1z0-819 exam

Exam 1z0-819 topic 1 question 51 discussion

Actual exam question from Oracle's 1z0-819
Question #: 51
Topic #: 1
[All 1z0-819 Questions]

Which code fragment does a service use to load the service provider with a Print interface?

  • A. private java.util.ServiceLoader loader = ServiceLoader.load(Print.class)
  • B. private Print print = new com.service.Provider.PrintImpl();
  • C. private java.util.ServiceLoader loader = new java.util.ServiceLoader<>()
  • D. private Print print = com.service.Provider.getInstance();
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
ASPushkin
9 months, 3 weeks ago
Selected Answer: A
ServiceLoader is like an annotation Bean ans Autowired in the Spring. Kind of a plugin for a searching and loading service provider implementations. public static <S> ServiceLoader<S> load(Class<S> sericeType)
upvoted 1 times
ASPushkin
5 months, 3 weeks ago
SPI is a simplified form of IoC (Inversion of Control). it could be this way : module customer.abs.com{ requires PrintServiceAPI; // this module defines the service interface org.printing.Print uses org.printing.Print; //specifies that this module uses this service //observe that the module with implementation is not required. } package com.abc.customer; public class ServiceLoader { public static void main(String[] args) { final ServiceLoader<Print> services = ServiceLoader.load(Print.class); for (Print service : services) { System.out.println("Name : " + service.name()); } } }
upvoted 1 times
...
...
Stavok
1 year, 6 months ago
Selected Answer: A
ServiceLoader is a class in the java.util package that provides a simple service-provider loading facility. It allows an application to specify one or more service interfaces and to discover and load implementations of those interfaces that are available in the runtime environment. Option A is the correct way to use ServiceLoader to load a service provider with a Print interface. The load method of ServiceLoader takes a Class object representing the service interface and returns a new ServiceLoader instance that can be used to obtain instances of the service.
upvoted 2 times
...
tmuralimanohar
1 year, 7 months ago
Answer: A
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago