4. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
5. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
6. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
7. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
8. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
d
ize
gs
on
ar
hr
ar
nc
su atile t/v
pu te d
Flags This Class Super Class
al sy
ce
iva te
tiv ct
l n
ab tfp
vo nsie
pr ec
fin r/
na ra
fa
ic
tra e
pr ic
pe
Interfaces
st
er
bl
ric
ot
at
int
st
st
Fields
Methods
Attributes
9. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
10. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
11. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
12. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
13. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
14. Class File Format
CA FE BA BE Minor Version Major Version
Constant Pool
Flags This Class Super Class
Interfaces
Fields
Methods
Attributes
15. Constant Pool
C 2 UTF 10 HelloWorld
C 4 UTF 16
“java/lang/Object”
UTF 6 “<init>” UTF
3 “()V” UTF 4 “Code”
M 3 9 N&T 5 6 UTF 4
“main” UTF 22
“([Ljava/lang/String;)V”
F 13 15 C 14 UTF
16 “java/lang/System”
18. Name Flags
Field Format
int
er
fa
ce
st
ric
Attributes
ab tfp
s
na tra
tiv ct
tra e
vo nsie
Descriptor
l n
su atile t/v
pe ar
fin r/ ar
al sy gs
st nc
at hr
pr ic on
ot ize
pr ec
iva te d
pu te d
bl
ic
19. Field Format
Flags Name Descriptor
“name”
Attributes
20. Field Format
Flags Name Descriptor “Ljava/lang/String;”
Attributes
24. Name Flags
int
er
fa
ce
Method Format
st
ric
Attributes
ab tfp
s
na tra
tiv ct
tra e
vo nsie
Descriptor
l n
su atile t/v
pe ar
fin r/ ar
al sy gs
st nc
at hr
pr ic on
ot ize
pr ec
iva te d
pu te d
bl
ic
43. Operation Types
Load and Store
Arithmetic and Logic
Type Conversion
Branch Instructions
Object Creation and Manipulation
Operand Stack
Method Invocation
44. Data Types
ac ts refix
als
ns e P
ray oc
Co Cod
By ture
Ar k / L
St tan
na
te
Sig
boolean Z
Integer Types
byte B b
char C c
short S s
int I i
long J l
float F f
double D d
reference L a
void V
45. Parameters and Local Variables
static int volume(
int width,
int depth,
int height )
{
int area = width * depth;
int volume = area * height;
return volume;
}
46. Parameters and Local Variables
static int volume( 0 iload_0
int width,
1 iload_1
int depth,
int height ) 2 imul
{ 3 istore_3
int area = width * depth;
4 iload_3
int volume = area * height;
return volume; 5 iload_2
} 6 imul
7 istore 4
9 iload 4
11ireturn
47. Parameters and Local Variables
static int volume( 0 iload_0
int width,
1 iload_1
int depth,
2 imul
e
int height )
are t
h
lum
igh
h
pt
a
dt
{ 3 istore_3
de
he
vo
wi
0 1 2 3 4
int area = width * depth;
4 iload_3
int volume = area * height;
return volume; 5 iload_2
} 6 imul
7 istore 4
9 iload 4
11ireturn
48. Parameters and Local Variables
static int volume( 0 iload_0
int width,
1 iload_1
int depth,
2 imul
e
int height )
are t
h
lum
igh
h
pt
a
dt
{ 3 istore_3
de
he
vo
wi
0 1 2 3 4
int area = width * depth;
4 iload_3 1 2 3
int volume = area * height;
return volume; 5 iload_2
} 6 imul
7 istore 4
9 iload 4
11ireturn
49. Parameters and Local Variables
static int volume( 0 iload_0
int width,
1 iload_1
int depth,
2 imul
e
int height )
are t
h
lum
igh
h
pt
a
dt
{ 3 istore_3
de
he
vo
wi
0 1 2 3 4
int area = width * depth;
4 iload_3 1 2 3
int volume = area * height;
return volume; 5 iload_2
} 6 imul
7 istore 4
9 iload 4
11ireturn 1
50. Parameters and Local Variables
static int volume( 0 iload_0
int width,
1 iload_1
int depth,
2 imul
e
int height )
are t
h
lum
igh
h
pt
a
dt
{ 3 istore_3
de
he
vo
wi
0 1 2 3 4
int area = width * depth;
4 iload_3 1 2 3
int volume = area * height;
return volume; 5 iload_2
} 6 imul
7 istore 4
9 iload 4 2
11ireturn 1
51. Parameters and Local Variables
static int volume( 0 iload_0
int width,
1 iload_1
int depth,
2 imul
e
int height )
are t
h
lum
igh
h
pt
a
dt
{ 3 istore_3
de
he
vo
wi
0 1 2 3 4
int area = width * depth;
4 iload_3 1 2 3
int volume = area * height;
return volume; 5 iload_2
} 6 imul
7 istore 4
9 iload 4
11ireturn 2
52. Parameters and Local Variables
static int volume( 0 iload_0
int width,
1 iload_1
int depth,
2 imul
e
int height )
are t
h
lum
igh
h
pt
a
dt
{ 3 istore_3
de
he
vo
wi
0 1 2 3 4
int area = width * depth;
4 iload_3 1 2 3 2
int volume = area * height;
return volume; 5 iload_2
} 6 imul
7 istore 4
9 iload 4
11ireturn
53. Parameters and Local Variables
static int volume( 0 iload_0
int width,
1 iload_1
int depth,
2 imul
e
int height )
are t
h
lum
igh
h
pt
a
dt
{ 3 istore_3
de
he
vo
wi
0 1 2 3 4
int area = width * depth;
4 iload_3 1 2 3 2
int volume = area * height;
return volume; 5 iload_2
} 6 imul
7 istore 4
9 iload 4
11ireturn 2
54. Parameters and Local Variables
static int volume( 0 iload_0
int width,
1 iload_1
int depth,
2 imul
e
int height )
are t
h
lum
igh
h
pt
a
dt
{ 3 istore_3
de
he
vo
wi
0 1 2 3 4
int area = width * depth;
4 iload_3 1 2 3 2
int volume = area * height;
return volume; 5 iload_2
} 6 imul
7 istore 4
9 iload 4 3
11ireturn 2
55. Parameters and Local Variables
static int volume( 0 iload_0
int width,
1 iload_1
int depth,
2 imul
e
int height )
are t
h
lum
igh
h
pt
a
dt
{ 3 istore_3
de
he
vo
wi
0 1 2 3 4
int area = width * depth;
4 iload_3 1 2 3 2
int volume = area * height;
return volume; 5 iload_2
} 6 imul
7 istore 4
9 iload 4
11ireturn 6
56. Parameters and Local Variables
static int volume( 0 iload_0
int width,
1 iload_1
int depth,
2 imul
e
int height )
are t
h
lum
igh
h
pt
a
dt
{ 3 istore_3
de
he
vo
wi
0 1 2 3 4
int area = width * depth;
4 iload_3 1 2 3 2 6
int volume = area * height;
return volume; 5 iload_2
} 6 imul
7 istore 4
9 iload 4
11ireturn
57. Parameters and Local Variables
static int volume( 0 iload_0
int width,
1 iload_1
int depth,
2 imul
e
int height )
are t
h
lum
igh
h
pt
a
dt
{ 3 istore_3
de
he
vo
wi
0 1 2 3 4
int area = width * depth;
4 iload_3 1 2 3 2 6
int volume = area * height;
return volume; 5 iload_2
} 6 imul
7 istore 4
9 iload 4
11ireturn 6
58. Parameters and Local Variables
static int volume( 0 iload_0
int width,
1 iload_1
int depth,
2 imul
e
int height )
are t
h
lum
igh
h
pt
a
dt
{ 3 istore_3
de
he
vo
wi
0 1 2 3 4
int area = width * depth;
4 iload_3 1 2 3 2 6
int volume = area * height;
return volume; 5 iload_2
} 6 imul
7 istore 4
9 iload 4
11ireturn
59. Static vs Virtual Methods
static int volume( 0 iload_0
int width, 1 iload_1
int depth,
2 imul
e
int height )
are t
he h
lum
h
igh
pt
a
dt
{ 3 istore_3
de
wi
vo
0 1 2 3 4 5
int area = width * depth; 4 iload_3
int volume = area * height;
return volume; 5 iload_2
} 6 imul
7 istore 4
9 iload 4
11 ireturn
60. Static vs Virtual Methods
int volume( 0 iload_0
int width, 1 iload_1
int depth,
2 imul
e
int height )
are t
he h
lum
h
igh
pt
a
dt
{ 3 istore_3
de
wi
vo
0 1 2 3 4 5
int area = width * depth; 4 iload_3
int volume = area * height;
return volume; 5 iload_2
} 6 imul
7 istore 4
9 iload 4
11 ireturn
61. Static vs Virtual Methods
int volume( 0 iload_0
int width, 1 iload_1
int depth,
2 imul
e
int height )
are t
he h
lum
h
igh
pt
a
dt
s
{ 3 istore_3
de
thi
wi
vo
0 1 2 3 4 5
int area = width * depth; 4 iload_3
int volume = area * height;
return volume; 5 iload_2
} 6 imul
7 istore 4
9 iload 4
11 ireturn
62. Static vs Virtual Methods
int volume( 0 iload_1
int width, 1 iload_2
int depth,
2 imul
e
int height )
are t
he h
lum
h
igh
pt
a
dt
s
{ 3 istore 4
de
thi
wi
vo
0 1 2 3 4 5
int area = width * depth; 5 iload 4
int volume = area * height;
return volume; 7 iload_3
} 8 imul
9 istore 5
11 iload 5
13 ireturn
71. New Object
return new BigDecimal(“2.0”);
0 new BigDecimal
3 dup
4 ldc “2.0”
6 invokespecial BigDecimal.<init>
9 areturn
72. New Object
return new BigDecimal(“2.0”);
0 1 2 3
0 new BigDecimal
3 dup
4 ldc “2.0”
“2.0”
6 invokespecial BigDecimal.<init>
9 areturn
73. New Object
return new BigDecimal(“2.0”);
0 1 2 3
0 new BigDecimal
3 dup
4 ldc “2.0”
“2.0”
6 invokespecial BigDecimal.<init>
9 areturn
BigDecimal
74. New Object
return new BigDecimal(“2.0”);
0 1 2 3
0 new BigDecimal
3 dup
4 ldc “2.0”
“2.0”
6 invokespecial BigDecimal.<init>
9 areturn
BigDecimal
75. New Object
return new BigDecimal(“2.0”);
0 1 2 3
0 new BigDecimal
3 dup
4 ldc “2.0”
“2.0”
6 invokespecial BigDecimal.<init>
9 areturn
BigDecimal
76. New Object
return new BigDecimal(“2.0”);
0 1 2 3
0 new BigDecimal
3 dup
4 ldc “2.0”
“2.0”
6 invokespecial BigDecimal.<init>
9 areturn
BigDecimal
77. If / Else
static boolean isPositive( int val ){
if ( val > 0 ) {
return true;
} else {
return false;
}
}
78. If / Else
static boolean isPositive( int val ){ 0 iload_0
test
if ( val > 0 ) { 1 ifle +5 //6
return true;
4 iconst_1
} else {
if
return false; 5 ireturn
} 6 iconst_0
else
} 7 ireturn
79. If / Else
static boolean isPositive( int val ){ 0 iload_0
test
if ( val > 0 ) { 1 ifle +5 //6
return true;
4 iconst_1
} else {
if
return false; 5 ireturn
} 6 iconst_0
else
} 7 ireturn
80. If / Else
static boolean isPositive( int val ){ 0 iload_0
test
if ( val > 0 ) { 1 ifle +5 //6
return true;
4 iconst_1
} else {
if
return false; 5 ireturn
} 6 iconst_0
else
} 7 ireturn
81. If / Else
static boolean isPositive( int val ){ 0 iload_0
test
if ( val > 0 ) { 1 ifle +5 //6
return true;
4 iconst_1
} else {
if
return false; 5 ireturn
} 6 iconst_0
else
} 7 ireturn
82. If / Else
static boolean isPositive( int val ){ 0 iload_0
test
if ( val > 0 ) { 1 ifle +5 //6
return true;
4 iconst_1
} else {
if
return false; 5 ireturn
} 6 iconst_0
else
} 7 ireturn
static boolean isPositive( int val ){
return ( val > 0 );
}
83. If / Else
static boolean isPositive( int val ){
if ( val > 0 ) {
return true;
} else {
return false;
}
}
static boolean isPositive( int val ){
return ( val > 0 );
}
84. If / Else
static boolean isPositive( int val ){ 0 iload_0
test
if ( val > 0 ) { 1 ifle +5 //6
return true;
4 iconst_1
} else {
if
return false; 5 ireturn
} 6 iconst_0
else
} 7 ireturn
static boolean isPositive( int val ){
return ( val > 0 );
}
85. For Loop
static int sum( int min, int max ){
int sum = 0;
for ( int i=min; i<max; ++i ){
sum += i;
}
return sum;
}
86. before
0 iconst_0
For Loop
init & test loop
1 istore_2
2 iload_1
static int sum( int min, int max ){ 3 istore_3
int sum = 0; 4 goto +10 //14
for ( int i=min; i<max; ++i ){ 7 iload_2
loop body
sum += i; 8 iload_3
} 9 iadd
return sum; 10 istore_2
}
inc
11 iinc 3 by 1
14 iload_3
test 15 iload_1
16 if_icmplt -9 //7
19 iload_2
after
loop
20 ireturn
87. before
0 iconst_0
For Loop
init & test loop
1 istore_2
2 iload_1
static int sum( int min, int max ){ 3 istore_3
int sum = 0; 4 goto +10 //14
for ( int i=min; i<max; ++i ){ 7 iload_2
loop body
sum += i; 8 iload_3
} 9 iadd
return sum; 10 istore_2
}
inc
11 iinc 3 by 1
14 iload_3
test 15 iload_1
16 if_icmplt -9 //7
19 iload_2
after
loop
20 ireturn
88. before
0 iconst_0
For Loop
init & test loop
1 istore_2
2 iload_1
static int sum( int min, int max ){ 3 istore_3
int sum = 0; 4 goto +10 //14
for ( int i=min; i<max; ++i ){ 7 iload_2
loop body
sum += i; 8 iload_3
} 9 iadd
return sum; 10 istore_2
}
inc
11 iinc 3 by 1
14 iload_3
test 15 iload_1
16 if_icmplt -9 //7
19 iload_2
after
loop
20 ireturn
89. before
0 iconst_0
For Loop
init & test loop
1 istore_2
2 iload_1
static int sum( int min, int max ){ 3 istore_3
int sum = 0; 4 goto +10 //14
for ( int i=min; i<max; ++i ){ 7 iload_2
loop body
sum += i; 8 iload_3
} 9 iadd
return sum; 10 istore_2
}
inc
11 iinc 3 by 1
14 iload_3
test 15 iload_1
16 if_icmplt -9 //7
19 iload_2
after
loop
20 ireturn
90. before
0 iconst_0
For Loop
init & test loop
1 istore_2
2 iload_1
static int sum( int min, int max ){ 3 istore_3
int sum = 0; 4 goto +10 //14
for ( int i=min; i<max; ++i ){ 7 iload_2
loop body
sum += i; 8 iload_3
} 9 iadd
return sum; 10 istore_2
}
inc
11 iinc 3 by 1
14 iload_3
test 15 iload_1
16 if_icmplt -9 //7
19 iload_2
after
loop
20 ireturn
91. before
0 iconst_0
For Loop
init & test loop
1 istore_2
2 iload_1
static int sum( int min, int max ){ 3 istore_3
int sum = 0; 4 goto +10 //14
for ( int i=min; i<max; ++i ){ 7 iload_2
loop body
sum += i; 8 iload_3
} 9 iadd
return sum; 10 istore_2
}
inc
11 iinc 3 by 1
14 iload_3
test 15 iload_1
16 if_icmplt -9 //7
19 iload_2
after
loop
20 ireturn
92. before
0 iconst_0
For Loop
init & test loop
1 istore_2
2 iload_1
static int sum( int min, int max ){ 3 istore_3
int sum = 0; 4 goto +10 //14
for ( int i=min; i<max; ++i ){ 7 iload_2
loop body
sum += i; 8 iload_3
} 9 iadd
return sum; 10 istore_2
}
inc
11 iinc 3 by 1
14 iload_3
test 15 iload_1
16 if_icmplt -9 //7
19 iload_2
after
loop
20 ireturn
93. Exception Handling
static int read( InputStream in ) {
try {
return in.read();
} catch ( IOException e ) {
return -1;
} finally {
IoUtils.closeQuietly( in );
}
}
102. Resources
The Java Virtual Machine Specification
http://java.sun.com/docs/books/jvms/
JClassLib Viewer
http://www.ej-technologies.com/products/jclasslib/
overview.html
Maxine VM
http://labs.oracle.com/projects/maxine/
New Features in Java 6 - Annotation Processing
http://www.javabeat.net/articles/14-java-60-features-
part-2-pluggable-annotation-proce-1.html