Java Operators

Operators are used to manipulate variables. There are following type of operators in java.

Arithmetic Operators

Arithmetic operators are used to perform mathematical operations. Following is the list of arithmetic operators in java.

Symbol Operator Example
 + Additive Operator  r =  n + 1;
 – Subtraction Operator  r =  n – 1;
 * Multiplication Operator  r =  n * 1;
 / Division Operator  r = n / 1;
 % Remainder Operator  r = n % 1;

Relational Operators

Relational operators are used to compare two variable and it will return true or false depending on the operator and values are variables being compared.

Symbol Operator Example
 == Equal to  a = = b
 != Not equal to  a ! = b
 > Greater than  a > b
 <  Less than  a < b
 >= Greater than or equal to  a > = b
 <= Less than or equal to  a > = b

Bitwise Operators

The bitwise operators work on bit level. They are used to manipulate the contents of variables at a bit level.

Symbol Operator Example
 ~ Unary bitwise complement ~var1
 & Bitwise AND var1 & var2
 | Bitwise inclusive OR var1 | var2
 ^ Bitwise exclusive OR var1 ^ var2
 << Signed left shift var1 << var2
 >> Signed right sift var1 >> var2
 >>> Unsigned right shift var1 >>> var2

Logical Operators

Logical operators are used to perform logical operations on variables. It return true or false depending on the value of variables and operator used.

Symbol Operator
 & AND
 && Conditional-AND
 | OR
 || Conditional-OR
 ! NOT
 ? : Ternary

Assignment Operators

Assignment operators are used to perform assignment operations on variables.

Symbol Operator Example
 = Simple assignment r = a + b
 += Add and Assignment r += a equivalent r = r + a
 -= Subtract and Assignment r -= a equivalent r = r – a
 *= Multiply and Assignment r *= a equivalent r = r * a
 /= Divide and Assignment r l= a equivalent r = r / a

Leave a Reply

Your email address will not be published. Required fields are marked *