Mastering data conversion, navigating the limits of memory, and writing efficient shortcuts.
When a big drink meets a small cup, something has to be left behind.
Why can't we just assign a double to an int?
double holds more information than an int. Java refuses to silently lose that data. Changing types: Narrowing vs. Widening
double → intint → double(int) someDouble — converts a double to int(double) someInt — converts an int to doubleCasting cuts the decimal — it never rounds
Truncation & widening
How to achieve (nearest int) instead of just truncation
0.5 before casting. (int)(x + 0.5)0.5 before casting. (int)(x - 0.5)What happens when you exceed the limit?
-2,147,483,6482,147,483,647What happens when numbers exceed their limits?
Why doubles are sometimes 'approximate'
Some decimal values cannot be stored exactly as doubles. Java keeps a very close approximation instead.
This leads to tiny precision errors during calculation — doubles are not always exact.
Write less, mean the same — each line starts from xp = 10
x op= y is always equivalent to x = x op y. Decode the shortcut operators
The ultimate one-step shortcut
x = x + 1.x = x - 1.++ and -- in action
This pattern is useful to recognize, but it is not part of the AP CSA exam focus.
Try tracing this one step by step before you trust your intuition.
This looks reasonable at first glance. What value disappears?
a = b, what is the value of a? When the next line runs, does the original 7 still exist anywhere? Before we write the fix, look at where each value moves.

A temporary variable keeps one value safe while the other moves.
The four things you must remember
(int) 3.9 → 3 (truncation, not rounding)
Integer.MAX_VALUE + 1 wraps to MIN_VALUE (Overflow)
0.1 + 0.2 can equal 0.30000000000000004 (Round-off Error)
x += 5 (compound) and x++ (increment) save time