A data type tells Java what kind of value a variable can hold, how much memory to reserve, and which operations make sense. When you write int age = 25; the word int is the instruction that everything else depends on.
byte smallNumber = 25;
// small box, saves memory
long hugeNumber = 9876543210L;
double price = 1499.99;
boolean isAvailable = true;Java is strongly typed, which means the compiler checks the type of every variable and every expression for you. Store a String in an int and the program never compiles. That strictness sounds annoying for the first few days, then it turns into the thing you rely on most.
Choosing the right type matters for three reasons.
- Memory. An int array of a million numbers uses four million bytes, while a byte array uses one million. In large systems that difference adds up quickly.
- Correctness. The type defines the range of values you can store, so the wrong type can silently overflow.
- Clarity. Reading double temperature tells a colleague that decimals are expected, while reading double value says nothing.