Java language has operators of all kinds namely Arithmetic Operators, Relational Operators, Logical Operators and Bitwise Operators. Different Java operators have got different precedence and associativity.
Java Operator Priority or Precedence and Associativity of all Operators
Along with operators like Arithmetic, Relational, Logical and Bitwise, Java also provides operators like Parentheses ( ) which increase the priority of a small expression inside a big expression. Type casting operation (typecast) has also got a higher priority. Let us see how Java Operator Precedence affects the result of any algebraic expression.
Golden Point: Java Operator Priority or Precedence decides which operators need to be evaluated first. Java Operator associativity decides which operator to be evaluated if more than one operators have equal priority.
|1||[ ], ( ), DOT (.)||Left to Right|
|2||++, -- Postfix||Right to Left|
|3||++, -- (Prefix), ~, !, Unary Minus (-), Unary Plus(+), (typecast L2R)||Right to Left|
|4||*, /, % Arithemetic||Left to Right|
|5||+, - Arithmetic||Left to Right|
|6||<<, >>, >>> Bitwise||Left to Right|
|7||>, >=, <, <= Relational||Left to Right|
|8||==, != Relational||Left to Right|
|9||& Bitwise, Logical||Left to Right|
|10||^ Bitwise, Logical||Left to Right|
|11||| Bitwise, Logical||Left to Right|
|12||&& Bitwise, Logical||Left to Right|
|13|||| Bitwise, Logical||Left to Right|
|14||?: Ternary Operator||Right to Left|
|15||-> Arrow Operator||Left to Right|
|15||=, op= (Compound Assignment)||Right to Left|
From the above Java operator priority table, it is understood that Postfix Increment and Postfix Decrement operators have got highest Priority or Precedence among all other operators. Equal to and Compound Assignment Operator have got the least priority among all other operators.
Go through Tutorials on Java Operators and Priority in the below list. Tutorials contain code examples for better understanding.
|1.||Arithmetic Operators & Priority|
|2.||Relational Operators & Priority|
|3.||Logical Operators & Priority|
|4.||Bitwise Operators & Priority|
That is all about different types of Java Operators, their Priority and Associativity.
Share this tutorial with your friends and colleagues to encourage authors.