Operators in Java
Hey there! In this guide, we'll explore operators in Java. Operators are symbols that instruct the compiler to perform specific operations on variables or values. Java supports a variety of operators, including arithmetic, relational, logical, bitwise, and more. Let's dive in!
- Operators are symbols that instruct the compiler to perform specific operations on variables or values.
- Java supports a variety of operators, including arithmetic, relational, logical, bitwise, and more.
Video Explanation

1. Arithmetic Operators
Arithmetic operators perform mathematical operations such as addition, subtraction, multiplication, and division.
| Operator | Description | Example |
|---|---|---|
| + | Addition | x + y |
| - | Subtraction | x - y |
| * | Multiplication | x * y |
| / | Division | x / y |
| % | Modulus (remainder) | x % y |
Example:
int x = 10, y = 5;
System.out.println(x + y); // Output: 15
System.out.println(x - y); // Output: 5
System.out.println(x * y); // Output: 50
System.out.println(x / y); // Output: 2
System.out.println(x % y); // Output: 0
2. Relational Operators
Relational operators compare two values and return a boolean result (true or false).
| Operator | Description | Example |
|---|---|---|
| == | Equal to | x == y |
| != | Not equal to | x != y |
| > | Greater than | x > y |
| < | Less than | x < y |
| >= | Greater than or equal to | x >= y |
| <= | Less than or equal to | x <= y |
Example:
int x = 10, y = 5; System.out.println(x == y); // Output: false
System.out.println(x != y); // Output: true
System.out.println(x > y); // Output: true
System.out.println(x < y); // Output: false
System.out.println(x >= y); // Output: true
System.out.println(x <= y); // Output: false
3. Logical Operators
Logical operators are used to perform logical operations and combine multiple conditions.
| Operator | Description | Example |
|---|---|---|
| && | Logical AND | (x > 5 && y < 10) |
| || | Logical OR | (x > 5 || y < 10) |
| ! | Logical NOT | !(x > 5) |