Variables are reserved memory locations to store values. Java is a statically-typed language, meaning every variable must be declared with a data type.
Used for storing whole numbers without decimals.
Used for numbers with fractional parts (decimals).
float f1 = 234.5f;
double d1 = 123.4;
Represents one bit of information (True/False). Used for flags and conditional logic.
boolean isActive = true;
16-bit Unicode character. Stores a single character.
char letter = 'A';
Reference variables are created using class constructors. They store the address of the object, not the value itself.
String s = "Hello";Comparing Size, Range, and Default Values
| Type | Size (Bits) | Default Value | Range / Description |
|---|---|---|---|
| byte | 8 | 0 | -128 to 127 |
| short | 16 | 0 | -32,768 to 32,767 |
| int | 32 | 0 | -231 to 231-1 |
| long | 64 | 0L | -263 to 263-1 |
| float | 32 | 0.0f | 7 decimal digits of precision |
| double | 64 | 0.0d | 15 decimal digits of precision |
| char | 16 | '\u0000' | 0 to 65,535 (Unicode) |
| boolean | 1* | false | true / false |
| String | N/A | null | Sequence of characters |