Content deleted Content added
→Representation in a C-like programming language: use more Java-like layout |
|||
(10 intermediate revisions by 10 users not shown) | |||
Line 23:
}}
A '''Java class file''' is a [[Computer file|file]] (with the {{mono|.class}} [[filename extension]]) containing [[Java bytecode]] that can be executed on the [[Java virtual machine|Java Virtual Machine (JVM)]]. A Java class file is usually produced by a [[Java compiler]] from [[Java (programming language)|Java programming language]] [[source file]]s ({{mono|.java}} files) containing Java [[Class (programming)|classes]] (alternatively, other [[JVM languages]] can also be used to create class files). If a source file has more than one class, each class is compiled into a separate class file. Thus, it is called a {{mono|.class}} file because it contains the bytecode for a single class.
JVMs are available for many [[platform (computing)|platform]]s, and a class file compiled on one platform will execute on a JVM of another platform. This makes Java applications [[cross-platform|platform-independent]].
Line 34:
===Sections===
There are 10 basic sections to the Java class file structure:
* '''[[Magic number (programming)|Magic Number]]''': <code>0xCAFEBABE</code>
* '''Version of Class File Format''': the minor and major versions of the class file
* '''Constant Pool''': Pool of constants for the class
Line 95:
| 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/
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 />
Line 229 ⟶ 232:
|}
===Representation
The following is a representation of a {{mono|.class}} file as if it were a C-style struct.
<syntaxhighlight lang="
struct
u4
u2
u2
u2
ConstantPoolInfo[constantPoolCount - 1] constantPool;
u2
u2
u2
u2
u2[interfacesCount] interfaces;
u2
FieldInfo[fieldsCount] fields;
u2
MethodInfo[methodsCount] methods;
u2
AttributeInfo[attributesCount] attributes;
}
</syntaxhighlight>
|