12

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

bartektartanus
  • 15,284
  • 6
  • 74
  • 102
GaryX
  • 737
  • 1
  • 5
  • 20

5 Answers5

14

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

Integer.MAX_VALUE

John B
  • 32,493
  • 6
  • 77
  • 98
  • It goes further than that: the *compilation* platform makes **no difference at all**: the output will be the same. In an ideal world even the *runtime* platform would make no difference, but there might be minor differences here. – Joachim Sauer Oct 21 '11 at 13:07
5

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

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
  • 1
    Note that a 64bit JVM *can* use 32 bit references. See [CompressedOops](http://wikis.sun.com/display/HotSpotInternals/CompressedOops) for details. – Joachim Sauer Oct 21 '11 at 10:25
1

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.

Luke Woodward
  • 63,336
  • 16
  • 89
  • 104
0

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.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
saurav
  • 3,424
  • 1
  • 22
  • 33
0

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.

Community
  • 1
  • 1
Wojciech Owczarczyk
  • 5,595
  • 2
  • 33
  • 55
  • thank you for your extra information. just wondering in what situation do we need to reference check on (Integer == Integer)? Shouldn't we all always just need the value check? So why doesn't someone overload the operator '==' on Integer? – GaryX Oct 24 '11 at 02:40