Is long always 64 bit in both 32 and 64 bit machine

Yes. A Java long is 64 bits on any JVM, without exception. All the Java primitive types are completely portable and have fixed sizes across all implementations.


The primitive types are always the same size. Only references can change in size, but you generally don't need to know this.

You can get the size of a reference with

int addressSize = Unsafe.addressSize();

Note: Even in a 64-bit JVM (on the latest Java 6+ JVMs), references are 32-bit but unless you use a 32 GB heap or larger. This is the default on the OpenJDK/Sun/Oracle JDK, however as @user988052 notes, the IBM JVM needs the appropriate flag to be set on the command line. Other JVMs might not support this option at all.


Yes. A long is known as a 64-bit Integer.

Tags:

Java