Java Operators

Email this to someonePrint this pageShare on Google+2Share on Facebook1Tweet about this on TwitterShare on LinkedIn1Share on Reddit0Pin on Pinterest3Share on StumbleUpon1

Java Operators
In this chapter we will learn about Operator Precedence and Operator Associativity.

Operator Precedence
Precedence decides which operator will be evaluated first in a case where more than one operators are present in the same calculation.

Operator Precedence Table

Operators Precedence(High to Low)
postfix expr++ expr
unary ++expr —expr +expr –expr ~ !
multiplicative * / %
additive + –
shift << >> >>>
relational < > <= >= instanceof
equality == !=
bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
logical AND &&
logical OR ||
ternary ? :
assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=

Example of Precedence

Operator Associativity
If two operators having same precedence exists in the calculation then Associativity of the operators will be used to decide which operator will be executed first.

Example of Associativity

Operators in Java
Let us discuss about each operator individually.Assignment (=) and Arithmetic operators(+, -, *, /) will work the same way as they do in other programming language. So we will not discuss about them. The precedence for ’/‘ & ’*‘ operators is higher than sum(+) or minus(-) or modular division(%).

Email this to someonePrint this pageShare on Google+2Share on Facebook1Tweet about this on TwitterShare on LinkedIn1Share on Reddit0Pin on Pinterest3Share on StumbleUpon1

About Team

Browse Archived Articles by Team