Clean • Professional
In Java, operators are special symbols used to perform operations on variables and values.
They form the backbone of any Java program, enabling calculations, decisions, and logical flows.
An operator is a symbol that tells the compiler to perform specific mathematical, logical, or relational operations on operands (values or variables).
Example:
int a = 10, b = 5;
int sum = a + b; // '+' is an arithmetic operator
Here,
a and b are operands+ is the operatorsum is the resultJava provides several categories of operators:

| Category | Description | Examples |
|---|---|---|
| Arithmetic Operators | Perform mathematical calculations | +, -, *, /, % |
| Relational Operators | Compare two values | ==, !=, >, <, >=, <= |
| Logical Operators | Combine multiple conditions | &&, ` |
| Bitwise Operators | Operate on bits | &, ` |
| Assignment Operators | Assign values to variables | =, +=, -=, *=, /=, %= |
| Unary Operators | Work with a single operand | ++, --, +, -, !, ~ |
| Ternary Operator | Conditional short form of if-else | ? : |
| instanceof Operator | Tests whether an object is of a specific type | obj instanceof ClassName |
Used for basic mathematical operations.
| Operator | Description | Example | Output |
|---|---|---|---|
+ | Addition | 10 + 5 | 15 |
- | Subtraction | 10 - 5 | 5 |
* | Multiplication | 10 * 5 | 50 |
/ | Division | 10 / 3 | 3 |
% | Modulus (Remainder) | 10 % 3 | 1 |
Example:
int a = 10, b = 3;
System.out.println(a + b);
System.out.println(a / b);
System.out.println(a % b);
Used to assign values to variables.
They can also perform an operation while assigning.
| Operator | Example | Equivalent To |
|---|---|---|
= | a = 5; | — |
+= | a += 5; | a = a + 5; |
-= | a -= 5; | a = a - 5; |
*= | a *= 5; | a = a * 5; |
/= | a /= 5; | a = a / 5; |
%= | a %= 5; | a = a % 5; |
Used with a single operand to perform increment, decrement, or negation.
| Operator | Description | Example | Output |
|---|---|---|---|
+ | Unary plus (no change) | +a | a |
- | Unary minus (negates value) | -a | negative of a |
++ | Increment | a++ or ++a | increases by 1 |
-- | Decrement | a-- or --a | decreases by 1 |
! | Logical NOT | !true | false |
~ | Bitwise Complement | ~5 | -6 |
Example:
int a = 5;
System.out.println(++a); // 6
System.out.println(a--); // 6, then a = 5
System.out.println(-a); // -5
Used to compare two values, returning a boolean result (true or false).
| Operator | Description | Example | Result |
|---|---|---|---|
== | Equal to | 5 == 5 | true |
!= | Not equal to | 5 != 3 | true |
> | Greater than | 5 > 3 | true |
< | Less than | 5 < 3 | false |
>= | Greater than or equal | 5 >= 5 | true |
<= | Less than or equal | 5 <= 4 | false |
Used to combine multiple boolean expressions.
| Operator | Description | Example | Result |
|---|---|---|---|
&& | Logical AND | (a > 5 && b < 10) | true if both true |
| ` | ` | Logical OR | |
! | Logical NOT | !(a > 5) | reverses result |
Example:
int a = 10, b = 20;
System.out.println(a > 5 && b > 15); // true
System.out.println(a < 5 || b > 15); // true
System.out.println(!(a == b)); // true
Work at bit level (0s and 1s).
Used for low-level programming, encryption, and optimization.
| Operator | Description | Example | Result |
|---|---|---|---|
& | AND | 5 & 3 | 1 |
| ` | ` | OR | `5 |
^ | XOR | 5 ^ 3 | 6 |
~ | Complement | ~5 | -6 |
<< | Left Shift | 5 << 1 | 10 |
>> | Right Shift | 5 >> 1 | 2 |
>>> | Unsigned Right Shift | -5 >>> 1 | large positive value |
Example:
int a = 5, b = 3;
System.out.println(a & b); // 1
System.out.println(a | b); // 7
System.out.println(a ^ b); // 6
System.out.println(a << 1); // 10
System.out.println(a >> 1); // 2
A short form of if-else.
Syntax:
variable = (condition) ? value_if_true : value_if_false;
Example:
int age = 20;
String result = (age >= 18) ? "Eligible" : "Not Eligible";
System.out.println(result);
Checks whether an object belongs to a particular class or subclass.
String name = "Java";
boolean check = name instanceof String;
System.out.println(check); // true
Determines the order in which operators are executed in complex expressions.
| Precedence | Operator | Description |
|---|---|---|
| Highest | (), [], . | Parentheses, array access |
++, --, !, ~ | Unary | |
*, /, % | Multiplicative | |
+, - | Additive | |
<<, >>, >>> | Shift | |
<, >, <=, >=, instanceof | Relational | |
==, != | Equality | |
&, ^, ` | ` | |
&&, ` | ||
?: | Ternary | |
| Lowest | =, +=, -= etc. | Assignment |
Example:
int result = 10 + 5 * 2; // result = 20, not 30
public class JavaOperators {
public static void main(String[] args) {
int a = 10, b = 5;
System.out.println("Arithmetic: " + (a + b));
System.out.println("Relational: " + (a > b));
System.out.println("Logical: " + (a > 0 && b > 0));
System.out.println("Bitwise AND: " + (a & b));
System.out.println("Ternary: " + ((a > b) ? "A is greater" : "B is greater"));
}
}
Output:
Arithmetic: 15
Relational: true
Logical: true
Bitwise AND: 0
Ternary: A is greater