Operators in Java
Followings are the operator available in
Java.
- 1. Arithmetic operator
- 2. Unary operator
- 3. Assignment operator
- 4. Relational operator
- 5. Logical operator
- 6. Boolean operator
- 7. Bitwise operator
- 8. Dot operator
- 9. Ternary operator
- 10. Instance of operator
- 11. New operator
- 12. Cast operator
a.
Relational operator: &&, !!, || (and, or, not)
b.
Logical operator: <, >,
(Less than or greater than)
c.
Boolean operator: Boolean (It return either true or false
result)
d.
Bitwise operator: Bitwise
and &, Bitwise or |, Bitwise XOR x^y
e.
Instanceof operator: Instance of (This is used to check if some
object belong to the class or not for example you can write Boolean emp=Instanceof
Employee(this will return true if emp belongs to Employee class)
f.
New operator:
new (This is used to create object of a class)
g.
Cast operator: This is used to convert the one
data type to other. (for e.g. : double x=12.234 now you can convert x type to
int by using cast operator e.g.: int x=(int x);
h.
Dot operator: This is used to access packages or
methods of a class.
i.
Ternary operator: This is a type of conditional
operator. Syntax for this “ ? : “ (e.g. : a>b?a:b ) here in this example fist it will
check if a is greater than b or not if a> b return true then result is
stored in a otherwise result is stored in b.
j.
Tilde operator:
~ This is used to find the compliment of a number. This is also called as Bitwise compliment operator.
k. Assignment operator: = this is called assignment
operator and it is used to assign the values of right side expression into left
side expression
l. Unary operator: Unary minus(-) and Increment and Decrement operator comes under this.
Priority of operators:
First: () and [].
Next: ++ and –
Next: * / %
Next: Addition subtraction
Next: Relational Operator
Next: Boolean and Bitwise
Next: Logical operator
Next: Ternary
Next: Assignment