Saturday 2 May 2015

In the JVM 1 + 1 = 4

Assuming a and b are equals to 1 :

int a = 1;
int b = 1;

How many JVM operations you see in the following code?

int c = a + b;






The answer is 4 :

iload_0
iload_1
iadd
istore_2


The JVM will load a and b (index 0 and 1 of the local variable array), add them together (in the operand stack), and will assign the result to c (index 2 of the local variable array).


No comments:

Post a Comment