Posted on

Java Operators

Operators are symbol which tells the compiler to perform logical and mathematical operations.

Java supports the following operators:

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Logical operators
  • Bitwise operators

Arithmetic Operators

Arithmetic Operators are used to perform common mathematical operations such as addition, subtraction, multiplication, and division.

OperatorDescription
++ operator is used to add two values.
– operator is used to subtract two values.
** operator is used to multiply two values.
// operator returns quotient after dividing 1st operand
by 2nd operand.
%% operator returns remainder after dividing 1st operand
by 2nd operand.
++Increase the value by 1.
Decreases the value by 1.

Assignment operators

Assignment operators is used to assign a value to any variable on its right hand side of operator to left.

OperatorDescription
=This operator assign the value from the right to left.
+=This operand adds the right operand to the left and
assign the value to left operand.
-=This operand subtract the right operand to the left and
assign the value to left operand.
*=This operand multiply the right operand to the left and
assign the value to left operand.
/=This operand divide the right operand to the left and
assign the value to left operand.
%=This operand takes the modulus from both the operand
and assign values to left operand.
<<=This is left shift and assignment operator.
>>=This is right shift and assignment operator.
|=This is bitwise inclusive OR operator.
^=This is bitwise exclusive OR operator.

Comparison operators

Comparison operators is also known as relational operator. This operator is used to compare two values.

OperatorDescription
==If both the condition are true then the condition
will become true.
<This operator will check whether the left operand
is less than the right operand.
>This operator will check whether the right operand
is greater than the left operand.
<=This operand will check whether the left operand
is less than or equal to the right operand.
>=This operand will check whether the right operand
is greater than or equal to the left operand.
!=If both the operand are not equal then the condition
will become true.

Logical operators

Logical operators is used to perform logical operations such as logical AND, logical OR, and Logical not.

OperatorDescription
ANDIf both the expression are true then the condition
will become rue.
ORIf any one of the expression is true then the condition
will become true.
NOTIf the expression result is false this operand will convert
the result into true.

Bitwise operators

Bitwise Operators used to perform manipulation of individual bits of a number. Bitwise operations are faster and usually use less power because of the reduced use of resources.

OperatorDescription
&The bitwise AND operator is used to compare two
numbers bit by bit of input values.
|The bitwise OR operator is used to compare two
numbers bit by bit of input values.
^The bitwise XOR operator is used to compare two
numbers bit by bit of input values.
~Bitwise compliment operator is used to inverts all the bits.
<<The Binary Left Shift Operator moves to the left operands
value to left by the number of bits specified by the right operand.
>>The Binary right Shift Operator moves to the right operands
value to left by the number of bits specified by the right operand.
>>>Shift right zero fill operator will shift right by pushing zeroes from the left.

One comment on “Java Operators”

  • admin February 6, 2021
    Reply

    Hello, I enjoy reading all of your article. I like to write a little comment to
    support you.

Write a comment