adheres and allow JVMs to verify that the class file is loadable. Every JVM has amaximum version it can load, and JVMs will reject class files with later versions.
The class file stores constants associated with its class or interface in the constant pool.Some constants that may be seen frolicking in the pool are literal strings, final variablevalues, class names, interface names, variable names and types, and method names andsignatures. A method
is its return type and set of argument types.The constant pool is organized as an array of variable-length elements. Each constantoccupies one element in the array. Throughout the class file, constants are referred to bythe integer index that indicates their position in the array. The initial constant has anindex of one, the second constant has an index of two, etc. The constant pool array is preceded by its array size, so JVMs will know how many constants to expect whenloading the class file.Each element of the constant pool starts with a one-byte tag specifying the type of constant at that position in the array. Once a JVM grabs and interprets this tag, it knowswhat follows the tag. For example, if a tag indicates the constant is a string, theJVM expects the next two bytes to be the string length. Following this two-byte length,the JVM expects to find
number of bytes, which make up the characters of thestring.In the remainder of the article I'll sometimes refer to the nth element of the constant poolarray as constant_pool[n]. This makes sense to the extent the constant pool is organizedlike an array, but bear in mind that these elements have different sizes and types and thatthe first element has an index of one.
The first two bytes after the constant pool, the access flags, indicate whether or not thisfile defines a class or an interface, whether the class or interface is public or abstract, and(if it's a class and not an interface) whether the class is final.