Lesson 2: Variables, Data Types & Operators
03 Jul 2026 1 min Swarnil Singhai
Java is statically typed — every variable's type is fixed at compile time, which catches whole categories of bugs before code ever ships.
Real-time example
An e-commerce checkout keeps totalPaise as a long, not a double, because floating point rounding on money causes real chargebacks.
long totalPaise = 0L;
totalPaise += 149900; // Rs 1499.00 in paise
double discount = 0.10;
long finalPaise = (long) (totalPaise * (1 - discount));
System.out.println("Final: Rs " + finalPaise / 100.0);
What's happening
Using integer subunits (paise/cents) instead of double avoids the classic 0.1 + 0.2 != 0.3 floating-point trap in financial code.
Pick data types for the domain, not convenience — money, time, and IDs each have a 'correct' primitive.
Advertisement