What is the right precedence of the math expression

Viewed 16839

What is the correct sequence of the math operations in this expression in Java:

    a + b  * c / ( d - e )
1.    4    1   3     2
2.    4    2   3     1

I understand that result is the same in both answers. But I would like to fully understand the java compiler logic. What is executed first in this example - multiplication or the expression in parentheses? A link to the documentation that covers that would be helpful.

UPDATE: Thank you guys for the answers. Most of you write that the expression in parentheses is evaluated first. After looking at the references provided by Grodriguez I created little tests:

int i = 2;
System.out.println(i * (i=3)); // prints '6'
int j = 2;
System.out.println((j=3) * j); // prints '9'

Could anybody explain why these tests produce different results? If the expression in parentheses is evaluated the first I would expect the same result - 9.

8 Answers
Related