Data and value types
The JVM specification considers two data types and associated value types:
- Primitive types are stored on the stack.
- Reference types are stored on the heap and references are stored in the stack.
The JVM assumes that type checking has taken place in the compiler and does not need to be performed at run-time. The JVM instruction set differentiates between operand types using instructions specific to their types.
Primitive
Primitive types are either numeric, boolean
, or returnAddress
.
Numeric
Integral:
byte
( to )short
( to )int
( to )long
( to )char
(0 to )
Floating-point:
float
(IEEE 754 binary32)double
(IEEE 754 binary64)
Not-a-Number values are represented as either Float.NaN
or Double.NaN
.
boolean
Stores values true
and false
, introduced in the second edition. No instructions dedicated to boolean values, and instead are treated internally as int
s. Boolean arrays can be created with newarray
and modified using the byte array instructions baload
and bastore
.
returnAddress
pointers to opcodes of JVM instructions; doesn't correspond to a Java programming language type and isn't modifiable by the running program.
Used by the jsr
, ret
, and jsr_w
instructions.
Reference
Reference types are class, array, and interface types.
class
Class types are created with the new
instruction.
interface
Interface methods are invoked using the invokeinterface
instruction.
array
Comprises:
- Component, which may itself be another array type, but eventually must be a non-array (primitive, class or interface) type known as the element type.
- Dimension (depth)
null
A reference to no object. Has no run-time type, but may be cast to any type.