The constant pool is used in java to save a copy of data in the compiled class file that has been determined during the compilation period. It includes constants in classes, methods, and interfaces, as well as String constants, such as String
S = "java. The constant pool is a block in the heap memory.
In addition to the constant values of various basic types (such as int and long) and object types (such as String and array) defined in the Code, it also contains some symbolic references that appear in the form of text, such as fully qualified names of classes and interfaces, field names and descriptors, methods and names, and descriptors. The class file has
11 constant table types:
| Constant table Type |
Flag value (1 byte) |
Description |
| CONSTANT_Utf8 |
1 |
Unicode string encoded by UTF-8 |
| CONSTANT_Integer |
3 |
Int-type Literal Value |
| CONSTANT_Float |
4 |
Float-type Literal Value |
| CONSTANT_Long |
5 |
Long Literal Value |
| CONSTANT_Double |
6 |
Double Literal Value |
| CONSTANT_Class |
7 |
Symbol reference for a class or interface |
| CONSTANT_String |
8 |
Reference of String-type Literal Value |
| CONSTANT_Fieldref |
9 |
Symbol reference for a field |
| CONSTANT_Methodref |
10 |
Symbol reference for methods in a class |
| CONSTANT_InterfaceMethodref |
11 |
Symbol reference of a method in an Interface |
| CONSTANT_NameAndType |
12 |
References part of a field or Method |
Eight basic types of packaging classes and object poolsIn java, most of the basic packaging classes implement the constant pool technology. These classes are Byte, Short, Integer, Long, Character, Boolean, the other two floating-point type packaging classes are not implemented. In addition, the object pool can be used only when the corresponding value is less than or equal to 127 for the five Integer packaging classes Byte, Short, Integer, Long, and Character. Reference: Baidu Baike-constant pool-http://baike.baidu.com/view/8680346.htm