Sunday, 28 June 2015

OPERATORS IN JAVA

OPERATORS IN JAVA

JAVA supports 44 number of operators and like C and C++, it's divided into 3 categories ,
1. Unary operator.
2. Binary operator
3. Conditional operator.

UNARY: + , - , ++ , -- , !

BINARY:
Arithmatic: + , - , * , / , ÷
Logical: && , ||
Bitwise: & , | , ^
Relational: > , < , >= , <= , != , ==
Assignment: = , += , -= , *= , ÷= , /=
Shift: << , >> , >>> ( unsigned right shift)

Ternary: ?!
Special: ( ), [ ] , , , . , type , instanceof

Modulus operator never works for float and double value in C or C++, but works in JAVA. I.e System.out.println(10.0℅3.0); o/p = 1.0

TYPE OPERATOR OR TYPE CASTING OPERATOR
Typecasting in JAVA is divided into 3 types-
1. Implicit casting
2. Explicit casting
3. Boolean casting.

Instanceof operator: it's am object comparison operator.
This operator always checks the object existence and returns Boolean value.
Object if the child class can be the object of the parent class.

DOT OPERATOR: It access the variable or the constant, accesses the method , accesses the object, accesses the class and accesses the package.