Card 09/ 09
Recap: Operators
Types choose the job, three kinds of comparison, early stopping, grouping and increments, with where each was.
Java's operators come down to the five ideas below, each listed with the card that covers it.
| The idea | Where |
|---|---|
| The operand types choose what a symbol does | Operators and Operand Types: One Symbol, Several Jobs |
= assigns, == asks about identity, equals asks about contents | = vs == vs equals in Java |
&& and || stop early, which is what makes a null guard work | Short-Circuit Evaluation with && and || |
*, / and % bind tighter than + and - | Operator Precedence: Why 5 + 3 * 2 % 4 Is 7 |
i++ produces the old value; ++i produces the new one | i++ vs ++i: Why j Is 5 After int j = i++ |
When an expression surprises you, look at the types and the grouping before you look at the operator. Both of those were decided by the compiler, and neither of them is visible in the line you read.
← → move through sections and cards