Java has well-defined rules for specifying the order in which the operators in an expression are evaluated when the expression has several operators.
Precedence Order
When two operators share an operand the operator with the higher precedence goes first.
Associativity
When two operators with the same precendence the expression is evaluated according to its associativity.
for example :
consider : 2 + 6 * 7 /4
since * and / have same precedence and have L to R associativity, * is evaluated first then /.
so it is evaluated as :
2 + ((6 * 7) / 4)
|
Operator Name |
Operators |
Associative |
| access array element, access object member, invoke a method |
[] . () | L to R |
| unary | ++ – - + - ~ ! (<data_type) | R to L |
| creation or cast | new (type)expression | R to L |
| multiplicative | * / % | L to R |
| additive | + - | L to R |
| shift | << , >> , >>> | L to R |
| relational | < , > , <= , >= , instance of | L to R |
| equality | == , != | L to R |
| bitwise AND | & | L to R |
| bitwise XOR | ^ | L to R |
| bitwise OR | | | L to R |
| logical AND | && | L to R |
| logical OR | || | L to R |
| conditional | <boolean_expr> ? <expr1> : <expr2> | R to L |
| assignment | = *= /= %= += -= <<=>>= >>>= &= ^= | = | R to L |
Important :
post-increment or post-decrement operators have higher precedence than pre-increment operator or pre-decrement operator.



July 25th, 2009 at 3:43 pm
Nice site. go to my favorites. TNx
July 28th, 2009 at 4:27 pm
The article is ver good. Write please more
punuptech.com – cool!!!!
July 30th, 2009 at 6:54 am
The best information i have found exactly here. Keep going Thank you
August 7th, 2009 at 7:43 am
I bookmarked this link. Thank you for good job!