01 Variables, Operators, Expressions, Input and Output
January 3, 2024 · 3 min read
Syntax Basics #
Variables #
- In Java, outputting a variable without assigning it a value causes an error.
- Built-in data types
| Type | Bytes | Example | Additional notes |
|---|---|---|---|
| byte | 1 | 123 | |
| short | 2 | 12345 | $2^{16}=65536$ |
| int | 4 | 123456789 | $2^{32}=2147483648≈2.1*10^9$ |
| long | 8 | 1234567891011L | $2^{64}≈10^{18}$ |
| float | 4 | 1.2F | About 6 or 7 significant decimal digits; subsequent digits are imprecise approximations. To explicitly denote a float, append f or F. |
| double | 8 | 1.2, 1.2D | About 15 or 16 significant decimal digits; subsequent digits are imprecise approximations. To explicitly denote a double, append d or D. |
| boolean | 1 | true, false | |
| char | 2 | ‘A’ | ASCII code correspondences: a-97 A-65 0-48 |