1. Definition of Interface in Java
The term "interface" in Java encompasses various meanings, contingent upon the context and application. Broadly speaking, an interface can be perceived as a Service Requirement Specification (SRS).
1.1 Case 1: Java Servlet Implementation
Consider Tommy, who aims to develop an online calculator web service using a Java-based language. To enable his app to run in a web server environment, he must implement Java Servlet. Various implementors like Apache Tomcat, OHS, Resin, and WebLogic follow the Servlet API provided by SUN, a set of guidelines dictating the methods and classes they should implement. The Servlet API serves as an interface, representing the service requirements for Java servlet implementation.
1.2 Case 2: JDBC API for Database Communication
In another scenario, imagine a Java application needing to communicate with databases like Oracle and MySQL. To facilitate this communication, a driver acts as a translator. For each database, a specific driver with JDBC API implementation is necessary. If a new database, such as PostgreSQL, emerges, a corresponding driver with JDBC API is required for seamless integration. Creating a custom driver for a proprietary database involves referencing the JDBC API provided by SUN, making JDBC API an interface defining the service requirements for database communication.
Understanding the concept of interface in Java involves recognizing it as a set of specifications and guidelines, crucial for seamless integration and communication within various contexts.