Java Operators Explanations with Example

Java Operators Explanations with Example

Java derives many feature from C language(mother of programming language). Like C and C++ , java provide a large collection of operators to work on variables.
It also provides many new operators to work with like conditional operators(? : ) and instanceOf operator

Types Of Operators

Relational Operators Relational operator are refer to those operator that are used in program to manipulate variables to perform some comparison like ==(equal),!=(not equal) etc.

Arithmetic Operators These operator are used to perform mathematical calculation like +(addition), -(subtraction),*(multiplication),/(divide) etc.

Logical Operators These operator are used in logical decision like && (logical and) , || (logical or) etc. and return true or false as a result.

Assignment Operators Assignment (=) operator have only one operator to assign value from one variable to other, like a=b.
Here we assign b value to a.

Bitwise OperatorsIt works on bits and performs bit-by-bit operation.Firstly ,It convert integer value into bit.
Java have bitwise operators, which can be applied to the number or digit types, long, int, short, char, and byte.

Conditional Operators These operator is also known as the ternary operator. It have three operands and is used to evaluate Boolean expressions. The purpose of the operator is to decide which value should be assigned to the variable. The operator is written as:
variable a = (expression) ? value if true : value if false

List Of Operators And Their Precedence

Precedence in operator decides in expression which two operands are calculated first , it define how an whole expression is evaluated.

AssociativityOperator CategoryOperator Symbol
Left to rightPostfix() [] . (dot operator)
Right to leftUnary++ – – ! ~
Left to rightMultiplicative (Arithmetic Operator)* / %
Left to rightAdditive (Arithmetic Operator)+ –
Left to rightShift (Bitwise Operator)>> >>> <<
Left to rightRelational (Relational Operator)> >= < <=
Left to rightEquality (Relational Operator)== !=
Left to rightBitwise AND&
Left to rightBitwise OR|
Left to rightBitwise XOR^
Left to rightLogical AND&&
Left to rightLogical OR&
Right to leftAssignment= += -= *= /= %= >>= <<= &= ^= |=
Right to leftConditional?: