Topic: 1z0-819 topic 1 question 51

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();

Re: 1z0-819 topic 1 question 51

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)

Re: 1z0-819 topic 1 question 51

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.

Re: 1z0-819 topic 1 question 51

Answer: A