• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

Programs need to perform operations on data — arithmetic calculations, comparisons, logical decisions, and value assignments. Without a well-defined operator system, every operation would require verbose method calls, making code harder to read, write, and maintain.

Core Idea

Java provides a rich set of operators that perform specific operations on one, two, or three operands. These include arithmetic (+, -, *, /, %), relational (<, >, ==, !=), logical (&&, ||, !), bitwise (&, |, ^, ~, <<, >>), assignment (=, +=, -=), and ternary (?:). Each operator has a fixed precedence and associativity.

How It Works

The compiler parses expressions according to operator precedence and associativity rules. Operators are syntactic sugar — the compiler translates a + b into the appropriate bytecode instructions (like iadd for int addition). Short-circuit operators (&&, ||) evaluate the right operand only when needed.

Visual Explanation

java_operators Ops Java Operators Arithmetic Arithmetic + - * / % Ops->Arithmetic Relational Relational < > <= >= == != Ops->Relational Logical Logical && || ! Ops->Logical Assignment Assignment = += -= *= /= Ops->Assignment Bitwise Bitwise & | ^ ~ << >> Ops->Bitwise Ternary Ternary ? : Ops->Ternary Instance Type Check instanceof Ops->Instance

Semantic Network

semantic_operators THIS Operators DT Data Types THIS--DT built from VAR Variables THIS--VAR builds into CTRL Control Flow THIS--CTRL builds into STR String Concatenation THIS--STR related

Key Properties

  • Operator precedence: * and / before + and - (standard math precedence)
  • Short-circuit evaluation: && stops if left is false; || stops if left is true
  • Type promotion: int + double promotes to double automatically
  • String concatenation: + is overloaded for string concatenation

Connections

  • Built from: Java Data Types — operators behave differently on different types
  • Builds into: Java Control Flow — relational and logical operators drive conditionals
  • Builds into: Java Loops — comparison operators control loop termination
  • Related: Java Variables — assignment operators modify variable values

Edge Cases & Gotchas

  • Integer division truncates: 5 / 2 = 2 (not 2.5); use 5 / 2.0 for floating-point
  • String + int concatenates: "Result: " + 42 = “Result: 42” (not “Result: 0”)
  • == compares references for objects: Use .equals() for value comparison
  • Bitwise vs logical: & and | do not short-circuit; && and || do