Operators

Lesson 2 of 20

Variables hold the data; operators put it to work — add, compare, decide. Master the symbols every Java program leans on.

The big picture

Variables + operators = work

A variable is a typed box; an operator is the action performed on what is inside. Together they do all the real work.

Typed boxes

int count, double price, boolean ok, String name — declare the type once and Java enforces it forever.

Arithmetic

+ - * / % compute numbers. Careful: 7 / 2 is 3 when both sides are ints — the fraction is dropped.

Compare and combine

== != < > <= >= produce booleans; && || ! combine or flip them.

Assign shortcuts

= stores a value; +=, -= and ++ update in place: total += 5 is total = total + 5.