Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Java class file
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===General layout=== Because the class file contains variable-sized items and does not also contain embedded file offsets (or pointers), it is typically parsed sequentially, from the first byte toward the end. At the lowest level the file format is described in terms of a few fundamental data types: * '''u1''': an unsigned [[octet (computing)|8-bit]] integer * '''u2''': an unsigned [[16-bit]] integer in [[Endianness|big-endian]] byte order * '''u4''': an unsigned [[32-bit]] integer in big-endian byte order * '''table''': an array of variable-length items of some type. The number of items in the table is identified by a preceding count number (the count is a u2), but the size in bytes of the table can only be determined by examining each of its items. Some of these fundamental types are then re-interpreted as higher-level values (such as strings or floating-point numbers), depending on context. There is no enforcement of word alignment, and so no padding bytes are ever used. The overall layout of the class file is as shown in the following table. {| class="wikitable" |- ! Byte offset ! Size ! Type or value ! Description |- | 0 | rowspan="4" | 4 bytes | u1 =<br />0xCA hex | rowspan="4" | [[magic number (programming)|magic number]] (CAFEBABE) used to identify file as conforming to the class file format |- | 1 | u1 =<br />0xFE hex |- | 2 | u1 =<br />0xBA hex |- | 3 | u1 =<br />0xBE hex |- | 4 | rowspan="2" | 2 bytes | rowspan="2" | u2 | rowspan="2" | minor version number of the class file format being used |- | 5 |- | 6 | rowspan="2" | 2 bytes | rowspan="2" | u2 | rowspan="2" | major version number of the class file format being used.<ref>{{Cite web|url=https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-4.html#jvms-4.1-200-B.2|title = Table 4.1-A. class file format major versions}}</ref><br /> Java SE 25 = 69 (0x45 hex),<br /> Java SE 24 = 68 (0x44 hex),<br /> Java SE 23 = 67 (0x43 hex),<br /> Java SE 22 = 66 (0x42 hex),<br /> Java SE 21 = 65 (0x41 hex),<br /> Java SE 20 = 64 (0x40 hex),<br /> Java SE 19 = 63 (0x3F hex),<br /> Java SE 18 = 62 (0x3E hex),<br /> Java SE 17 = 61 (0x3D hex),<br /> Java SE 16 = 60 (0x3C hex),<br /> Java SE 15 = 59 (0x3B hex),<br /> Java SE 14 = 58 (0x3A hex),<br /> Java SE 13 = 57 (0x39 hex),<br /> Java SE 12 = 56 (0x38 hex),<br /> Java SE 11 = 55 (0x37 hex),<br /> Java SE 10 = 54 (0x36 hex),<ref>{{cite web |url=http://www.oracle.com/technetwork/java/javase/10-relnote-issues-4108729.html#Remaining |title = JDK 10 Release Notes}}</ref><br /> Java SE 9 = 53 (0x35 hex),<ref>{{cite web |url=https://bugs.openjdk.java.net/browse/JDK-8148785 |title = [JDK-8148785] Update class file version to 53 for JDK-9 - Java Bug System}}</ref><br /> Java SE 8 = 52 (0x34 hex),<br />Java SE 7 = 51 (0x33 hex),<br />Java SE 6.0 = 50 (0x32 hex),<br />Java SE 5.0 = 49 (0x31 hex),<br />JDK 1.4 = 48 (0x30 hex),<br />JDK 1.3 = 47 (0x2F hex),<br />JDK 1.2 = 46 (0x2E hex),<br />JDK 1.1 = 45 (0x2D hex).<br />For details of earlier version numbers see footnote 1 at [https://docs.oracle.com/javase/specs/jvms/se6/html/ClassFile.doc.html The JavaTM Virtual Machine Specification 2nd edition] |- | 7 |- | 8 | rowspan="2" | 2 bytes | rowspan="2" | u2 | rowspan="2" | constant pool count, number of entries in the following constant pool table. This count is at least one greater than the actual number of entries; see following discussion. |- | 9 |- | 10 | rowspan="4" | ''cpsize'' (variable) | rowspan="4" | table | rowspan="4" | constant pool table, an array of variable-sized constant pool entries, containing items such as literal numbers, strings, and references to classes or methods. Indexed starting at 1, containing (''constant pool count'' - 1) number of entries in total (see note). |- | ... |- | ... |- | ... |- | 10+''cpsize'' | rowspan="2" | 2 bytes | rowspan="2" | u2 | rowspan="2" | access flags, a bitmask |- | 11+''cpsize'' |- | 12+''cpsize'' | rowspan="2" | 2 bytes | rowspan="2" | u2 | rowspan="2" | identifies ''this'' class, index into the constant pool to a "Class"-type entry |- | 13+''cpsize'' |- | 14+''cpsize'' | rowspan="2" | 2 bytes | rowspan="2" | u2 | rowspan="2" | identifies ''super'' class, index into the constant pool to a "Class"-type entry |- | 15+''cpsize'' |- | 16+''cpsize'' | rowspan="2" | 2 bytes | rowspan="2" | u2 | rowspan="2" | interface count, number of entries in the following interface table |- | 17+''cpsize'' |- | 18+''cpsize'' | rowspan="4" | ''isize'' (variable) | rowspan="4" | table | rowspan="4" | interface table: a variable-length array of constant pool indexes describing the interfaces implemented by this class |- | ... |- | ... |- | ... |- | 18+''cpsize''+''isize'' | rowspan="2" | 2 bytes | rowspan="2" | u2 | rowspan="2" | field count, number of entries in the following field table |- | 19+''cpsize''+''isize'' |- | 20+''cpsize''+''isize'' | rowspan="4" | ''fsize'' (variable) | rowspan="4" | table | rowspan="4" | field table, variable length array of fields each element is a field_info structure defined in https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.5 |- | ... |- | ... |- | ... |- | 20+''cpsize''+''isize''+''fsize'' | rowspan="2" | 2 bytes | rowspan="2" | u2 | rowspan="2" | method count, number of entries in the following method table |- | 21+''cpsize''+''isize''+''fsize'' |- | 22+''cpsize''+''isize''+''fsize'' | rowspan="4" | ''msize'' (variable) | rowspan="4" | table | rowspan="4" | method table, variable length array of methods each element is a method_info structure defined in https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.6 |- | ... |- | ... |- | ... |- | 22+''cpsize''+''isize''+''fsize''+''msize'' | rowspan="2" | 2 bytes | rowspan="2" | u2 | rowspan="2" | attribute count, number of entries in the following attribute table |- | 23+''cpsize''+''isize''+''fsize''+''msize'' |- | 24+''cpsize''+''isize''+''fsize''+''msize'' | rowspan="4" | ''asize'' (variable) | rowspan="4" | table | rowspan="4" | attribute table, variable length array of attributes each element is an attribute_info structure defined in https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7 |- | ... |- | ... |- | ... |}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)