Operators in JAVA:
Operators are the symbols used to perform specific operations.
Various operators can be used for different purposes.
The operators are categorized as:
Unary
Arithmetic
Relational
Logical
Ternary
Assignment
Bitwise
Unary Operators
operator Name Description
++ Post increment Increments the value after u
Pre increment Increments the value before
-- Post increment decrements the value after u
Pre increment decrements the value before
~ Bitwise complement Flips bits of the value
! Logical negation Inverts the value of a Boole
Arithmetic Operators
Operator Description
+ Additive operator (also used for string con
- Subtractive operator
* Multiplication operator
/ Division operator
% Modulus operator
Relational operators:
Operator Description
== Equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
!= Not equal to
Logical Operators
Operator Name Description
&& AND The result will be true only if both expres
|| OR The result will be true if any one of the ex
The result will be false if the expression is
! NOT
a
Ternary Operator
The ternary operator is used as a single-line
replacement for if-then-else statements and acts upon
three operands.
Syntax:
<condition> ? <value if condition is true> : < value if condition is
false>
Assignment Operators
Oper
Description
ator
= Assigns the value on the right to the variable on the left
Adds the current value of the variable on the left to the value on
+=
signs the result to the variable on the left
Subtracts the value of the variable on the right from the current v
-=
on left and then assigns the result to the variable on the left
Multiplies the current value of the variable on left to the value on
*=
ssigns the result to the variable on the left
Divides the current value of the variable on left by the value on t
/=
ign the result to the variable on the left
Bitwise Operators:
Bitwise AND (&)
Bitwise OR (|)
Bitwise Exclusive OR (^)
Left shift operator (<<)
Right shift operator (>>)