Java operators are special symbols that are used to perform operations on variables and values in a Java program. They help you calculate results, compare data, apply conditions, and control how your program executes. In simple terms, operators tell Java what action to perform.
Operators in Java are extremely important because every program depends on them. Operators are involved in many things like in adding numbers, checking if a condition is true, updating a variable inside a loop, making decisions using if statements, etc. You cannot perform arithmetic calculations, evaluate logical expressions, or control program flow without the use of operators. They are like the foundation of expressions, conditions, and decision-making in Java programming.
Understanding the types of operators in Java with examples is one of the first major steps for beginners and students. So, let’s begin by understanding what are operators in Java and types of operators in Java.
Also Read: Java Tutorial for Beginners
In Java programming, operators are special symbols that perform operations on variables and values (called as operands). They are used to create expressions that calculate results, compare data, assign values, and control decision-making in a program.
Whenever you write an expression in Java, you are using one or more operators. Operators make all the logic possible, from adding numbers, checking conditions to updating a variable inside a loop.
|
An expression in Java is a combination of variables, values, and operators that produces a result. For instance, you can see the expression given below:
|
This expression shows how operators follow specific execution rules such as precedence and associativity. Let’s understand its step-by-step execution:
| Precedence Level | Operators | Description | Associativity |
|---|---|---|---|
| 1 (Highest) | ++ -- + - ! ~ | Unary operators | Right to Left |
| 2 | * / % | Multiplication, Division, Modulus | Left to Right |
| 3 | + - | Addition, Subtraction | Left to Right |
| 4 | << >> >>> | Shift operators | Left to Right |
| 5 | < <= > >= | Relational operators | Left to Right |
| 6 | == != | Equality operators | Left to Right |
| 7 | & | Bitwise AND | Left to Right |
| 8 | ^ | Bitwise XOR | Left to Right |
| 9 | | | Bitwise OR | Left to Right |
| 10 | && | Logical AND | Left to Right |
| 11 | || | Logical OR | Left to Right |
| 12 | ? : | Ternary operator | Right to Left |
| 13 (Lowest) | = += -= *= /= %= | Assignment operators | Right to Left |
Also Explore: How to Install Java for Installation
In Java programming, operators are divided into different categories based on the type of operation they perform. Understanding the types of operators in Java helps beginners write clearer code and choose the correct operator for a specific task.
Java provides the following main types of operators:
Arithmetic operators in Java are symbols used to perform mathematical calculations on numeric values such as integers and decimal numbers. They help a program to add, subtract, multiply, divide or calculate the remainder between two numbers. These operators work on numeric data types like int, double, float, long and short. Then, they return a computed result based on the operation performed.
In simple terms, arithmetic operators are what make calculations possible in a Java program. The Arithmetic Operators are as follows:
| 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 |
|
|

Relational operators in Java are used to compare two values, variables, or expressions. Their main purpose is to determine the relationship between two operands, such as whether they are equal, different, greater than, or less than each other. Unlike arithmetic operators, relational operators do not perform calculations. Instead, they evaluate a condition and always return a Boolean result. This means the outcome will either be true or false.
For instance, if you compare two numbers and the condition is satisfied. Then, the result will be true; otherwise, it will be false. This Boolean result helps Java programs to make decisions. The relational operators are as follows:
| Operator | Description | Example | Output |
|---|---|---|---|
| == | 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 to | 5 >= 5 | true |
| <= | Less than or equal to | 3 <= 5 | true |
|
|

Read Also: Final Keyword in Java
The instanceof operator in Java is used to check whether an object belongs to a specific class, subclass, or interface. It helps determine the type of an object at runtime. This operator returns a Boolean value, which means the result will either be true or false.
The instanceof operator is especially useful in object-oriented programming when working with inheritance, polymorphism, or when handling objects of different types. It ensures type safety before performing type casting and helps prevent ClassCastException errors.
| Operator | Description | Example | Output |
|---|---|---|---|
| instanceof | Checks whether an object belongs to a specific class or interface | "Java" instanceof String | true |
|
|
Modern Update (Java 16 and Later): Starting from Java 16, pattern matching was introduced with instanceof. This allows type casting directly inside the condition, making the code cleaner and more readable.
|
This modern feature improves readability and reduces unnecessary type casting in Java programs.
Read Also: Java 21 Features
Java logical operators are used to modify or combine Boolean expressions. They are mainly used when a program needs to evaluate more than one condition at the same time. It is not like arithmetic operators that work with numbers. Logical operators work with boolean values. This means they deal only with true or false.
In simple terms, logical operators help a Java program make smarter decisions by checking multiple conditions together. The Logical Operators are as follows:
| Operator | Description | Rule |
|---|---|---|
| && | Logical AND | True if both conditions are true |
| ! | Logical NOT | Reverses the boolean value |
| || | Logical OR | True if at least one condition is true |
|
Output:
|

