1Z0-830 practice question 1 of 25
A consumer needs to access a service provided by another module. Which of the following statements is TRUE?
Full set: 116 questionsThis question is flawed, but option B is the most plausible intended answer. For a consumer to use a service, the module that defines the service interface must make that interface accessible. It does this by using the exports directive for the package containing the interface. The provider module then uses provides...with and the consumer module uses uses.
Option B incorrectly states the keyword is opens (which is for deep reflection) instead of exports. However, the other options are conceptually incorrect about the service locator pattern, whereas B correctly identifies the need for the service's module to explicitly expose the interface.
A. Access is not automatic. The consumer module must explicitly declare its intent to use the service with the uses directive in its module-info.java.
C. The service locator pattern is designed to prevent this. Bypassing the provider mechanism via reflection violates the encapsulation and decoupling principles of the module system.
D. Consumers interact with the service through its public interface, not the concrete implementation. The ServiceLoader API provides instances of the implementation, cast to the interface type.
1. Oracle Corporation. (2023). Java® SE 21 & JDK 21: ServiceLoader Class Documentation. Java Platform, Standard Edition 21 API Specification. Retrieved from https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/ServiceLoader.html. (The class documentation describes the roles of service, provider, and consumer.)
2. Oracle Corporation. (2023). The Java™ Tutorials: The Module System. Services with the Module System. Retrieved from https://docs.oracle.com/javase/tutorial/modules/services.html. (This tutorial shows the module defining the service interface must export its package.)
Keep practicing
Take the free 1Z0-830 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other 1Z0-830 practice questions
- Question 2Which of the following statements is TRUE about modules in Java SE 21?
- Question 3What interface does a class need to implement to be eligible for serialization?
- Question 4What is the primary benefit of encapsulation in Java?
- Question 5A Path object represents which of the following?
- Question 6Which of the following statements about overloaded methods with varargs is TRUE?
- Question 7Which of the following statements is TRUE about static initializers in Java?
