int (Java)

int is the most common Java primitive type for whole numbers, such as 5, 0, or -42. It holds a 32-bit signed integer, with a range of about -2.1 billion to 2.1 billion.

Java

Unlike Python, Java's int has a fixed size and will overflow if a value goes beyond its range. For larger whole numbers, use the long type, which is 64-bit.

Integer division in Java drops the decimal part: 7 / 2 gives 3, not 3.5.

Examples

Java

int count = 10;
int result = 7 / 2;
System.out.println(count);
System.out.println(result);

Output:

10
3

Learn it in a lesson

See also

Back to the Dictionary