# Operators

Java operators can be grouped into the following four groups:

• Arithmetic,
• Bitwise,
• Relational,
• Logical.

## Arithmetic Operators

Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra. The following table lists the arithmetic operators:

Java Arithmetic Operators

OperatorResult
-Subtraction (unary minus)
*Multiplication
/Division
%Modulus
++Increment
-=Subtraction assignment
*=Multiplication assignment
/=Division assignment
%=Modulus assignment
--Decrement

The operands of the arithmetic operators must be of a numeric type. You cannot use arithmetic operators on boolean types, but you can use them on char types.

## Java Bitwise Operators

Java bitwise operators can be applied to the integer types: `long, int, short, char, byte`. Bitwise Operators act upon the individual bits of their operands.

Bitwise Operators

OperatorResult
~Bitwise unary NOT
&Bitwise AND
|Bitwise OR
^Bitwise exclusive OR
>>Shift right
>>>Shift right zero fill
<<Shift left
&= Bitwise AND assignment
|=Bitwise OR assignment
^=Bitwise exclusive OR assignment
>>= Shift right assignment
>>>= Shift right zero fill assignment
<<= Shift left assignment

## Relational Operators

The relational operators determine the relationship between two operands. The relational operators are:

Relational Operators

OperatorResult
==Equal to
!=Not equal to
>Greater than
<Less than
>= Greater than or equal to
<= Less than or equal to

## Boolean Logical Operators

The Boolean logical operators operate only on boolean operands.

Boolean Logical Operators

OperatorResult
&Logical AND
|Logical OR
^Logical XOR (exclusive OR)
||Short-circuit OR
&&Short-circuit AND
!Logical unary NOT
&= AND assignment
|=OR assignment
^=XOR assignment
==Equal to
!=Not equal to
? :Ternary if-then-else

## Operators in Java, in Descending Order of Precedence

CategoryOperators
Unary++ -- + - ! ~ (type)
Arithmetic* / % + -
Shift<<>>>>>
Comparison<<= >>= instanceof == !=
Bitwise& ^ |
Short-circuit&& ||
Conditional? :
Assignment= op=