A data type is a classification that specifies the kind of value a variable can hold, the operations that can be performed on it, and how its binary representation is stored in memory. Common primitive data types include integers, floating-point numbers, characters, and booleans, while composite types include arrays, strings, and objects. Choosing the correct data type is essential for memory efficiency, performance, and preventing logical errors in programs.
| Data Type | Example Value | Memory Size | Use Case |
|---|---|---|---|
| int (integer) | 42, -7, 0 | 4 bytes (32-bit) | Counting, indexing |
| float | 3.14, -0.5 | 4 bytes | Decimal calculations |
| double | 3.14159265 | 8 bytes | High-precision math |
| char | 'A', 'z' | 1–2 bytes | Single characters |
| boolean | true / false | 1 bit (often 1 byte) | Conditional logic |
| String | "Hello World" | Variable | Text data |
Wikimedia Commons, CC BY-SA
A variable is a named storage location in a program's memory that holds a value which can be read or modified during execution. Variables allow programmers to store, retrieve, and manipulate data dynamically without hardcoding fixed values. They are fundamental to all programming paradigms, enabling algorithms to operate on different inputs and maintain state across instructions.
Encapsulation is the OOP principle of bundling an object's data (attributes) and the methods that operate on that data into a single unit (a class), while restricting direct external access to the internal state. By declaring attributes as private and exposing them only through public getter and setter methods, encapsulation enforces data integrity and hides implementation details. This protects objects from unintended interference and simplifies maintenance since internal changes do not affect external code.
Object-Oriented Programming (OOP) is a programming paradigm that organises software design around data, called objects, rather than functions and logic. Each object encapsulates data (attributes) and behaviour (methods), and objects interact with one another to build complex systems. The four core principles of OOP — encapsulation, inheritance, polymorphism, and abstraction — promote code reusability, modularity, and maintainability.
Combination of "data" (Latin "datum", meaning "given thing") and "type" (Greek "typos", meaning "impression" or "kind"). The concept was formalised in programming language theory during the 1960s, with ALGOL 60 being among the first languages to introduce explicit type declarations.