Day-4 Data Types
Source: Dev.to
Data types
Data types are the kinds of information stored in a variable (e.g., numbers, characters, true/false, etc.).
There are two categories of data types:
- Primitive data types
- Non‑primitive data types
Primitive data types
| Type | Size (bytes) | Size (bits) |
|---|---|---|
| Byte | 1 | 8 |
| Short | 2 | 16 |
| Int | 4 | 32 |
| Long | 8 | 64 |
| Float | 2 | 16 |
| Double | 4 | 16 |
| Char | 1 | 8 |
| Boolean | — | 1 (bit) |
Note: Boolean occupies 1 bit (the smallest addressable unit is typically 1 byte).
Non‑primitive data types
String
- String values are enclosed in double quotation marks (
"). - A
Stringcan store any text, including:- Names →
"John" - Sentences →
"I love programming" - Numbers as text →
"12345" - Symbols →
"@#$%" - Addresses →
"New York, USA"
- Names →
Internally, a String stores a sequence of characters.