Card 09/ 09

RecapDifficulty: Intermediate1 min

Recap: Variables and Types

What a variable holds, what assignment copies, the eight primitives, money and casts, with where each was.

Variables and types come down to the six ideas below, each listed with the card that covers it.

What the topic established, and which card it was on
The ideaWhere
A primitive variable holds the value; a reference variable holds an addressPrimitive and Reference Variables: What a Variable Holds
Assignment copies what the variable holds, which is why two names can reach one listReference Assignment Example: Two Names for One Shopping Basket
Eight primitive types, each with a size and a default for fieldsJava's Eight Primitive Types
Money is never a double; it is pence in a long or a BigDecimalint vs long vs double vs BigDecimal for Money
Widening is automatic, narrowing needs a cast, and the cast is you taking responsibilityStatic Typing: Widening, Narrowing and Casts
Binary fractions cannot hold 0.1 exactly, so decimal sums driftFloating-Point Error: Why 0.1 + 0.2 Is Not 0.3

The declared type is a promise checked before anything runs, and what the variable holds decides what assignment does. Between them, those two facts answer most questions about why a value changed when you did not expect it to.