![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we create a Service Provider interface in Java 9?
A module that provides the implementation for the Service interface contains a "provides" statement in the module descriptor file. If the module doesn’t have the "provides" statement in the module descriptor file, the service loader can't load that module.
We can create the Service Provider Interface by using below steps:
- We create a new Module com.tutorialspoint.serviceproviderinterface.
- In the src/main/java directory, we create "module-info.java" file.
- Inside our source directory, we create the package com.tutorialspoint.serviceproviderinterface.spi.
- Finally, we create the interface ServiceProviderInterface that contains a method: printServiceName() to be implemented.
In the below, we can define Service Provider Interface.
package com.tutorialspoint.serviceproviderinterface.spi; public interface ServiceProviderInterface { void printServiceName(); }
Advertisements