In java, is an int guaranteed to always be of 32bit size and a long of 64bit size regardless of whether the architecture is 32 or 64 bit?
Asker knows that int is 32 bit and long is 64 bit. – David Heffernan Mar 12, 2014 at 22:57 Add a comment | 4 Answers 4 ActiveOldestVotes 29 Don't you worry about that. The longvalue will be stored in 2 memory addresses. Int64/longwill always be 64bit, and Int32/intwill always be 32bit.
If a plain int is adjusted to 64 bits, the constraint that sizeof (int) <= sizeof (long) would force long to be at least 64 bits and from there there's an intrinsic gap in sizes. Since long or a plain int usually are used as a 32 bit integer and neither of them could now, we only have one more data type that could, short.
A 32-bit system can access 2 32 different memory addresses, i.e 4 GB of RAM or physical memory ideally, it can access more than 4 GB of RAM also. A 64-bit system can access 2 64 different memory addresses, i.e actually 18-Quintillion bytes of RAM. In short, any amount of memory greater than 4 GB can be easily handled by it.
d 32-bit microcomputers define "char" as 8 bits, "short" as 16 bits, and "long" as 32 bits. The only difference among them is whether "int" is 16 bits or 32. While a 32-bit or larger CPU could use "int" as a 32-bit type, leaving "long" available as a 64-bit type, there is a substantial corpus of code which expects that "long" will be 32 bits.
Java is platform independent. So int
is 32-bits, and long
is 64-bit.
int
in Java is always 32-bit. No matter the OS type/architecture/whatever.
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