You have taken the quote out of context. The full context is this:
64-bit Java
How is native code affected?
...
When porting 32-bit native code to 64-bit Java platforms, you will need to modify you code to be 64-bit clean. This involves examining your C/C+ + code and looking for code that assumes the size of a pointer to be 4 bytes or that a pointer can be cast and stored in an integer. Long data types are also troublesome when porting 32-bit code. You should avoid the use of longs if at all possible since longs have different sizes on different operating systems even in 64-bit. Windows 64-bit platforms define longs to be 4 bytes but most Unix operating systems specify that longs are 8 bytes in size. For more details, refer to the links below under learning more about 64-bit programming.
To answer your questions:
Java size of long type?
The Java long type is 64 bits on all platforms.
What does this quote mean?
It is self evident, but it is clearly NOT referring the the Java long type. It is referring to the use of the C or C++ long type in native code.
When I want to store value more than ~2^31, how JVM store this value?
In Java code, use long. It works. The JVM implementation takes care of it in different ways on different platforms. Don't worry about it.
In C / C++ native code you have a problem if you want your code to be portable. But the original article provides you with links to help you get your head around the problem.
In calculations, JVM use RAX, or EAX register?
The Java language specification requires that long has a 64 bit (no less, no more) representation, and that all long op long arithmetic is performed with at least 64 bits of precision so that the answer is the same on all platforms.
The actual implementation depends on the platform. The JVM / JIT compiler will (most likely) chose registers and instructions that are most efficient for the current platform.
Bear in mind that the JVM you run on a 32 bit Windows Intel platform is different to one for a 64 bit Windows Intel platform, or Solaris, ARM, and so on. For many of those platforms there are no registers called RAX and EAX.
But if you really need to know, look at the source code, or use the JVM option for dumping the native code emitted by the JIT compiler.
Answer from Stephen C on Stack OverflowVideos
For a school project, we're supposed to work with longs in encoding and reading from .dat and .idx files.
So for example, encoding a 0 into a file would encode 0000 0000 0000 0000. I'm trying to puzzle through the definition of longs, and according to the java docs, a long is 64 bits, or 8 bytes.
So for a long 0000 0000 0000 0000, how does this correspond to 8 bytes if there are 16 zeroes in total?
Quoting this answer:
In a modern 64-bit JDK, an object has a 12-byte header, padded to a multiple of 8 bytes
The extra 4 bytes is padding to get to a multiple of 8.
you can check the size of double:
double numDouble=2;
long size=(long)(numDouble*Double.SIZE) / Byte.SIZE;
System.out.println(size);
output: 16
I’ve tried looking for definitive answers but the only difference I see seems to be based on the precision of the numbers?
Which data type is larger and which one is smaller?
There are specific suffixes for long (e.g. 39832L), float (e.g. 2.4f) and double (e.g. -7.832d).
If there is no suffix, and it is an integral type (e.g. 5623), it is assumed to be an int. If it is not an integral type (e.g. 3.14159), it is assumed to be a double.
In all other cases (byte, short, char), you need the cast as there is no specific suffix.
The Java spec allows both upper and lower case suffixes, but the upper case version for longs is preferred, as the upper case L is less easy to confuse with a numeral 1 than the lower case l.
See the JLS section 3.10 for the gory details (see the definition of IntegerTypeSuffix).
By default any integral primitive data type (byte, short, int, long) will be treated as int type by java compiler. For byte and short, as long as value assigned to them is in their range, there is no problem and no suffix required. If value assigned to byte and short exceeds their range, explicit type casting is required.
Ex:
byte b = 130; // CE: range is exceeding.
to overcome this perform type casting.
byte b = (byte)130; //valid, but chances of losing data is there.
In case of long data type, it can accept the integer value without any hassle. Suppose we assign like
long l = 2147483647; //which is max value of int
in this case no suffix like L/l is required. By default value 2147483647 is considered by java compiler is int type. Internal type casting is done by compiler and int is auto promoted to Long type.
long l = 2147483648; //CE: value is treated as int but out of range
Here we need to put suffix as L to treat the literal 2147483648 as long type by java compiler.
so finally
long l = 2147483648L;// works fine.
The absolute quantity of information that you can store in 64 bit is of course the same.
What changes is the meaning you assign to the bits.
In an integer or long variable, the codification used is the same you use for decimal numbers in your normal life, with the exception of the fact that number two complement is used, but this doesn't change that much, since it's only a trick to gain an additional number (while storing just one zero instead that a positive and a negative).
In a float or double variable, bits are split in two kinds: the mantissa and the exponent. This means that every double number is shaped like XXXXYYYYY where it's numerical value is something like XXXX*2^YYYY. Basically you decide to encode them in a different way, what you obtain is that you have the same amount of values but they are distribuited in a different way over the whole set of real numbers.
The fact that the largest/smallest value of a floating number is larger/smaller of the largest/smalles value of a integer number doesn't imply anything on the amount of data effectively stored.
A double can store a larger number by having larger intervals between the numbers it can store, essentially. Not every integer in the range of a double is representable by that double.
More specifically, a double has one bit (S) to store sign, 11 bits to store an exponent E, and 52 bits of precision, in what is called the mantissa (M).
For most numbers (There are some special cases), a double stores the number (-1)^S * (1 + (M * 2^{-52})) * 2^{E - 1023}, and as such, when E is large, changing M by one will make a much larger change in the size of the resulting number than one. These large gaps are what give doubles a larger range than longs.