Reputation: 737
Is the value of Integer.MAX_VALUE
different between 32bit JVMs and 64bit JVMs?
I am compiling a Java class using 32bit JDK and deploy it on a 64bit machine. I just want to make sure that I can rely on detecting if (aNumber == Integer.MAX_VALUE)
.
Upvotes: 12
Views: 8371
Reputation: 3462
what all 32 bit and 64 bit resembles is the number of memory locations they can refer.. in case of 32 bit possible number of address will be 2^32 and in case of 64 bit it is 2^64.
The jvm version has nothing to do with Integer.MAX_VALUE , it will remain same.
Upvotes: 0
Reputation: 5735
You probably want to avoid comparing Integers using =
sign due to:
Comparing Integers (provided aNumber is an object of class java.lang.Integer
)
and no, there is no difference.
Upvotes: 0
Reputation: 64969
This constant has the same value regardless of whether the JVM the code is running on is 32-bit or 64-bit. The documentation for Integer.MAX_VALUE describes this value as:
A constant holding the maximum value an
int
can have, 231-1.
Upvotes: 1
Reputation: 62864
No. The 32-bit JDK makes 32-bit addresses for the instances, and the 64-bit JDK makes 64-bit addresses for the object instances. Thus, Integer.MAX_VALUE is the same, because it's just an value, not an object address. :)
Upvotes: 5