Precedence and associativity rules are necessary for deterministic evaluation of expressions. The operators, together with their precedence and associativity are summarized below.

The following remarks apply to below list:

  • The operators are shown with decreasing precedence from the top of the list
  • Operators within the same row have the same precedence.
  • Parentheses, (), can be used to override precedence and associativity.
  • The unary postfix operators and all binary operators, except for the assignment operators, associate from left to right.
  • All urary operators (except for unary postfix operators), all assignment operators, and the ternary conditional operator (including object creation and cast) associate from right to left.

Postfix Operators [], . (para), exp++, exp–

Prefix Unary Operators ++exp, –exp, +exp, -exp, ~, !

Object creation & cast new (type)

Multiplication *, /, %

Addition +, –

Shift <<, >>, >>>

Relational Operators <, <= ,>, >=, instanceof

Equality Operators ==, !=

bitwise/boolean AND &

bitwise/boolean XOR ^

bitwise/boolean OR |

logical AND &&

logical OR ||

Conditional Operator ?:

Assignment =, +=, -=, *=. /=, %=, <<=, >>=, >>>=, &=, ^=, |=

Advertisements