|
|
|
Advertisement
|
Primitive types
The JVM supports seven primitive data types.
Java programmers can declare and use variables of these data types, and
Java bytecodes operate upon these data types. The seven primitive types
are listed in the following table:
| Type | Definition |
|---|---|
byte |
one-byte signed two's complement integer |
short |
two-byte signed two's complement integer |
int |
4-byte signed two's complement integer |
long |
8-byte signed two's complement integer |
float |
4-byte IEEE 754 single-precision float |
double |
8-byte IEEE 754 double-precision float |
char |
2-byte unsigned Unicode character |
The primitive types appear as operands in bytecode streams. All primitive
types that occupy more than 1 byte are stored in big-endian order in
the bytecode stream, which means higher-order bytes precede lower-order
bytes. For example, to push the constant value 256 (hex 0100) onto the
stack, you would use the sipush opcode followed by a short operand. The
short appears in the bytecode stream, shown below, as "01 00"
because the JVM is big-endian. If the JVM were little-endian, the short
would appear as "00 01".
// Bytecode stream: 17 01 00
// Dissassembly:
sipush 256; // 17 01 00
Java opcodes generally indicate the type of their operands. This allows
operands to just be themselves, with no need to identify their type to
the JVM. For example, instead of having one opcode that pushes a local
variable onto the stack, the JVM has several. Opcodes iload,
lload,
fload, and dload push local variables of type int, long,
float, and double, respectively, onto the stack.
|
Sponsored Links
|