Java provides eight basic types. Six numeric types (four integers, two floating point types), one character type, and one boolean type.
1. Integer: Contains int, short, byte, long, and the initial value is 0.
2. float: float, double, initial value: 0.0
3. Character: char. The initial value is a space, that is, ''. If the output is not displayed on the Console.
4. boolean: boolean. The initial value is false.
Basic Type |
Size |
Minimum value |
Maximum Value |
Boolean |
----- |
----- |
------ |
Char |
16-bit |
Unicode 0 |
Unicode 2 ^ 16-1 |
Byte |
8-bit |
-128 |
+ 127 |
Short |
16-bit |
-2 ^ 15 |
+ 2 ^ 15-1 |
Int |
32-bit |
-2 ^ 31 |
+ 2 ^ 31-1 |
Long |
64-bit |
-2 ^ 63 |
+ 2 ^ 63-1 |
Float |
32-bit |
IEEE754 |
IEEE754 |
Double |
64-bit |
IEEE754 |
IEEE754 |
Void |
|
|
|
Note:
The ^ In the table indicates the power of the power;
Java uses unicode, two bytes to represent a character.
Basic Package Type
Integer, Long, Short, Byte, Character, Double, Float, Boolean, BigInteger, BigDecmail
BigInteger and BigDecimal have no corresponding basic types and are mainly used in high-precision operations. BigInteger supports any precision integer,
BigDecimal supports any operation with decimal point precision.
Similarities and differences between basic types and packaging types:
1. in Java, everything is an object, but the eight basic types are not objects.
2. for different declaration methods, the basic type does not need to be created using the new keyword, while the encapsulation type requires the new keyword.
3. for different storage methods and locations, the basic type is to store the values of variables directly in the stack for efficient access. The encapsulation type needs to be referenced to the instance, the specific instance is saved in the heap.
4. Different initial values: the initial value of the encapsulation type is null. The initial value of the basic type depends on the specific type. For example, the initial value of the int type is 0, and the value of the boolean type is false;
5. Use different methods. For example, the packaging type can only be used for cooperation with the collection class.