Integer.MAX_VALUE and Integer.MIN_VALUE
Fast recall
Quick revision
Core answer
Integer.MAX_VALUE is 2,147,483,647 and Integer.MIN_VALUE is -2,147,483,648, the bounds of Java's signed 32-bit int. They are useful for range checks and sometimes as initial values when a non-empty algorithm's invariant makes that safe. They do not detect overflow by themselves; use Math.addExact, Math.multiplyExact, or a wider/decimal type when overflow must be reported.Whether you know the values and their practical use cases in coding problems.
Not knowing what happens when you go beyond MAX_VALUE — silent integer overflow: MAX_VALUE + 1 wraps to MIN_VALUE (negative). No exception, no warning.
Mention the overflow trap: multiplying two large ints can silently overflow to a wrong result. Fix: cast one operand to long first — `long result = (long) a * b`. Also: use Long.MAX_VALUE / Long.MIN_VALUE when int range is not enough.
Interview-ready guide
Interview answer
These two constants give you the edges of a 32-bit int without memorising the digits — Integer.MAX_VALUE is 2147483647, about 2.1 billion, and Integer.MIN_VALUE is -2147483648. The place you actually use them is min/max search: to find the smallest element you initialise your tracker at MAX_VALUE, so the first real value is guaranteed to beat it; to find the largest you start at MIN_VALUE. They also work as sentinels when 0 or -1 might be valid data.
The thing I'd make sure to land is what happens when you go past the edge, because most people assume Java protects you. It doesn't. Integer overflow is completely silent — Integer.MAX_VALUE + 1 doesn't throw, it just wraps around to Integer.MIN_VALUE, a negative number. The same trap hits multiplication: 100000 * 100000 overflows and gives a wrong answer with no warning at all.
The fix is to widen before the operation — cast one operand to long, (long) a * b, so the math happens in 64 bits. And it has to be the operand, not the result; (long)(a * b) is too late because the int multiply already overflowed. If int genuinely isn't enough, I move up to Long.MAX_VALUE, which is around 9.2 × 10¹⁸.
Integer.MAX_VALUE and Integer.MIN_VALUE
Direct Answer
Integer.MAX_VALUE is 2,147,483,647 and Integer.MIN_VALUE is -2,147,483,648, the bounds of Java's signed 32-bit int. They are useful for range checks and sometimes as initial values when a non-empty algorithm's invariant makes that safe. They do not detect overflow by themselves; use Math.addExact, Math.multiplyExact, or a wider/decimal type when overflow must be reported.
Code Example
public class MinMaxDemo {
public static void main(String[] args) {
// The values
System.out.println(Integer.MAX_VALUE); // 2147483647
System.out.println(Integer.MIN_VALUE); // -2147483648
// Classic use: finding minimum in an array
int[] arr = {42, 7, 99, 3, 55};
int min = Integer.MAX_VALUE; // start with largest possible
for (int x : arr) {
if (x < min) min = x; // every real value beats Integer.MAX_VALUE
}
System.out.println("Min: " + min); // 3
// Finding maximum
int max = Integer.MIN_VALUE;
for (int x : arr) {
if (x > max) max = x;
}
System.out.println("Max: " + max); // 99
// OVERFLOW TRAP — silent wrap-around, no exception!
int big = Integer.MAX_VALUE;
System.out.println(big + 1); // -2147483648 — wraps to MIN_VALUE!
// Safe fix: use long
long safe = (long) Integer.MAX_VALUE + 1;
System.out.println(safe); // 2147483648 — correct
// Multiply overflow — common bug
int a = 100000;
int b = 100000;
System.out.println(a * b); // 1410065408 — WRONG (overflow)
System.out.println((long) a * b); // 10000000000 — correct
}
}
Common Mistakes & Pitfalls
- Assuming overflow throws an exception — it never does in plain Java;
Integer.MAX_VALUE + 1silently wraps toInteger.MIN_VALUEwith no warning. - Multiplying two
ints without widening —100000 * 100000overflows; forcelongmath with(long) a * b. - Casting after the overflow —
long r = (long)(a * b)is too late, because theintmultiply already wrapped; cast an operand first, not the result. - Expecting
Math.abs(Integer.MIN_VALUE)to be positive — there is no positive twin forMIN_VALUE, soMath.abs()overflows and returnsMIN_VALUEagain, still negative. - Using
Integer.MAX_VALUEas a sentinel and then doing arithmetic on it — adding to it overflows; keep sentinels out of calculations or widen tolong.
Check your understanding
Answer these without looking back at the article.
- What is integer overflow in Java and why doesn't it throw an exception?
- How do you safely multiply two large integers in Java without overflow?
- What is Long.MAX_VALUE and when would you use it instead of Integer.MAX_VALUE?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.