Assignment operators in Java are used to assign values to variables and in updating their existing values. They play a fundamental role in programming because they help data to be stored, modified, and reused throughout a program. Variables would not be able to hold or change values, and meaningful computation would not be possible without assignment operators
The most basic assignment operator is the equals sign (=). It assigns the value on the right-hand side to the variable on the left-hand side. The assignment operators are as follows:
| Operator | Description | Equivalent To |
|---|---|---|
| = | Assign value | a = 5 |
| += | Add and assign | a = a + 5 |
| -= | Subtract and assign | a = a - 5 |
| *= | Multiply and assign | a = a * 5 |
| /= | Divide and assign | a = a / 5 |
| %= | Modulus and assign | a = a % 5 |
|
|

Unary operators in Java are operators that work on only one operand. This is not like arithmetic or relational operators that require two values to perform an operation. Unary operators act on a single variable or value and modify or evaluate it directly.
The word “unary” means “one”. It clearly explains their behavior. These operators are commonly used to increment a value, decrement a value, change the sign of a number or reverse a boolean condition. Even though they operate on just one operand, they play a very important role in controlling how values change during program execution. The Unary Operators are as follows:
| Operator | Description | Example |
|---|---|---|
| ++ | Increment by 1 | a++ |
| -- | Decrement by 1 | a-- |
| + | Unary plus | +a |
| - | Unary minus | -a |
| ! | Logical NOT | !true |
|
|

Bitwise operators in Java perform operations directly on the binary representation of numbers. They do not work with decimal values like arithmetic operators. Bitwise operators manipulate individual bits like 0s and 1s inside an integer. Since every number in a computer is stored in binary form, bitwise operators allow programmers to work at a lower level of data processing.
In Java, bitwise operators are mainly used with integer data types such as int, long, short, and byte. When a bitwise operation is performed, Java converts the numbers into binary form, applies the operation bit by bit and then converts the result back into a decimal number. The Bitwise operators are follows:
| Operator | Description | Example | Output |
|---|---|---|---|
| & | Bitwise AND | 5 & 3 | 1 |
| ` | ` | Bitwise OR | `5 |
| ^ | XOR | 5 ^ 3 | 6 |
| ~ | Complement | ~5 | -6 |
| << | Left Shift | 5 << 1 | 10 |
| >> | Right Shift | 5 >> 1 | 2 |
|
|

Java ternary operator is a conditional operator. It is used to evaluate a condition and return one of two values based on whether that condition is true or false. It is called ternary because it works with three parts: a condition, a value returned if the condition is true, and a value returned if the condition is false. It is written using the symbols : and ?. It is considered a shorter and a more compact version of a simple if-else statement.
|
|

Related Article: Keywords in Java
Operators in Java look simple but sometimes beginners make mistakes that lead to wrong output or logical errors. Understanding these common issues will help you avoid bugs and write better programs.
Also Explore: Classes and Objects in Java
If you want to master operators in Java, you should focus not only on syntax but also on writing clean, logical, and efficient code.
Java operators are the foundation of every Java program. They allow you to perform calculations, compare values, apply logical conditions, and control how your code runs. Operators are used in almost every line of real-world Java applications from simple arithmetic operations to complex decision-making.
Understanding operators in Java will help you in building strong programming fundamentals. Once you master arithmetic, relational, logical, assignment, unary, bitwise, and ternary operators, then writing expressions and conditions will become much easier for you.
For that you need to practice regularly, test your output and focus on clarity. A strong understanding of Java operators will make advanced topics like loops, arrays, and object-oriented programming much easier to learn for you.
Explore Our Trending Articles-
There are seven main types of operators in Java: arithmetic, relational, logical, assignment, unary, bitwise, and ternary operators. Each type is used for a specific purpose in expressions and decision-making.
Java operators are important because they form the foundation of programming logic. Java operators are used in every calculation, comparison, and condition. Understanding them early helps beginners in writing correct code and in avoiding common mistakes.
The = operator is used to assign a value to a variable, while == is used to compare two values. The assignment operator stores data and equality checks whether two values are the same.
Operator precedence in Java determines the order in which operators are evaluated in an expression. Operators with higher precedence are executed first, unless parentheses are used to change the order.