I think you are confused as to what precedence means. It doesn't mean order of execution in all cases. It means order of nested or association e.g. it means that
j = i++
is the same as
j = (i++)
not
(j = i)++
like
a = b + c * d
is
(a = (b + (c * d)))
As Jacob notes: the ++
means increment this value after using or saving the original value. In Java this is always done at the end, whereas in C and C++ it is not defined as to when this will happen.
EDIT: A more complex example is as follows
int i = 3;
int j = 4;
int k = i-- * j++; // same as int k = i * j; i--; j++;
System.out.println(k);
prints
12
and it is not the same as
int i = 3;
int j = 4;
int k = (i = i - 1) * (j = j + 1);
System.out.println(k);
10
manpreet
Best Answer
2 years ago
Actually i am a kickbhut in C. I just started to learn Java. And directly preparing for OCJP6 Certification. In Kathy-Sierra book, and as well as in exam syllabus also, there's no Operator's precedence matter. But i was in fully confused when i saw the Java Operators precedence table from orablce-sun Documentation.
Please some one clarify me!