Literals Rules for writing variable name
Jul 10

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.

written by Anup


4 Responses to “Operators precedence”

  1. 1. electromozzo Says:

    Nice site. go to my favorites. TNx

  2. 2. MishaPowerauto Says:

    The article is ver good. Write please more
    punuptech.com – cool!!!!

  3. 3. SergeyNikolaev Says:

    The best information i have found exactly here. Keep going Thank you

  4. 4. Vivalkakira Says:

    I bookmarked this link. Thank you for good job!

Leave a Reply