What Are Operators in Java?
Operators perform operations on variables and values. For example, adding two numbers, comparing two values, or combining conditions.
Types of Java Operators
1️⃣ Arithmetic Operators (for mathematical operations)
| Operator | Description | Example |
|---|---|---|
| + | Addition | int sum = 5 + 10; |
| - | Subtraction | int diff = 10 - 5; |
| * | Multiplication | int product = 5 * 2; |
| / | Division | int division = 10 / 2; |
| % | Modulus (remainder) | int remainder = 10 % 3; |
| ++ | Increment by 1 | i++; |
| – | Decrement by 1 | i--; |
2️⃣ Relational Operators (compare two values)
| Operator | Description | Example |
|---|---|---|
| == | Equal | if (a == b) { } |
| != | Not equal | if (a != b) { } |
| > | Greater than | if (a > b) { } |
| < | Less than | if (a < b) { } |
| >= | Greater than or equal | if (a >= b) { } |
| <= | Less than or equal | if (a <= b) { } |
3️⃣ Logic Operators (combine two or more conditions)
| Operator | Description | Example |
|---|---|---|
| && | AND (both true) | if (a == 5 && b == 10) { } |
| || | OR (at least 1 true) | if (a == 5 \|\| b == 10) { } |
| ! | NOT (reverse boolean) | if (!isValid) { } |
4️⃣ Assignment Operators (assign or modify values)
| Operator | Description | Example |
|---|---|---|
| = | Assign | int a = 5; |
| += | Add and assign | a += 5; // a = a + 5; |
| -= | Subtract and assign | a -= 5; // a = a - 5; |
| *= | Multiply and assign | a *= 5; // a = a * 5; |
| /= | Divide and assign | a /= 5; // a = a / 5; |
| %= | Modulus and assign | a %= 5; // a = a % 5; |
5️⃣ Bitwise Operators (work at bit level)
| Operator | Description | Example |
|---|---|---|
| & | Bitwise AND | c = a & b; |
| | | Bitwise OR | `c = a |
| ^ | Bitwise XOR | c = a ^ b; |
| ~ | Bitwise NOT | c = ~a; |
| << | Left shift | c = a << 2; |
| >> | Right shift | c = a >> 2; |
Summary
- Arithmetic — Perform mathematical operations
- Relational — Compare two values
- Logic — Combine multiple conditions
- Assignment — Store or modify a variable’s value
- Bitwise — Perform operations at the bit level
0
likes
Your Feedback
Help us improve by sharing your thoughts
Online Learner helps developers master programming, database concepts, interview preparation, and real-world implementation through structured learning paths.
Quick Links
© 2023 - 2026 OnlineLearner.in | All Rights Reserved.
