Integer Types
The Java integer types are byte, short, int, and long.
byte
Occupies 8 bits or 1 byte, which is:
-27 to 27-1 or -128 to 127
Default value of 0
Example: -17, 123
short
Occupies 16 bits or 2 bytes, which is:
-215 to 215-1 or -32,768 to 32,767
Default value of 0
Example: 31,098, -9001
int
Occupies 32 bits or 4 bytes, which is:
-231 to 231-1 or -2,147,483,648 to 2,147,483,647
Default value of 0
Example: 50, 2147000000, -53000
The int is probably the most commonly used integral type in Java. That's because it is often not worth trying to save memory space by using a smaller type, such as a byte. Here's why: when you perform a comparison operation or an arithmetic operation with a byte, it gets promoted to an int anyway by the runtime, then the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access