Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Java class file
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===The constant pool=== The constant pool table is where most of the literal constant values are stored. This includes values such as numbers of all sorts, strings, identifier names, references to classes and methods, and type descriptors. All indexes, or references, to specific constants in the constant pool table are given by 16-bit (type u2) numbers, where index value 1 refers to the first constant in the table (index value 0 is invalid). Due to historic choices made during the file format development, the number of constants in the constant pool table is not actually the same as the constant pool count which precedes the table. First, the table is indexed starting at 1 (rather than 0), but the count should actually be interpreted as the maximum index plus one.<ref name="jvms-4.4">{{Cite web|url=https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-4.html#jvms-4.4|title=Chapter 4. The class File Format}}</ref> Additionally, two types of constants (longs and doubles) take up two consecutive slots in the table, although the second such slot is a phantom index that is never directly used. The type of each item (constant) in the constant pool is identified by an initial byte ''tag''. The number of bytes following this tag and their interpretation are then dependent upon the tag value. The valid constant types and their tag values are: {| class="wikitable" |- ! Tag byte ! Additional bytes ! Description of constant ! Version introduced |- | 1 | 2+''x'' bytes<br />(variable) | UTF-8 (Unicode) string: a character string prefixed by a 16-bit number (type u2) indicating the number of bytes in the encoded string which immediately follows (which may be different than the number of characters). Note that the encoding used is not actually [[UTF-8]], but involves a slight modification of the Unicode standard encoding form. | 1.0.2 |- | 3 | 4 bytes | Integer: a signed 32-bit [[two's complement]] number in big-endian format | 1.0.2 |- | 4 | 4 bytes | Float: a 32-bit single-precision [[IEEE 754]] floating-point number | 1.0.2 |- | 5 | 8 bytes | Long: a signed 64-bit two's complement number in big-endian format (takes two slots in the constant pool table) | 1.0.2 |- | 6 | 8 bytes | Double: a 64-bit double-precision IEEE 754 floating-point number (takes two slots in the constant pool table) | 1.0.2 |- | 7 | 2 bytes | Class reference: an index within the constant pool to a UTF-8 string containing the fully qualified class name (in ''internal format'') (big-endian) | 1.0.2 |- | 8 | 2 bytes | String reference: an index within the constant pool to a UTF-8 string (big-endian too) | 1.0.2 |- | 9 | 4 bytes | Field reference: two indexes within the constant pool, the first pointing to a Class reference, the second to a Name and Type descriptor. (big-endian) | 1.0.2 |- | 10 | 4 bytes | Method reference: two indexes within the constant pool, the first pointing to a Class reference, the second to a Name and Type descriptor. (big-endian) | 1.0.2 |- | 11 | 4 bytes | Interface method reference: two indexes within the constant pool, the first pointing to a Class reference, the second to a Name and Type descriptor. (big-endian) | 1.0.2 |- | 12 | 4 bytes | Name and type descriptor: two indexes to UTF-8 strings within the constant pool, the first representing a name (identifier) and the second a specially encoded type descriptor. | 1.0.2 |- | 15 | 3 bytes | Method handle: this structure is used to represent a method handle and consists of one byte of type descriptor, followed by an index within the constant pool.<ref name="jvms-4.4" /> | 7 |- | 16 | 2 bytes | Method type: this structure is used to represent a method type, and consists of an index within the constant pool.<ref name="jvms-4.4" /> | 7 |- | 17 | 4 bytes | Dynamic: this is used to specify a dynamically computed constant produced by invocation of a bootstrap method.<ref name="jvms-4.4" /> | 11 |- | 18 | 4 bytes | InvokeDynamic: this is used by an ''invokedynamic'' instruction to specify a bootstrap method, the dynamic invocation name, the argument and return types of the call, and optionally, a sequence of additional constants called static arguments to the bootstrap method.<ref name="jvms-4.4" /> | 7 |- | 19 | 2 bytes | Module: this is used to identify a module.<ref name="jvms-4.4" /> | 9 |- | 20 | 2 bytes | Package: this is used to identify a package exported or opened by a module.<ref name="jvms-4.4" /> | 9 |} There are only two integral constant types, integer and long. Other integral types appearing in the high-level language, such as boolean, byte, and short must be represented as an integer constant. Class names in Java, when fully qualified, are traditionally dot-separated, such as "java.lang.Object". However within the low-level Class reference constants, an internal form appears which uses slashes instead, such as "java/lang/Object". The Unicode strings, despite the moniker "UTF-8 string", are not actually encoded according to the Unicode standard, although it is similar. There are two differences (see [[UTF-8]] for a complete discussion). The first is that the code point U+0000 is encoded as the two-byte sequence <code>C0 80</code> (in hex) instead of the standard single-byte encoding <code>00</code>. The second difference is that supplementary characters (those outside the [[Basic Multilingual Plane|BMP]] at U+10000 and above) are encoded using a surrogate-pair construction similar to [[UTF-16]] rather than being directly encoded using UTF-8. In this case each of the two surrogates is encoded separately in UTF-8. For example, U+1D11E is encoded as the 6-byte sequence <code>ED A0 B4 ED B4 9E</code>, rather than the correct 4-byte UTF-8 encoding of <code>F0 9D 84 9E</code>.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)