Application Programming Interface (API): Definition, Types, and Examples in Java
📘 Application Programming Interface (API)
An Application Programming Interface (API) is a collection of interfaces, implementation classes, and helper classes that enables communication between two different applications.
APIs act as a bridge that allows one software application to interact with another without knowing its internal implementation.
An API is generally provided in the form of a JAR (Java Archive) file.
Most APIs are developed and maintained by software vendors to allow developers to use their services or features.
🔍 Example of API
✅ JDBC (Java Database Connectivity)
- JDBC is a standard Java API
- Used to connect Java applications with a database server
- Allows execution of SQL queries from Java programs
🧩 Categories of API
APIs can be classified into three main categories based on how interfaces and implementations are packaged.
🔹 Category 1 API
Interface, implementation classes, and helper classes are present in a single JAR file
Easy to use and deploy
📌 Example: Core Java APIs like java.lang, java.util
🔹 Category 2 API
Consists of two JAR files
First JAR:
Interfaces
- Partial implementation
- Helper classes
Second JAR:
- Remaining partial implementation of interfaces
📌 Used when implementation is split or extended separately
🔹 Category 3 API
Consists of two JAR files
First JAR:
- Interfaces
- Helper classes
Second JAR:
- Complete implementation of the interfaces
📌 Example:
JDBC API
- java.sql (interfaces)
- Database vendor JAR (implementation like MySQL, Oracle)
⭐ Key Advantages of API
- Enables inter-application communication
- Promotes code reusability
- Hides internal implementation
- Supports loose coupling
Comments
Post a Comment