So, just to clarify (more for my own sanity right now, I'm trying to understand this) -- the operator ++ effectively acts after multiplication and division. Is that right?No. It acts after the operand is evaluated. So the value for the purposes of the rest of the expression is the unincremented operand. It acts before multiply etc as the precedence table says, but its effect isn't part of the resulting value. It changes the operand to the new value but returns the old value into the expression.
The value of 'test' will be zero. The value of i++ is the 'original' value before incrementing and that 'original' value is assigned to 'test'.
i = 0; test = i++;
to disassemble this. I manually added the actual source code so you can try to follow this
javap -c -l Test1
The Java Virtual Machine Specification has all of the JVM instructions and what they do.
int u = 2; 4:iconst_2 5:istore 5 int v = 3; 7:iconst_3 8:istore 6 int w = 5; 10:iconst_5 11:istore 7 int z; z = z = u++ / v + u++ * w; 13: iload 5 15: iinc 5, 1 18: iload 6 20: idiv 21: iload 5 23: iinc 5, 1 26: iload 7 28: imul 29: iadd 30: dup 31: istore 8 33: istore 8
It loads the variable again. This IS the incremented value. It was incremented by the 'iinc' on line 15 that I discussed above.
21: iload 5 - load variable 5 again