0Pricing
Java Academy · Lesson

Integer Arithmetic & Overflow

Understand integer division, modulus, overflow behavior, and how to detect it.

Integer Arithmetic & Overflow

Java integers have fixed sizes. When a calculation exceeds the maximum or minimum value, it wraps around silently — no exception is thrown. Understanding this prevents subtle bugs.

Integer Ranges

Each integer type has a bounded range determined by its bit width:

  • byte: -128 to 127
  • short: -32,768 to 32,767
  • int: -2,147,483,648 to 2,147,483,647
  • long: -9.2 × 10^18 to 9.2 × 10^18
System.out.println(Integer.MAX_VALUE); // 2147483647
System.out.println(Integer.MIN_VALUE); // -2147483648
System.out.println(Long.MAX_VALUE);    // 9223372036854775807
System.out.println(Byte.MAX_VALUE);    // 127

All lessons in this course

  1. The Math Class Essentials
  2. Integer Arithmetic & Overflow
  3. BigDecimal for Financial Calculations
  4. NumberFormat and printf
← Back to Java Academy