<s>
A	O
Java	B-Language
class	I-Language
file	I-Language
is	O
a	O
file	B-Operating_System
(	O
with	O
the	O
filename	O
extension	O
)	O
containing	O
Java	B-Language
bytecode	I-Language
that	O
can	O
be	O
executed	O
on	O
the	O
Java	B-Language
Virtual	I-Language
Machine	I-Language
(	O
JVM	B-Language
)	O
.	O
</s>
<s>
A	O
Java	B-Language
class	I-Language
file	I-Language
is	O
usually	O
produced	O
by	O
a	O
Java	B-Language
compiler	I-Language
from	O
Java	B-Language
programming	I-Language
language	I-Language
source	O
files	O
(	O
files	O
)	O
containing	O
Java	B-Language
classes	O
(	O
alternatively	O
,	O
other	O
JVM	B-Language
languages	I-Language
can	O
also	O
be	O
used	O
to	O
create	O
class	B-Language
files	I-Language
)	O
.	O
</s>
<s>
If	O
a	O
source	O
file	B-Operating_System
has	O
more	O
than	O
one	O
class	O
,	O
each	O
class	O
is	O
compiled	O
into	O
a	O
separate	O
class	B-Language
file	I-Language
.	O
</s>
<s>
JVMs	B-Language
are	O
available	O
for	O
many	O
platforms	B-Device
,	O
and	O
a	O
class	B-Language
file	I-Language
compiled	O
on	O
one	O
platform	B-Device
will	O
execute	O
on	O
a	O
JVM	B-Language
of	O
another	O
platform	B-Device
.	O
</s>
<s>
This	O
makes	O
Java	B-Language
applications	O
platform-independent	B-Operating_System
.	O
</s>
<s>
On	O
11	O
December	O
2006	O
,	O
the	O
class	B-Language
file	I-Language
format	O
was	O
modified	O
under	O
Java	B-Language
Specification	I-Language
Request	I-Language
(	O
JSR	O
)	O
202	O
.	O
</s>
<s>
There	O
are	O
10	O
basic	O
sections	O
to	O
the	O
Java	B-Language
class	I-Language
file	I-Language
structure	O
:	O
</s>
<s>
Class	B-Language
files	I-Language
are	O
identified	O
by	O
the	O
following	O
4	O
byte	B-Application
header	B-General_Concept
(	O
in	O
hexadecimal	O
)	O
:	O
CA	O
FE	O
BA	O
BE	O
(	O
the	O
first	O
4	O
entries	O
in	O
the	O
table	O
below	O
)	O
.	O
</s>
<s>
I	O
was	O
re-vamping	O
some	O
file	B-Operating_System
format	O
code	O
and	O
needed	O
a	O
couple	O
of	O
magic	O
numbers	O
:	O
one	O
for	O
the	O
persistent	O
object	O
file	B-Operating_System
,	O
and	O
one	O
for	O
classes	O
.	O
</s>
<s>
I	O
used	O
CAFEDEAD	O
for	O
the	O
object	O
file	B-Operating_System
format	O
,	O
and	O
in	O
grepping	O
for	O
4	O
character	O
hex	O
words	O
that	O
fit	O
after	O
"	O
CAFE	O
"	O
(	O
it	O
seemed	O
to	O
be	O
a	O
good	O
theme	O
)	O
I	O
hit	O
on	O
BABE	O
and	O
decided	O
to	O
use	O
it	O
.	O
</s>
<s>
So	O
CAFEBABE	O
became	O
the	O
class	B-Language
file	I-Language
format	O
,	O
and	O
CAFEDEAD	O
was	O
the	O
persistent	O
object	O
format	O
.	O
</s>
<s>
But	O
the	O
persistent	O
object	O
facility	O
went	O
away	O
,	O
and	O
along	O
with	O
it	O
went	O
the	O
use	O
of	O
CAFEDEAD	O
-	O
it	O
was	O
eventually	O
replaced	O
by	O
RMI.	O
"	O
</s>
<s>
Because	O
the	O
class	B-Language
file	I-Language
contains	O
variable-sized	O
items	O
and	O
does	O
not	O
also	O
contain	O
embedded	O
file	B-Operating_System
offsets	O
(	O
or	O
pointers	O
)	O
,	O
it	O
is	O
typically	O
parsed	O
sequentially	O
,	O
from	O
the	O
first	O
byte	B-Application
toward	O
the	O
end	O
.	O
</s>
<s>
At	O
the	O
lowest	O
level	O
the	O
file	B-Operating_System
format	O
is	O
described	O
in	O
terms	O
of	O
a	O
few	O
fundamental	O
data	O
types	O
:	O
</s>
<s>
The	O
number	O
of	O
items	O
in	O
the	O
table	O
is	O
identified	O
by	O
a	O
preceding	O
count	O
number	O
(	O
the	O
count	O
is	O
a	O
u2	O
)	O
,	O
but	O
the	O
size	O
in	O
bytes	B-Application
of	O
the	O
table	O
can	O
only	O
be	O
determined	O
by	O
examining	O
each	O
of	O
its	O
items	O
.	O
</s>
<s>
There	O
is	O
no	O
enforcement	O
of	O
word	O
alignment	O
,	O
and	O
so	O
no	O
padding	O
bytes	B-Application
are	O
ever	O
used	O
.	O
</s>
<s>
The	O
overall	O
layout	O
of	O
the	O
class	B-Language
file	I-Language
is	O
as	O
shown	O
in	O
the	O
following	O
table	O
.	O
</s>
<s>
byte	B-Application
offset	O
size	O
type	O
or	O
value	O
description	O
0	O
4	O
bytes	B-Application
u1	O
=	O
0xCA	O
hex	O
magic	O
number	O
(	O
CAFEBABE	O
)	O
used	O
to	O
identify	O
file	B-Operating_System
as	O
conforming	O
to	O
the	O
class	B-Language
file	I-Language
format	O
1	O
u1	O
=	O
0xFE	O
hex	O
2	O
u1	O
=	O
0xBA	O
hex	O
3	O
u1	O
=	O
0xBE	O
hex	O
4	O
2	O
bytes	B-Application
u2	O
minor	O
version	O
number	O
of	O
the	O
class	B-Language
file	I-Language
format	O
being	O
used	O
5	O
6	O
2	O
bytes	B-Application
u2	O
major	O
version	O
number	O
of	O
the	O
class	B-Language
file	I-Language
format	O
being	O
used	O
.	O
</s>
<s>
Java	B-Language
SE	O
21	O
=	O
65	O
(	O
0x41	O
hex	O
)	O
,	O
</s>
<s>
Java	B-Language
SE	O
20	O
=	O
64	O
(	O
0x40	O
hex	O
)	O
,	O
</s>
<s>
Java	B-Language
SE	O
19	O
=	O
63	O
(	O
0x3F	O
hex	O
)	O
,	O
</s>
<s>
Java	B-Language
SE	O
18	O
=	O
62	O
(	O
0x3E	O
hex	O
)	O
,	O
</s>
<s>
Java	B-Language
SE	O
17	O
=	O
61	O
(	O
0x3D	O
hex	O
)	O
,	O
</s>
<s>
Java	B-Language
SE	O
16	O
=	O
60	O
(	O
0x3C	O
hex	O
)	O
,	O
</s>
<s>
Java	B-Language
SE	O
15	O
=	O
59	O
(	O
0x3B	O
hex	O
)	O
,	O
</s>
<s>
Java	B-Language
SE	O
14	O
=	O
58	O
(	O
0x3A	O
hex	O
)	O
,	O
</s>
<s>
Java	B-Language
SE	O
13	O
=	O
57	O
(	O
0x39	O
hex	O
)	O
,	O
</s>
<s>
Java	B-Language
SE	O
12	O
=	O
56	O
(	O
0x38	O
hex	O
)	O
,	O
</s>
<s>
Java	B-Language
SE	O
11	O
=	O
55	O
(	O
0x37	O
hex	O
)	O
,	O
</s>
<s>
Java	B-Language
SE	O
10	O
=	O
54	O
(	O
0x36	O
hex	O
)	O
,	O
</s>
<s>
Java	B-Language
SE	O
9	O
=	O
53	O
(	O
0x35	O
hex	O
)	O
,	O
</s>
<s>
Java	B-Language
SE	O
8	O
=	O
52	O
(	O
0x34	O
hex	O
)	O
,	O
Java	B-Language
SE	O
7	O
=	O
51	O
(	O
0x33	O
hex	O
)	O
,	O
Java	B-Language
SE	O
6.0	O
=	O
50	O
(	O
0x32	O
hex	O
)	O
,	O
Java	B-Language
SE	O
5.0	O
=	O
49	O
(	O
0x31	O
hex	O
)	O
,	O
JDK	O
1.4	O
=	O
48	O
(	O
0x30	O
hex	O
)	O
,	O
JDK	O
1.3	O
=	O
47	O
(	O
0x2F	O
hex	O
)	O
,	O
JDK	O
1.2	O
=	O
46	O
(	O
0x2E	O
hex	O
)	O
,	O
JDK	O
1.1	O
=	O
45	O
(	O
0x2D	O
hex	O
)	O
.For	O
details	O
of	O
earlier	O
version	O
numbers	O
see	O
footnote	O
1	O
at	O
The	O
JavaTM	O
Virtual	O
Machine	O
Specification	O
2nd	O
edition	O
7	O
8	O
2	O
bytes	B-Application
u2	O
constant	O
pool	O
count	O
,	O
number	O
of	O
entries	O
in	O
the	O
following	O
constant	O
pool	O
table	O
.	O
</s>
<s>
each	O
element	O
is	O
an	O
attribute_info	O
structure	O
defined	O
in	O
https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7	O
...	O
...	O
...	O
</s>
<s>
Since	O
C	B-Language
does	O
n't	O
support	O
multiple	O
variable	O
length	O
arrays	O
within	O
a	O
struct	O
,	O
the	O
code	O
below	O
wo	O
n't	O
compile	O
and	O
only	O
serves	O
as	O
a	O
demonstration	O
.	O
</s>
<s>
All	O
indexes	O
,	O
or	O
references	O
,	O
to	O
specific	O
constants	O
in	O
the	O
constant	O
pool	O
table	O
are	O
given	O
by	O
16-bit	B-Device
(	O
type	O
u2	O
)	O
numbers	O
,	O
where	O
index	O
value	O
1	O
refers	O
to	O
the	O
first	O
constant	O
in	O
the	O
table	O
(	O
index	O
value	O
0	O
is	O
invalid	O
)	O
.	O
</s>
<s>
Due	O
to	O
historic	O
choices	O
made	O
during	O
the	O
file	B-Operating_System
format	O
development	O
,	O
the	O
number	O
of	O
constants	O
in	O
the	O
constant	O
pool	O
table	O
is	O
not	O
actually	O
the	O
same	O
as	O
the	O
constant	O
pool	O
count	O
which	O
precedes	O
the	O
table	O
.	O
</s>
<s>
The	O
type	O
of	O
each	O
item	O
(	O
constant	O
)	O
in	O
the	O
constant	O
pool	O
is	O
identified	O
by	O
an	O
initial	O
byte	B-Application
tag	O
.	O
</s>
<s>
The	O
number	O
of	O
bytes	B-Application
following	O
this	O
tag	O
and	O
their	O
interpretation	O
are	O
then	O
dependent	O
upon	O
the	O
tag	O
value	O
.	O
</s>
<s>
Tag	O
byte	B-Application
Additional	O
bytes	B-Application
Description	O
of	O
constant	O
Version	O
introduced	O
1	O
2+x	O
bytes(variable )	O
UTF-8	O
(	O
Unicode	O
)	O
string	O
:	O
a	O
character	O
string	O
prefixed	O
by	O
a	O
16-bit	B-Device
number	O
(	O
type	O
u2	O
)	O
indicating	O
the	O
number	O
of	O
bytes	B-Application
in	O
the	O
encoded	O
string	O
which	O
immediately	O
follows	O
(	O
which	O
may	O
be	O
different	O
than	O
the	O
number	O
of	O
characters	O
)	O
.	O
</s>
<s>
1.0.2	O
3	O
4	O
bytes	B-Application
Integer	O
:	O
a	O
signed	O
32-bit	O
two	B-General_Concept
's	I-General_Concept
complement	I-General_Concept
number	O
in	O
big-endian	O
format	O
1.0.2	O
4	O
4	O
bytes	B-Application
Float	O
:	O
a	O
32-bit	O
single-precision	O
IEEE	O
754	O
floating-point	O
number	O
1.0.2	O
5	O
8	O
bytes	B-Application
Long	O
:	O
a	O
signed	O
64-bit	O
two	B-General_Concept
's	I-General_Concept
complement	I-General_Concept
number	O
in	O
big-endian	O
format	O
(	O
takes	O
two	O
slots	O
in	O
the	O
constant	O
pool	O
table	O
)	O
1.0.2	O
6	O
8	O
bytes	B-Application
Double	O
:	O
a	O
64-bit	O
double-precision	O
IEEE	O
754	O
floating-point	O
number	O
(	O
takes	O
two	O
slots	O
in	O
the	O
constant	O
pool	O
table	O
)	O
1.0.2	O
7	O
2	O
bytes	B-Application
Class	O
reference	O
:	O
an	O
index	O
within	O
the	O
constant	O
pool	O
to	O
a	O
UTF-8	O
string	O
containing	O
the	O
fully	O
qualified	O
class	O
name	O
(	O
in	O
internal	O
format	O
)	O
(	O
big-endian	O
)	O
1.0.2	O
8	O
2	O
bytes	B-Application
String	O
reference	O
:	O
an	O
index	O
within	O
the	O
constant	O
pool	O
to	O
a	O
UTF-8	O
string	O
(	O
big-endian	O
too	O
)	O
1.0.2	O
9	O
4	O
bytes	B-Application
Field	O
reference	O
:	O
two	O
indexes	O
within	O
the	O
constant	O
pool	O
,	O
the	O
first	O
pointing	O
to	O
a	O
Class	O
reference	O
,	O
the	O
second	O
to	O
a	O
Name	O
and	O
Type	O
descriptor	O
.	O
</s>
<s>
(	O
big-endian	O
)	O
1.0.2	O
10	O
4	O
bytes	B-Application
Method	B-Language
reference	O
:	O
two	O
indexes	O
within	O
the	O
constant	O
pool	O
,	O
the	O
first	O
pointing	O
to	O
a	O
Class	O
reference	O
,	O
the	O
second	O
to	O
a	O
Name	O
and	O
Type	O
descriptor	O
.	O
</s>
<s>
(	O
big-endian	O
)	O
1.0.2	O
11	O
4	O
bytes	B-Application
Interface	O
method	B-Language
reference	O
:	O
two	O
indexes	O
within	O
the	O
constant	O
pool	O
,	O
the	O
first	O
pointing	O
to	O
a	O
Class	O
reference	O
,	O
the	O
second	O
to	O
a	O
Name	O
and	O
Type	O
descriptor	O
.	O
</s>
<s>
(	O
big-endian	O
)	O
1.0.2	O
12	O
4	O
bytes	B-Application
Name	O
and	O
type	O
descriptor	O
:	O
two	O
indexes	O
to	O
UTF-8	O
strings	O
within	O
the	O
constant	O
pool	O
,	O
the	O
first	O
representing	O
a	O
name	O
(	O
identifier	O
)	O
and	O
the	O
second	O
a	O
specially	O
encoded	O
type	O
descriptor	O
.	O
</s>
<s>
1.0.2	O
15	O
3	O
bytes	B-Application
Method	B-Language
handle	O
:	O
this	O
structure	O
is	O
used	O
to	O
represent	O
a	O
method	B-Language
handle	O
and	O
consists	O
of	O
one	O
byte	B-Application
of	O
type	O
descriptor	O
,	O
followed	O
by	O
an	O
index	O
within	O
the	O
constant	O
pool	O
.	O
</s>
<s>
7	O
16	O
2	O
bytes	B-Application
Method	B-Language
type	O
:	O
this	O
structure	O
is	O
used	O
to	O
represent	O
a	O
method	B-Language
type	O
,	O
and	O
consists	O
of	O
an	O
index	O
within	O
the	O
constant	O
pool	O
.	O
</s>
<s>
7	O
17	O
4	O
bytes	B-Application
Dynamic	O
:	O
this	O
is	O
used	O
to	O
specify	O
a	O
dynamically	O
computed	O
constant	O
produced	O
by	O
invocation	O
of	O
a	O
bootstrap	O
method	B-Language
.	O
</s>
<s>
11	O
18	O
4	O
bytes	B-Application
InvokeDynamic	O
:	O
this	O
is	O
used	O
by	O
an	O
invokedynamic	O
instruction	O
to	O
specify	O
a	O
bootstrap	O
method	B-Language
,	O
the	O
dynamic	O
invocation	O
name	O
,	O
the	O
argument	O
and	O
return	O
types	O
of	O
the	O
call	O
,	O
and	O
optionally	O
,	O
a	O
sequence	O
of	O
additional	O
constants	O
called	O
static	O
arguments	O
to	O
the	O
bootstrap	O
method	B-Language
.	O
</s>
<s>
7	O
19	O
2	O
bytes	B-Application
Module	O
:	O
this	O
is	O
used	O
to	O
identify	O
a	O
module	O
.	O
</s>
<s>
9	O
20	O
2	O
bytes	B-Application
Package	O
:	O
this	O
is	O
used	O
to	O
identify	O
a	O
package	O
exported	O
or	O
opened	O
by	O
a	O
module	O
.	O
</s>
<s>
Other	O
integral	O
types	O
appearing	O
in	O
the	O
high-level	O
language	O
,	O
such	O
as	O
boolean	O
,	O
byte	B-Application
,	O
and	O
short	O
must	O
be	O
represented	O
as	O
an	O
integer	O
constant	O
.	O
</s>
<s>
Class	O
names	O
in	O
Java	B-Language
,	O
when	O
fully	O
qualified	O
,	O
are	O
traditionally	O
dot-separated	O
,	O
such	O
as	O
"	O
java.lang.Object	O
"	O
.	O
</s>
<s>
However	O
within	O
the	O
low-level	O
Class	O
reference	O
constants	O
,	O
an	O
internal	O
form	O
appears	O
which	O
uses	O
slashes	O
instead	O
,	O
such	O
as	O
"	O
java/lang/Object	O
"	O
.	O
</s>
<s>
The	O
first	O
is	O
that	O
the	O
code	O
point	O
U+0000	O
is	O
encoded	O
as	O
the	O
two-byte	O
sequence	O
C0	O
80	O
(	O
in	O
hex	O
)	O
instead	O
of	O
the	O
standard	O
single-byte	O
encoding	O
00	O
.	O
</s>
<s>
For	O
example	O
,	O
U+1D11E	O
is	O
encoded	O
as	O
the	O
6-byte	O
sequence	O
ED	O
A0	O
B4	O
ED	O
B4	O
9E	O
,	O
rather	O
than	O
the	O
correct	O
4-byte	O
UTF-8	O
encoding	O
of	O
F0	O
9D	O
84	O
9E	O
.	O
</s>
