GaryX
GaryX

Reputation: 737

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

Upvotes: 12

Views: 8371

Answers (5)

saurav
saurav

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

Wojciech Owczarczyk
Wojciech Owczarczyk

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

Luke Woodward
Luke Woodward

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

John B
John B

Reputation: 32969

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

Integer.MAX_VALUE

Upvotes: 14

Konstantin Yovkov
Konstantin Yovkov

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

Related Questions