Java class file: Difference between revisions

Content deleted Content added
 
(One intermediate revision by one other user not shown)
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 232:
|}
 
===Representation inof a C-likeclass programming languagefile===
The following is a representation of a {{mono|.class}} file as if it were a C-style struct.
Since [[C (programming language)|C]] does not support multiple variable length arrays within a struct, the code below won't compile and only serves as a demonstration.
<syntaxhighlight lang="ccpp">
struct Class_File_FormatClassFileFormat {
u4 magic_numbermagicNumber;
 
u2 minor_versionminorVersion;
u2 major_versionmajorVersion;
 
u2 constant_pool_countconstantPoolCount;
ConstantPoolInfo[constantPoolCount - 1] constantPool;
cp_info constant_pool[constant_pool_count - 1];
 
u2 access_flagsaccessFlags;
 
u2 this_classthisClass;
u2 super_classsuperClass;
 
u2 interfaces_countinterfacesCount;
u2[interfacesCount] interfaces;
u2 interfaces[interfaces_count];
 
u2 fields_countfieldsCount;
FieldInfo[fieldsCount] fields;
field_info fields[fields_count];
 
u2 methods_countmethodsCount;
MethodInfo[methodsCount] methods;
method_info methods[methods_count];
 
u2 attributes_countattributesCount;
AttributeInfo[attributesCount] attributes;
attribute_info attributes[attributes_count];
}
</syntaxhighlight>