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

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


Solution 1:

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.

Solution 2:

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.

Solution 3:

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

Solution 4:

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.