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....
🌐
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 › 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).
🌐
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
Top answer
1 of 4
1

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

2 of 4
1

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

🌐
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 ...
🌐
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.
🌐
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?.
🌐
W3Resource
w3resource.com › java-tutorial › java-premitive-data-type.php
Java Primitive data type - w3resource
... package primitive; public class PrimitiveDemo { public static void main(String[] args) { byte b =100; short s =123; int v = 123543; int calc = -9876345; long amountVal = 1234567891; float intrestRate = 12.25f; double sineVal = 12345.234d; ...
🌐
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.
🌐
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
🌐
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 ·
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › › api › java.base › java › lang › Long.html
Long (Java SE 21 & JDK 21)
January 20, 2026 - 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 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.