Start Coding Now

Operators in Java - Arithmetic, Relational & Logical

Master Java operators including arithmetic, assignment, comparison, logical, and ternary operators with examples.

Types of Operators

Java divides operators into several groups:

1. Arithmetic Operators

Used for mathematical operations.
  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • % Modulus (Remainder)
int x = 10, y = 3;
System.out.println(x + y); // 13
System.out.println(x % y); // 1

2. Assignment Operators

Used to assign values.
  • = Assign
  • += Add and assign
  • -= Subtract and assign
int x = 10;
x += 5; // x = x + 5 (15)

3. Comparison Operators

Used to compare two values. Returns boolean.
  • == Equal to
  • != Not equal
  • > Greater than
  • < Less than
int x = 5, y = 3;
System.out.println(x > y); // true

4. Logical Operators

Used to combine conditional statements.
  • && Logical AND
  • || Logical OR
  • ! Logical NOT

Frequently Asked Questions