- Published on
KembaraXtra-Conputer Science - API Study Guide
I. Core Concept: Application Programming Interface (API)
I. Core Concept: Application Programming Interface (API)
- Definition: A specification that defines how a program interacts with an operating system (OS).
- Purpose: Allows applications to request services from the OS (e.g., creating files, accessing hardware).
- Components:
- Functions: Specific actions an application can request (e.g., open(), CreateFileA(), fopen()).
- Data Structures: Formats for data passed between the application and the OS.
- Implementation: APIs are implemented in software libraries that are included with the OS.
- UI (Shell):
- Interface for users to interact with the OS (e.g., taskbar, Start menu, command line).
- Translates user commands into API calls.
- API:
- Interface for applications to interact with the OS.
- Applications call the API directly, bypassing the UI.
- User Action (via UI): User clicks "New File" in a graphical shell.
- Shell Translation: The UI translates the click into an API call (e.g., a function call to create a file).
- API Call: The API function is invoked (e.g., open() in Unix/Linux, CreateFileA() in Windows).
- OS Action: The OS code (behind the API) executes the request, creating the file.
- Application Action (via API): The application directly invokes open() or CreateFileA() to create a file.
- C:
- Direct access to OS APIs.
- Example (Unix/Linux): open("hello.txt", O_WRONLY|O_CREAT);
- Example (Windows): CreateFileA("hello.txt", GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
- C (Standard Library):
- Provides portable functions that work across different OSes.
- Internally calls the OS-specific API.
- Example: fopen("hello.txt", "w");
- Python:
- Uses a Python interpreter to handle OS-specific API calls.
- The interpreter translates Python code into the correct OS API calls.
- Example: open('hello.txt', 'w')
- POSIX (Portable Operating System Interface):
- Standard for Unix-like systems (Linux, macOS, etc.).
- Defines standards for the OS API, shell behavior, and utilities.
- macOS/iOS:
- Cocoa (macOS): Apple's API for macOS.
- Cocoa Touch (iOS): Apple's API for iOS.
- Android:
- Android Platform APIs: A set of programming interfaces for Android development.
- Windows:
- Win16: Original 16-bit Windows API.
- Win32: 32-bit Windows API.
- Win64: 64-bit Windows API.
- Universal Windows Platform (UWP): Introduced in Windows 10 to provide a consistent API across different Windows devices.
0 Comments