Typed variable
Variable with a specified type.
Syntax
type name = value;
Description
Java is statically typed: the type of every variable is written. int, double, boolean, String are the most common.
Example
Loading editor…
Expected output
Alex 36
When to use?
Storing all kinds of data.
Common mistakes
- ⚠️ Assigning the wrong type causes a compilation error: int x = "5"; → ERROR.