num=num++;
equal to -
num = num; num ++;
First he appoints, then he tries to increase the number that is already assigned. For better framing -
0 iconst_0 1 istore_1 [num] 2 iconst_0 3 istore_2 [i] 4 goto 22 7 iload_1 [num] // Load first 8 iinc 1 1 [num] // incement but no reload 11 istore_1 [num] // store old load value 12 getstatic java.lang.System.out : java.io.PrintStream [16] 15 iload_1 [num] 16 invokevirtual java.io.PrintStream.print(int) : void [22] 19 iinc 2 1 [i] 22 iload_2 [i] 23 iconst_5 24 if_icmplt 7 27 return
if we consider num=++num;
then the byte code generated will be -
0 iconst_0 1 istore_1 [num] 2 iconst_0 3 istore_2 [i] 4 goto 22 7 iinc 1 1 [num] // Increment 10 iload_1 [num] // load the incremented value 11 istore_1 [num] // store the loaded incremented value ...
source share