1.2

Variables and Data Types

Java variables store values using primitive types (int, double, boolean) or reference types, each with specific operations.

1525% of exam
Understand It
Ace It
Context

What this topic is and why it exists

Imagine you're moving into a new apartment and you need boxes.
You wouldn't stuff a winter coat into a tiny shoebox, and you wouldn't waste a massive wardrobe box on a pair of sunglasses.
Choosing the right container matters — and that's exactly what picking a data type in Java is all about.
Every piece of information your program works with needs a home, and that home is called a variable — a labeled container that holds a value which can change as your program runs.
But before you store anything, you have to tell Java what *kind* of thing goes inside.
For this course, you need three essential types.
Use `int` when you're dealing with whole numbers — scores, counts, ages.
Use `double` when you need decimal precision — temperatures, averages, distances.
And use `boolean` when the answer is simply true or false — is the user logged in?
Did the student pass?
These three are called *primitive* types because they hold raw, simple values directly.
Everything else — strings, lists, objects you build yourself — falls under reference types, which point to more complex structures.
For now, mastering the choice between `int`, `double`, and `boolean` is your foundation.
Get this right, and every program you write starts on solid ground.
1 / 9