Long.MAX_VALUE is 9223372036854775807 (9,223,372,036,854,775,807 or 263-1).

If you were executing your function once per nanosecond, it would still take over 292 years to encounter this situation according to this source.

When that happens, it'll just wrap around to Long.MIN_VALUE which is -9223372036854775808 (-9,223,372,036,854,775,808 or -263) as others have said.

Answer from Krease on Stack Overflow
🌐
Delft Stack
delftstack.com › home › howto › java › long max value in java
Long.MAX_VALUE in Java | Delft Stack
October 30, 2023 - Then, we attempt to add 1 to a. Before performing the addition, we check if the result is less than the original value of a or greater than Long.MAX_VALUE. If this condition is true, it indicates that an overflow has occurred. Otherwise, the addition is within the valid range for long values and no overflow has occurred. ... Overflow detected! In Java, attempting to add 1 to the Long.MAX_VALUE constant will indeed result in overflow, causing the value to wrap around to the lowest possible long value, which is -9223372036854775808.
🌐
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 ...
🌐
GoLinuxCloud
golinuxcloud.com › home › java › long.max_value & long.min_value in java (exact values + examples)
Long.MAX_VALUE & Long.MIN_VALUE in Java (Exact Values + Examples) | GoLinuxCloud
January 16, 2022 - It is 19 digits long (9,223,372,036,854,775,807). No. Java is platform-independent. A long is strictly 64-bit on all JVM architectures. Long.MAX_VALUE and Long.MIN_VALUE define the boundaries of the 64-bit long type.
🌐
Coderanch
coderanch.com › t › 401851 › java › Maximum-digits-allowed-literal
Maximum digits allowed for each literal (Beginning Java forum at Coderanch)
NUMERIC INTEGRALS... byte: 8 bits short: 16 bits int: 32 bits long: 64 bits NUMERIC FLOATING POINT... float: 32 bits double: 64 bits SPECIAL CASES... char: 16 bits boolean: 1 bit Once you know this, the next step is to understand how values are represented in binary for each type.
🌐
Grails
grails.asia › maximum-value-of-long-in-java
Maximum Value of Long in Java - Grails Cookbook
And when you when you diminish one from 9,223,372,036,854,775,808, that will bring you the maximum value for long values which is 9,223,372,036,854,775,807 . Check out the code snippet from the Long class that defines the constant maximum value of Long in Java:
🌐
Deep Java
digibeatrix.com › home › java fundamentals › java long max value: long.max_value, range, and overflow (with examples)
Java long Max Value: Long.MAX_VALUE, Range, and Overflow (With Examples) - Deep Java
1 month ago - Do not calculate it directly. Always use: ... Math.pow() returns a double and is therefore inaccurate for large integers. If the range is within about 2.1 billion → use int ... Use long for DB BIGINT columns and timestamps. The maximum value has 19 digits: 9223372036854775807
🌐
Quora
quora.com › In-Java-how-many-digits-short-can-int-and-long-can-store
In Java, how many digits short can int and long can store? - Quora
Here is the bit counts except sign bit, and decimal digits: float: 23 bit, 6 ~ 7 decimal digits, double: 52 bit, 15 ~ 16 decimal digits, byte: 7 bit, 2 ~ 3 decimal digits, short: 15 bit, 4 ~ 5 decimal digits, int: 31 bit,...
Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.long.maxvalue
Long.MaxValue Field (Java.Lang) | Microsoft Learn
[Android.Runtime.Register("MAX_VALUE")] public const long MaxValue = 9223372036854775807; [<Android.Runtime.Register("MAX_VALUE")>] val mutable MaxValue : int64 ... Java documentation for java.lang.Long.MAX_VALUE.
🌐
i-Programmer
i-programmer.info › ebooks › modern-java › 5423-java-data-types-numeric-data.html
Java Data Types - Numeric Data
Programming book reviews, programming tutorials,programming news, C#, Ruby, Python,C, C++, PHP, Visual Basic, Computer book reviews, computer history, programming history, joomla, theory, spreadsheets and more.
🌐
GeeksforGeeks
geeksforgeeks.org › java › integer-max_value-and-integer-min_value-in-java-with-examples
Integer.MAX_VALUE and Integer.MIN_VALUE in Java with Examples - GeeksforGeeks
July 12, 2025 - Example 2: Trying to initialize a variable value Integer.MAX_VALUE + 1 ... // Java program to show what happens when // a value greater than Integer.MAX_VALUE // is stored in an int variable class GFG { // Driver code public static void main(String[] arg) { try { System.out.println( "Trying to initialize" + " a N with value" + " Integer.MAX_VALUE + 1"); // Try to store value Integer.MAX_VALUE + 1 int N = Integer.MAX_VALUE + 1; // Print the value of N System.out.println("N = " + N); } catch (Exception e) { System.out.println(e); } } }
🌐
iO Flood
ioflood.com › blog › integer-max-value-java
Java's Integer.MAX_VALUE Explained: A Complete Guide
March 11, 2024 - The long data type in Java can hold much larger values than int. The maximum value of long is 9,223,372,036,854,775,807, which is retrieved by Long.MAX_VALUE.
🌐
Dirask
dirask.com › posts › Java-get-long-max-value-xpJPV1
Java - get long max value
Short solution: Java Long max value is 9223372036854775807 Additionally short solution to get long min value: Java Long min value is -9223372036854775808 1. Alt...
🌐
Runestone Academy
runestone.academy › ns › books › published › apcsareview › VariableBasics › minAndMax.html
3.7. Integer Min and Max — AP CSA Java Review - Obsolete
In 32 bits of space with one bit ... that many values. Why is there one more negative number than positive number? It is because 0 is considered a positive number. What do the last two lines print out? Did this surprise you? Java will actually return the maximum integer value ...
🌐
iO Flood
ioflood.com › blog › java-long
The Long Data Type in Java: A Detailed How-To Guide
February 26, 2024 - As mentioned earlier, each numeric data type in Java has a specific range of values it can hold. If a calculation results in a value that is outside this range, it can lead to numeric overflow (if the value is too large) or underflow (if the value is too small). For example, if you add 1 to the maximum value an int can hold, you’ll get numeric overflow, and the result will wrap around to the minimum value an int can hold.