简体   繁体   中英

Is there difference for Integer.MAX_VALUE between 32bit JVM and 64bit JVM?

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) .

No. By definition Integer.MAX_VAlUE = 2^31 - 1

Integer.MAX_VALUE

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. :)

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, 2 31 -1.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM