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

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

+62
java
Dec 30 '09 at 15:02
source share
7 answers

32 bits. This is one of the features of the Java language that the size of the integer is independent of the host computer. See the relevant section of the specification .

+82
Dec 30 '09 at 15:04
source share

The size of the primitive data is part of the specification of the virtual machine and does not change. Which will change the size of object references, from 32 bits to 64. Thus, the same program will require more memory on a 64-bit JVM. The effect of this depends on your application, but can be significant.

+22
Dec 30 '09 at 20:24
source share

If you need a 64-bit integer, use a long one.

+9
Dec 30 '09 at 15:08
source share

32 bits. Java should work the same regardless of which computer or OS it is running on, and of course this is true for primitive data types, at least.

+4
Dec 30 '09 at 15:05
source share

This is one of the consequences of the โ€œcompile once, run anywhereโ€ slogan: Java execution does not depend on the base size and final size of the hardware; JVM works the same everywhere.

This guarantee of independence works much better than trying to distract the OS; -)

+2
Dec 30 '09 at 18:00
source share

Yup, it's 32 bits

0
Dec 30 '09 at 15:06
source share

Another point that is usually misunderstood is the fact that the size of these data types will always be the same regardless of whether our program works. Thus, you can program on a 64-bit machine, but int will always be 32 bits so that it will have the same range. This is true for both C # and Java.

Here is the full article on this subject:

Integrated data types in Java and C #.

0
Aug 08 2018-12-12T00:
source share



All Articles