Magic number
The first 4 bytes of each class file are called the Magic number, and the value is 0xCAFEBASE, which is used to determine whether the file is a class file that can be accepted by the virtual machine. Identifying with the magic number rather than the extension is primarily based on security considerations because the file extension can be arbitrarily altered.
Version number
followed by the 4 bytes of magic. The version number of the class file is stored: the 5th and 6th bytes are minor versions (Minor version), and the 7th and 8th bytes are the major version numbers (Major versions). The version of Java begins with 45, with each JDK major release major version JDK1.1 1 (jdk1.0-1.1 uses the 45.0-45.3 version number), and a high version of the JDK is backward compatible with previous versions of the class file. However, you cannot run a later version of the class file, even if the file format has not changed. The JDK1.2 corresponds to a major version number of 46,jdk1.3 to 47, and so on.
Constant pool
followed by the primary and secondary version number is the constant pool entry, which is the most associated data type in the class file structure with other items, and is also one of the data items that occupy the largest class file space, and it is the first table type data item that appears in the class file.
Because the data for constants in a constant pool is not fixed, a U2 type of data is required at the inlet of the constant pool, representing the constant pool capacity computed value (Constant_pool_count). Unlike the Java language habit, this capacity count starts at 1 instead of 0. The purpose of the No. 0 constant is to satisfy some of the following data that points to the index value of a constant pool in a particular case that says "do not reference any of the constant pool items." The class file structure has only the capacity count of constant pools starting at 1, for other collection types, including interface index sets, Field table collections, and Method table collections, which are calculated from 0.
There are two main types of constants in a constant pool: literal (Literal) and symbolic references (symbolic References). Literal values are closer to the Java language level of constant concepts, such as text strings, declared as final constants, and so on. Symbolic references, however, include the following three types of constants in the concept of the Principle of attribute compilation:
A. Fully qualified name of class and interface (fully qualified name)
B. Field names and descriptors (descriptor)
C. The name and descriptor of the method
Each constant in a constant pool is a table, there are 11 different structure of the table structure data, these 11 kinds of tables have a common feature, is that the first bit of the table is a U1 type of flag bit, representing the current constant properties of which type of constants, 11 types of constants specific meaning is as follows:
Each constant item structure: