O'Reilly logo

The Java® Virtual Machine Specification, Java SE 7 Edition, Third Edition by Alex Buckley, Gilad Bracha, Frank Yellin, Tim Lindholm

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.2. Use of Constants, Local Variables, and Control Constructs

Java Virtual Machine code exhibits a set of general characteristics imposed by the Java Virtual Machine’s design and use of types. In the first example we encounter many of these, and we consider them in some detail.

The spin method simply spins around an empty for loop 100 times:

void spin() {     int i;     for (i = 0; i < 100; i++) {         ;    // Loop body is empty     } }

A compiler might compile spin to:

0   iconst_0        // Push int constant 0 1   istore_1        // Store into local variable 1 (i=0) 2   goto 8          // First time through don't increment 5   iinc 1 1        // Increment local variable 1 by 1 (i++) 8   iload_1         // Push local variable 1 (i) 9    ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required