➗ Operators & Expressions
14 Java concepts, each explained step by step with real code, a common trap and practice questions.
- Arithmetic operators+ - * / % on numbers.
- Integer division & remainderint / int truncates toward zero; % keeps the sign of the dividend.
- Division by zeroInteger /0 throws ArithmeticException; floating /0 gives Infinity or NaN.
- Increment & decrementPrefix ++x vs postfix x++ and the classic x = x++ trap.
- Assignment & compound assignment+=, -=, … include an implicit cast (byte b += 1 compiles).
- Relational & equality operators<, >, <=, >=, ==, != and comparing references vs values.
- Logical operators & short-circuit&& and || skip the right side; & and | always evaluate both.
- Bitwise operators&, |, ^, ~ on integer bits and common bit masks.
- Shift operators<<, >> (sign-extending) and >>> (zero-fill).
- Ternary operatorcondition ? a : b and its type rules.
- Precedence & associativityWhich operator binds first and left-to-right evaluation of operands.
- String concatenation+ with a String converts operands; "1" + 2 + 3 vs 1 + 2 + "3".
- Floating-point precision0.1 + 0.2 != 0.3, NaN != NaN, why money needs BigDecimal.
- The Math classMath.max/min/abs/pow/sqrt/round/floor/ceil and Math.floorMod.