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
As you can see here .
If you use unsigned type the just calculate
ans = (2 power number_of_bits) - 1
else calculate ans = (2 power number_of_bits - 1)
and the range is
[-ans,ans-1]
have a great day :)
Check this link, it is the official documentation by oracle, where it is explained in detail.
Source Link - Oracle Documentation
For a quick reference, quoting the main points from the documentation.
byte:
The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation.
short:
The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with byte, the same guidelines apply: you can use a short to save memory in large arrays, in situations where the memory savings actually matters.
int:
By default, the int data type is a 32-bit signed two's complement integer, which has a minimum value of -231 and a maximum value of 231-1. In Java SE 8 and later, you can use the int data type to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of 232-1. Use the Integer class to use int data type as an unsigned integer. See the section The Number Classes for more information. Static methods like compareUnsigned, divideUnsigned etc have been added to the Integer class to support the arithmetic operations for unsigned integers.
long:
The long data type is a 64-bit two's complement integer. The signed long has a minimum value of -263 and a maximum value of 263-1. In Java SE 8 and later, you can use the long data type to represent an unsigned 64-bit long, which has a minimum value of 0 and a maximum value of 264-1. Use this data type when you need a range of values wider than those provided by int. The Long class also contains methods like compareUnsigned, divideUnsigned etc to support arithmetic operations for unsigned long.
float:
The float data type is a single-precision 32-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. As with the recommendations for byte and short, use a float (instead of double) if you need to save memory in large arrays of floating point numbers. This data type should never be used for precise values, such as currency. For that, you will need to use the java.math.BigDecimal class instead. Numbers and Strings covers BigDecimal and other useful classes provided by the Java platform.
double:
The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency.
boolean:
The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined.
char:
The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).
In addition to the eight primitive data types listed above, the Java programming language also provides special support for character strings via the java.lang.String class. Enclosing your character string within double quotes will automatically create a new String object; for example, String s = "this is a string";. String objects are immutable, which means that once created, their values cannot be changed. The String class is not technically a primitive data type, but considering the special support given to it by the language, you'll probably tend to think of it as such. You'll learn more about the String class in Simple Data Objects
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?