The file structure of Java class

Source: Internet
Author: User

The class file is comprised of 8bits byte streams, all of which make up 15 meaningful items. There are no meaningless bytes between these items, so the class file is very compact. Here's a look at the contents of the class file, specific meanings:
1.magic (magic number):
Magic Number is the beginning of the class file 4 bytes, the value of 0xCAFEBABE, the main purpose is to determine whether a file is a class file.
2.minor_version, major_version (minor, major version number)
Each account is 2 bytes. with the development of Java technology, the format of the class file will be changed. The role of the version number is to enable the virtual machine to recognize the file format of the currently loaded class. To extract the class file information accurately.
3.constant_pool_count, Constance_pool (Chang)
a constant pool stores content such as symbolic constants, final constant values, literals of basic data types, and so on. the JVM makes each constant a constant table with its own entry address for each constant table. where constant_pool_count records How many constant tables there are. Constant pool composition see the table at the end of the article.
4.access_flags (Access flag)
used to indicate whether a class or an interface is defined in the class file, and whether the access modifier is public or default. Whether the class or interface is abstract. Whether the class is final.
5.this_class
occupies 2 bytes. It is an index to a constant pool. Refers to a constant pool in which the class name symbol is stored .
6.super_class
occupies 2 bytes. that refers to the index of the superclass name that holds the class defined by the current class file.
7.Inteface_count, interfaces
Interface_count is the number of interfaces that are implemented directly by the classes defined by the class file or by the parent class. accounts for 2 bytes. Intefaces contains the index of the Constant_class_info constant table for each interface.
8.fields_count, fields
Fields_count Indicates the number of fields in the class . Fields are sequences of field_info tables of different lengths. These field_info tables do not contain fields that are inherited by superclass or parent interfaces. The Field_info table shows information about a field, including the name of the field, the descriptor, and the modifier. If the field is final, it will also show its constant value. Note that some of this information is stored in Field_info, while others are stored in the constant pool pointed to by Field_info.
9.Method_count, Methods
Method_count indicates the number of methods in the class and the index of the constant table for each method.


constant Pool composition:
A constant pool consists of a constant table of 11 constant tables for class files:

Constant table Type Flag value (1 byte) Describe
Constant_utf8 1 UTF-8 encoded Unicode string
Constant_integer 3 literal literals of type int
Constant_float 4 Literal value of float type
Constant_long 5 Literal literals of type long
Constant_double 6 Literal literals of double type
Constant_class 7 A symbolic reference to a class or an interface
Constant_string 8 Reference to String type literals
Constant_fieldref 9 A symbolic reference to a field
Constant_methodref 10 A symbolic reference to a method in a class
Constant_interfacemethodref 11 A symbolic reference to a method in an access port
Constant_nameandtype 12 A partial symbol reference to a field or method

The file structure of Java class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.