Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
442 views

Operator Precedence in Java

Operators in Java have a specific precedence from highest to lowest. Parentheses can be used to alter the default precedence if needed. The highest precedence operators are array indexing, method calls, and member access. Next are unary operators like increment/decrement. Multiplication and division are higher than addition and subtraction. Relational and equality operators like less than and equal to are next. Logical AND has higher precedence than logical OR. Assignment and combined assignment have the lowest precedence.

Uploaded by

Gabriela Pech
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
442 views

Operator Precedence in Java

Operators in Java have a specific precedence from highest to lowest. Parentheses can be used to alter the default precedence if needed. The highest precedence operators are array indexing, method calls, and member access. Next are unary operators like increment/decrement. Multiplication and division are higher than addition and subtraction. Relational and equality operators like less than and equal to are next. Logical AND has higher precedence than logical OR. Assignment and combined assignment have the lowest precedence.

Uploaded by

Gabriela Pech
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

3/28/2011 Operator Precedence in Java

Operator Precedence in Java


NOTE: Use explicit parentheses when there is even the possibility of confusion.

The operators in Java, shown in order of precedence - from highest to lowest


Priority Operators Operation Associativity
[ ] array index
1 () method call left
. member access

++ pre- or postfix increment


-- pre- or postfix decrement
+ - unary plus, minus
2 ~ bitwise NOT right
! boolean (logical) NOT
(type) type cast
new object creation

3 * / % multiplication, division, remainder left

+ - addition, substraction
4 left
+ string concatenation

<< signed bit shift left


5 >> signed bit shift right left
>>> unsigned bit shift right

< <= less than, less than or equal to


6 > >= greater than, greater than or equal to left
instanceof reference test

== equal to
7 left
!= not equal to

& bitwise AND


8 left
& boolean (logical) AND

^ bitwise XOR
9 left
^ boolean (logical) XOR

| bitwise OR
10 left
| boolean (logical) OR

11 && boolean (logical) AND left

12 || boolean (logical) OR left


uni-bonn.de/…/javaoperators.php?me… 1/2
3/28/2011 Operator Precedence in Java
13 ? : conditional right

= assignment
*= /= += -= %=

14 combinated assignment right


<<= >>= >>>=
(operation and assignment)

&= ^= |=

Further reading
Java Language Specification SE :
Evaluation Order (Expressions )

Retrieved from http://www.uni-bonn.de/~manfear/javaoperators.php.

uni-bonn.de/…/javaoperators.php?me… 2/2

You might also like