There are 8 basic data types in the Java language, and the basic information is summarized as follows:
|
Serial number |
Data type |
Size/bit |
Encapsulation class |
Default value |
can represent a range of data |
|
1 |
BYTE (bit) |
8 |
Byte |
0 |
-128~127 |
|
2 |
Short (shorter integer) |
16 |
Short |
0 |
-32768~32767 |
|
3 |
Int (integer) |
32 |
Integer |
0 |
-2147483648~2147483647 |
|
4 |
Long (length integer) |
64 |
Long |
0L |
-9223372036854775808~9223372036854775807 |
|
5 |
Float (single precision) |
32 |
Float |
0.0f |
1.4e-45~3.4028235e38 |
|
6 |
Double (dual precision) |
64 |
Double |
0.0 |
4.9e-324~1.7976931348623157e308 |
|
7 |
char (character) |
16 |
Character |
'/uoooo ' (null) |
0~65535 |
|
8 |
Boolean |
8 |
Boolean |
Flase |
True or False |
☆☆☆☆☆
When a variable is used as a member of a class, Java ensures that its initial value is given , preventing a program run-time error. But these initial values are not correct for your program. Therefore, you must explicitly specify the initial value.
However, the above complaint does not apply to "local" variables (i.e., fields that are not a class). Therefore, when you define int i in a method, the variable I may get any value. will not be initialized to 0. So pay an appropriate value before use. If you forget, Java will return an error at compile time. Tells you that this variable is not initialized. When you define a reference to an object in a class, the reference defaults to a null value if there is no given initialization value. That is, the default value for the base type in Java is 0, and the reference type defaults to NULL.
Default values for initial variables in Java