For any comparison operation, JVM looks for data type of the operands. Depending on the operand type different Java byte code instructions are used for comparison.
JVM works on two kinds of data types.
According to JVM 7 specification:
Like the Java programming language, the Java Virtual Machine operates
on two kinds of types: primitive types and reference types. There are,
correspondingly, two kinds of values that can be stored in variables,
passed as arguments, returned by methods, and operated upon: primitive
values and reference values.
References too are values of type reference
.
The Java Virtual Machine contains explicit support for objects. An
object is either a dynamically allocated class instance or an array. A
reference to an object is considered to have Java Virtual Machine type
reference. Values of type reference can be thought of as pointers to
objects. More than one reference to an object may exist. Objects are
always operated on, passed, and tested via values of type reference.
For arithmetic operations on primitive and reference types, JVM uses opcodes which specify data type of the arguments along with operation.
For example,
lcmp
- Compare two long values
Finally, for JVM any arithmetic operation is byte arithmetic on given operands.