Operator in java: – It is used to perform the operation over operands. The following are its type –

Arithmetic operator: – Used to perform arithmetic operation.

Ex: - +, -, *, / and % (modulus)

Unary operator: – Used to perform operation on one operand.

Ex: - -, ++, --

Assignment operator: – Used to store the R.H.S. value into L.H.S. variable.

Ex: - =

Relational operator: – Used to compare two operands and returns either true or false.

Ex: - >, <, >=, <=, !=, == etc.

Logical operator: – Used to compare two relational operators. It also returns either true or false.

Ex: - &&, ||, ! etc.

Boolean operator: – Used t fined either operation is true or false.

Ex: - &, |, !
Boolean a,b;
A=True;
B=True;
(a&b) = T
(a|b) = T
|(a|b) = F
!(a) = F

Bitwise operator: – It is used to work on binary number bit by bit of any integer value.

Ex: - &, |, ~, ^, >>, <<, >>> etc.

Ternary/Conditional Operator: – Used to compare the operands and based on true condition. First argument is considered otherwise second argument is considered.

Ex: - (?:)
Byte b=(10>5) ? 10:5;      //b=10
Byte b=(10<5) ? 10:5;      //b=5

Member operator (.): – This operator is used to call or access the member of class.

Ex: –

obj.mehod();
obj.variable;

new operator: – It is use to create a new object for specified class.

Syntax: – To create an object –

                Class_Name Reference_Variable=new Class_Name();

Ex: –

                Demo d=new Demo();

Instanceof operator: – Used to verify whether an object belongs to that specified class or not. It returns Boolean value either true or false.

Ex: –

Demo d=new Demo();
If(d instanceof Demo)
{
                _ _ _ _ _
                _ _ _ _ _
}

Cast operator: – Used to type cast explicitly are type into another type.

Syntax: - (Data_Type) Source_Variable;
Advertisements