tags:

views:

1574

answers:

6

On a 64-bit machine is the size of an int in Java 32 bits or 64 bits?

+25  A: 

32 bits. It's one of the Java language features that the size of the integer does not vary with the underlying computer. See the relevant section of the spec.

Thomas Jones-Low
+3  A: 

32 bits. Java is meant to be run the same regardless of the machine or OS it is run on, and at certainly this is true for primitive data types, at the very least.

Phil
+1  A: 

Yup, it's 32 bits

Chad Okere
+4  A: 

If you want a 64-bit integer, use a long.

R. Bemrose
+2  A: 

That's one of the consequences of the "compile once, run anywhere" slogan: Java execution is independent of underlying hardware word-size and endian-ness; the JVM works everywhere the same way.

This independence guarantee works a lot better than the attempt to abstract the OS away ;-)

mfx
+1  A: 

The size of primitive data is part of the virtual machine specification, and doesn't change. What will change is the size of object references, from 32 bits to 64. So, the same program will require more memory on a 64 bit JVM. The impact this has depends on your application, but can be significant.

erickson