Java Data Types
The Java integer constant is the int type by default, but there are two things to be aware of:
1. Assigning a small integer constant (within the range of Byte,short) to the Byte,short type, the system automatically treats the integer constant as a byte,short type.
2. When using a huge integer constant (out of the int range), Java does not automatically treat this integer constant as a long type. You need to add L or L (recommended L) after the integer constant.
The system automatically handles 127 as a byte type, allocating 1 bytes of storage space byte SMALL1 = 127;//system handles 127 as an int type, allocates 4 bytes of storage space int small2 = 127;//syntax error "the literal 214 7483648 of type int is out of range "long big1 = 2147483648;//correct, plus L is forced to use long type long big2 = 2147483648L;
Integer constants are represented in 3 ways: decimal (default), octal, hexadecimal.
Octal notation, starting with 0 int octalvalue = 011;//decimal 9//16 binary, starting with 0x or 0X int hexvalue = 0xa;//decimal 10
Java Data types