Notes / Java / Operators

Operators in Java — Revision Notes

A quick-reference cheat sheet: definition, syntax, example, common mistakes and an interview tip.

beginner 📖 2 min revision

Definition

📌 Operators Java's operators closely mirror C and C++: arithmetic (+ - * / %), relational (== != > <), and logical (&& || !) — but comparisons always produce a real boolean, never an int..

Syntax

syntax
a + b   a - b   a * b   a / b   a % b
a == b  a != b  a > b   a < b
a && b  a || b  !a

Example

java
public class Main {
    public static void main(String[] args) {
        int a = 10, b = 3;
        System.out.println("Sum: " + (a + b));
        System.out.println("Remainder: " + (a % b));
        System.out.println("Greater: " + (a > b));
    }
}

Output

outputSum: 13 Remainder: 1 Greater: true

Important Points

Common Mistakes

Interview Tip

🎯 Before your interview Know that Java's strict boolean typing prevents a whole class of C-style bugs where an accidental assignment (=) inside an if silently "works".
Back to notes Read full lesson →