Operators in Java
Operators in Java are special symbols that perform specific operations on one or more
operands (variables or values) and return a result. They are essential for manipulating data
and performing various calculations and functions within a program.
Operators are fundamental building blocks in Java, allowing for dynamic and complex data
manipulation within programs.
Types of Operators
1. Arithmetic Operators: These operators perform basic mathematical operations. +
(Addition), - (Subtraction), * (Multiplication), / (Division), and % (Modulus - remainder of
division).
2. Relational Operators: These operators compare two values and return a boolean result
(true or false).
== (Equal to)
!= (Not equal to)
> (Greater than)
< (Less than)
>= (Greater than or equal to)
<= (Less than or equal to)
3. Logical Operators: These operators combine multiple boolean expressions.
&& (Logical AND)
|| (Logical OR)
! (Logical NOT)
4. Assignment Operators: These operators assign values to variables.
= (Simple assignment)
+= (Add and assign)
-= (Subtract and assign)
*= (Multiply and assign)
/= (Divide and assign)
%= (Modulus and assign)
1
5. Bitwise Operators: These operators perform operations at the bit level.
& (Bitwise AND)
| (Bitwise OR)
^ (Bitwise XOR)
~ (Bitwise NOT)
<< (Left shift)
>> (Right shift)
>>> (Unsigned right shift)
6. Unary Operators: These operators operate on a single operand. ++ (Increment), --
(Decrement), + (Unary plus), and - (Unary minus).
7. Conditional (Ternary) Operator: This operator is a shorthand for if-else
statements.
condition ? expression1 : expression2
8. Instanceof Operator: This operator checks if an object is an instance of a particular
class. object instanceof ClassName.
9. Type Cast Operator: This operator explicitly converts one data type to another.
(dataType) variable.
2
Increment and Decrement Operators