The foundational vocabulary for every variable you'll ever declare in Java — get the types, operators, and conversions locked down here.
| Type | Stores | Java keyword | Example |
|---|---|---|---|
| String / text | A sequence of characters | String | "Hello World" |
| Char | A single character | char | 'A' |
| Integer | Whole numbers | int | 42 |
| Floating point / real | Numbers with decimals | double | 3.14 |
| Boolean | True or false only | boolean | true |
Arithmetic operators and how they apply to each numeric type:
| Operator | Meaning | Example (int) | Result |
|---|---|---|---|
| + | Addition | 5 + 2 | 7 |
| - | Subtraction | 5 - 2 | 3 |
| * | Multiplication | 5 * 2 | 10 |
| / | Real division | 5.0 / 2 | 2.5 |
| div (integer division) | Whole number division, discards remainder | 5 / 2 (both ints in Java) | 2 |
| mod | Remainder after division | 5 % 2 | 1 |
Order of precedence follows standard maths rules (brackets first, then *, /, mod/div, then + and -) — use brackets to force a specific order when needed.
Choosing the right type matters: a telephone number or ID number should be stored as a String, not an integer/number type — because you'll never do arithmetic on it, and a leading zero (e.g. '011...') would be silently lost if stored as a number.
Type conversion (casting):
| Conversion | Example | Notes |
|---|---|---|
| String ↔ numeric | Integer.parseInt("5"), String.valueOf(5) | Needed because user input is normally read as a String |
| String ↔ char | "A".charAt(0) | Get a single character from a String |
| char ↔ int | (int) 'A' → 65 | Each char has an underlying numeric (ASCII/Unicode) value |
| real ↔ integer | (int) 3.9 → 3 | Converting a real to an int truncates (cuts off) the decimal part, it does not round |
String operations you must know:
💡 Exam Tip
Java trap: never compare Strings with ==. Two Strings with identical text can be different objects in memory, so == checks object identity, not content. Always use .equals().