Welcome to the Ranch Thomas.
Because you did not state your question I am only guessing:
var1+(increment(2)+var1) should print 21, instead of 19 as it does? The reasoning is given that the parentheses executes first the first var1 should be 7 when evaluated?
In
java the expressions are evaluted from left to right. The value of the first var1 (5) is stored (in the operand stack) and then the rest of the expression is executed. Thus the problem was the tendency to think that a parentheses is executed before anything to its left. This is not true when evaluating expressions in Java.
It is possible to check this out using javap -c
Test:
The bytecode at line 0 stores the value of var1 in the operand stack before the invokation of increment(2) in line 4. The last integer addition (iadd) at line 11 adds this value previously stored, and the result of
increment(2) + var1