As I understand the difference between two integer from 32bit & 64bit are the following: 32bit range −2,147,483,648 to 2,147,483,647 64bit range: −9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
I am using a 64bit jdk, I validate it by printing the following: System.out.println("JVM Bit size: " + System.getProperty("sun.arch.data.model"));
JVM Bit size: 64
when I try to init a new Integer variable with number bigger ther 10 letters I get a compilation error. why is that? it looks like the 64bit is larger
example (ran on netbeans): int x = 12345678910; => Error: integer is too large
Unlike other languages, Java's numeric primitive types are always the same size, whatever the platform (32bit or 64bit, LE or BE); they are all big endian and are 1 byte long for byte
, 2 bytes long for short
and char
, 4 bytes long for int
and 8 bytes long for long
.
If it were not the case, jars would not be portable across platforms...
The size of an int
in Java is completely independent of the 32-bitness or 64-bitness of a JDK. It is always 4 bytes = 32 bits = −2,147,483,648 to 2,147,483,647.
If you want a 64-bit integer, use a long
, which is always 64 bits = 8 bytes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With