World 3 of 26 · Beginner

➗ Operators & Expressions

14 Java concepts, each explained step by step with real code, a common trap and practice questions.

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