Operators in Java:
Java provides many types of operators. They are classified into several types they are:
- Arithmetic Operators
- Assignment Operators
- Relational Operators
- Logical Operators
- Ternary Operators
- Bitwise Operators
- Shift Operators
Arithmetic Operators:
They are used to perform simple arithmetic operations on primitive data types.
+ - Addition
– - Subtraction
• - Multiplication
/ - Division
% - Modulus
+ - Addition
– - Subtraction
• - Multiplication
/ - Division
% - Modulus
Assignment Operators:
Assignment operator '=' is used to assigning a value to any variable. It has a right to left associativity.
The general format of the assignment operations:
+=, adding left operand
-=, subtracting right operand
*=, multiplying left operand
/=, dividing left operand
%=,assigning modulus left operand
-=, subtracting right operand
*=, multiplying left operand
/=, dividing left operand
%=,assigning modulus left operand
Relational Operators:
These operators are used to check for relations like equality, greater than, and less than.
Some of the relational operators are:
==, Equal to
!=, Not Equal to
<, less than
<=, less than or equal to
>, Greater than
>=, Greater than or equal to
!=, Not Equal to
<, less than
<=, less than or equal to
>, Greater than
>=, Greater than or equal to
Logical Operators:
These operators are used to perform “logical AND” and “logical OR” operations. Used extensively to test for several conditions for making a decision. Java also has “Logical NOT”, which returns true when the condition is false and vice-versa.
Ternary operators:
Ternary operator is a shorthand version of the if-else statement. It has three operands and hence the name ternary.
Bitwise Operators:
These operators are used to perform the manipulation of individual bits of a number.
&, Bitwise AND operator.
|, Bitwise OR operator.
^, Bitwise XOR operator.
~, Bitwise Complement Operator: This is a unary operator
Shift Operators:
These operators are used to shift the bits of a number left or right, thereby multiplying or dividing the number by two, respectively. They can be used when we have to multiply or divide a numbers.
<<, Left shift operator
>>, Signed Right shift operator
>>>, Unsigned Right shift operator.