0Pricing
Java Academy · Lesson

BigInteger for Huge Numbers

Arbitrary-precision integers.

Beyond long

The primitive long can hold values up to about 9.2 quintillion. When you need integers larger than that, Java offers BigInteger from the java.math package, which has no fixed upper limit.

When long Overflows

Exceeding Long.MAX_VALUE silently wraps around to a negative number. This corruption is a classic bug source.

public class Main {
    public static void main(String[] args) {
        long max = Long.MAX_VALUE;
        System.out.println(max);
        System.out.println(max + 1);
    }
}

All lessons in this course

  1. Why Not double for Money
  2. Working with BigDecimal
  3. Rounding and Scale
  4. BigInteger for Huge Numbers
← Back to Java Academy