Java Integer MAX_VALUE Field
Example
Print the largest int value, and see what happens when you add 1:
public class Main {
public static void main(String[] args) {
int myNum = Integer.MAX_VALUE;
System.out.println(myNum);
System.out.println(myNum + 1);
}
}
Definition and Usage
The MAX_VALUE field is a constant (a fixed value) that holds the largest value an int can have: 2147483647.
If a calculation goes above this value, the result wraps around to the smallest value. This is called an overflow. Use a long if your numbers can be larger.
Tip: Use MIN_VALUE to get the smallest value an int can have.
Syntax
public static final int MAX_VALUE
Related Pages
❮ Integer Methods