Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

integer

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

like image 252
GaryX Avatar asked Oct 21 '11 10:10

GaryX


People also ask

What is the difference between 32-bit and 64-bit JVM?

In a 64-bit JVM, you can specify more memory for heap size than in a 32-bit JVM; for example, in a 32-bit JVM, the theoretical maximum memory limit is 4GB, whereas 64-bit is much higher.

Should I use 32 or 64-bit Java?

Java with 64 and/or 32 bit web browsersUsers that run Applets and Web Start applications through web browsers should choose the version of Java that matches their web browser. Generally speaking, 64 bit browsers run only 64 bit plugins and 32 bit browsers run only 32 bit plugins.

What is the value of integer MAX_VALUE?

MAX_VALUE is a number in the Java Integer сlass of java. lang package. It is the maximum possible Integer number that can be represented in 32 bits. Its exact value is 2147483647 i.e. 231-1.


3 Answers

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

Integer.MAX_VALUE

like image 65
John B Avatar answered Oct 19 '22 19:10

John B


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

like image 24
Konstantin Yovkov Avatar answered Oct 19 '22 19:10

Konstantin Yovkov


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.

like image 41
Luke Woodward Avatar answered Oct 19 '22 21:10

Luke Woodward