Operators in Java
Types of Operators in Java with Examples (Complete Guide)
Introduction to Operators in Java
Operators in Java are special symbols used to perform operations on variables and values. In simple terms, they help you work with data easily. Moreover, they play an important role in Java programming.
For example, operators are used in calculations, conditions, and decision-making. Therefore, if you are learning Java, understanding operators in Java will help you write clean and efficient code.
What are Operators in Java?
Operators in Java are used to perform different types of operations such as addition, comparison, and logical evaluation. In other words, they simplify how you handle data and variables in a program.
As a result, programmers can write shorter and more effective code.
Example:
int b = 5;
int sum = a + b;
Types of Operators in Java

Java provides different types of operators that are used for various tasks. Now, let’s understand them one by one.
Arithmetic Operators in Java
First of all, arithmetic operators are used to perform mathematical calculations.
- Addition (+) → a + b
- Subtraction (-) → a – b
- Multiplication (*) → a * b
- Division (/) → a / b
- Modulus (%) → a % b
Example:
System.out.println(a + b);
System.out.println(a % b);
Relational Operators in Java
Next, relational operators are used to compare two values and return true or false.
- Equal to (==)
- Not equal to (!=)
- Greater than (>)
- Less than (<)
- Greater than or equal to (>=)
- Less than or equal to (<=)
Example:
System.out.println(a > b);
Logical Operators in Java
After that, logical operators are used to combine multiple conditions.
- Logical AND (&&)
- Logical OR (||)
- Logical NOT (!)
Example:
System.out.println(age > 18 && age < 30);
Assignment Operators in Java
In addition, assignment operators are used to assign values to variables.
- = → a = 10
- += → a += 5
- -= → a -= 3
- *= → a *= 2
- /= → a /= 2
Example:
a += 5;
Unary Operators in Java
Finally, unary operators work on a single value.
- Positive (+)
- Negative (-)
- Increment (++)
- Decrement (–)
Example:
a++;
Why Operators in Java are Important
Operators are essential in programming. For instance, they help in performing calculations and making decisions.
Furthermore, they are used in loops and conditions. Because of this, learning operators in Java makes your code simple and easy to understand.
Conclusion
In conclusion, operators are a basic but important part of Java programming. By understanding operators in Java, you can write better programs.
Overall, mastering these operators will help you solve problems more efficiently and improve your coding skills.
Frequently Asked Questions
What are operators in Java?
Operators in Java are symbols used to perform operations on variables and values.
How many types of operators are there in Java?
There are five main types: arithmetic, relational, logical, assignment, and unary operators.
What is an arithmetic operator in Java?
Arithmetic operators are used for calculations like addition, subtraction, multiplication, and division.
What are relational operators in Java?
They are used to compare values and return true or false.
What is the use of logical operators in Java?
Logical operators combine conditions and return a boolean result.
What is the difference between == and = in Java?
The = operator assigns a value, while == compares two values.
What is a unary operator in Java?
A unary operator works on a single value, such as increment or decrement.

