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 Overflow
Top answer
1 of 1
4

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.

🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › datatypes.html
Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)
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 ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Long.html
Long (Java Platform SE 8 )
October 20, 2025 - Parses the string argument as an unsigned decimal long. The characters in the string must all be decimal digits, except that the first character may be an an ASCII plus sign '+' ('\u002B'). The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseUnsignedLong(java.lang.String, int) method.
🌐
iO Flood
ioflood.com › blog › java-long
The Long Data Type in Java: A Detailed How-To Guide
February 26, 2024 - The int and long data types are ... 2,147,483,647. long is a 64-bit data type and can hold values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807....
🌐
W3Schools
w3schools.com › java › java_data_types.asp
Java Data Types
Note: This rule makes Java safer, because the compiler will stop you if you try to mix up types by mistake. If you really need to change between types, you must use type casting or conversion methods (for example, turning an int into a double).
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java long class
Java Long Class Overview
September 1, 2008 - Following are the fields for java.lang.Long class − · static long MAX_VALUE − This is a constant holding the maximum value a long can have, 263-1. static long MIN_VALUE − This is a constant holding the minimum value a long can have, -263. ...
🌐
W3Schools
w3schools.com › java › ref_keyword_long.asp
Java long Keyword
Java Examples Java Videos Java ... ... The long keyword is a data type that can store whole numbers from -9223372036854775808 to 9223372036854775808....
Find elsewhere
🌐
GitHub
github.com › AdoptOpenJDK › openjdk-jdk11 › blob › master › src › java.base › share › classes › java › lang › Long.java
openjdk-jdk11/src/java.base/share/classes/java/lang/Long.java at master · AdoptOpenJDK/openjdk-jdk11
int mag = Long.SIZE - Long.numberOfLeadingZeros(val); int chars = Math.max(((mag + (shift - 1)) / shift), 1); if (COMPACT_STRINGS) { byte[] buf = new byte[chars]; formatUnsignedLong0(val, shift, buf, 0, ...
Author   AdoptOpenJDK
🌐
BeginnersBook
beginnersbook.com › 2022 › 10 › what-is-long-keyword-in-java
What is long Keyword in Java
public class JavaExample { public static void main(String[] args) { long num = 12345678910L; System.out.println(num); } } ... The long values are ended with ‘L’ letter as shown in the above example. The size of long is 64 bit (8 bytes), which is higher than int so you should use int for ...
🌐
Coderanch
coderanch.com › t › 779211 › java › suffix-needed-long-number
L (or l) suffix needed for long number, but why? (Beginning Java forum at Coderanch)
This following code does compile , and the difference is that I added the suffix L to the number. The question is: why do I have to add the L when the variable is already declared to be of the long type?.
🌐
Huda Tutorials
hudatutorials.com › java › basics › java-arrays › java-long-array
Java long Array - long Array in Java, Initializing
July 16, 2021 - That is the size of an array must be specified by an int value and not long or short. All the arrays index beginning from 0 to ends at 2147483646. You can store elements upto 2147483647.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-data-types
Java Data Types - GeeksforGeeks
Size : 8 bytes (64 bits). It is recommended to go through rounding off errors in java. ... public class Geeks { public static void main(String[] args) { double pi = 3.141592653589793; double avogadro = 6.02214076e23; System.out.println("Pi: ...
Published   November 7, 2016
🌐
DataCamp
datacamp.com › doc › java › long
long Keyword in Java: Usage & Examples
BigInteger for Very Large Numbers: If you need to handle numbers larger than the long range, consider using BigInteger from the java.math package.
Top answer
1 of 7
209

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).

2 of 7
19

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.
🌐
LabEx
labex.io › tutorials › java-how-to-interpret-long-value-ranges-in-java-422176
How to interpret long value ranges in Java | LabEx
In Java, the long data type is a 64-bit signed two's complement integer that can store very large numeric values. It provides a wider range of values compared to other integer types like int. Size: 64 bits (8 bytes) Range: -2^63 to 2^63 - 1 ·
🌐
Quora
quora.com › How-do-you-enter-a-long-data-type-range-in-Java
How to enter a long data type range in Java - Quora
Answer: I see your problem… When you are using the scanner you are sending the next integer to the long value a. You cannot convert between int and long like that. I can't remember if there is a next long function for scanner but you can certainly do that research.
Top answer
1 of 4
7

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.

2 of 4
2

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.