Thursday, November 14, 2013

Basic Operators in Java

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:
  • Arithmetic Operators
  • Relational Operators
  • Bitwise Operators
  • Logical Operators
  • Assignment Operators
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:
OperatorDescription
+Addition
-Subtraction
*Multiplication
/Division
%Modulus
++Increment
--Decrement

The Relational Operators:

There are following relational operators supported by Java language
OperatorDescription
==Is equal
!=Not equal
>Greater than
<Less than
>=Greater than equal to
<=Less than equal to
The Bitwise Operators:

Java defines several bitwise operators which can be applied to the integer types, long, int, short, char, and byte.
OperatorDescription
&Binary AND Operator
|Binary OR Operator
^Binary XOR Operator
~Binary Ones Complement Operator
<<Binary Left Shift Operator.
>>Binary Right Shift Operator.
>>>Shift right zero fill operator.
Logical Operators:

The following table lists the logical operators:
OperatorDescription
&&Called Logical AND  operator
||Called Logical OR  operator.
!Called Logical NOT  operator.
The Assignment Operators:

There are following assignment operators supported by Java language:
OperatorDescription
=Simple assignment operator, Assigns values from right side operands to left side operand
+=Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand
-=Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand
*=Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand
/=Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand
%=Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand
<<=Left shift AND assignment operator
>>=Right shift AND assignment operator
&=Bitwise AND assignment operator
^=bitwise exclusive OR and assignment operator
|=bitwise inclusive OR and assignment operator

No comments:

Post a Comment