(1) Summary of data types
Java data types are mainly Boolean, byte, int, short, char, long, float, double.
The byte type data occupies 1 bytes, 8 bits, and the highest bit represents the symbol, then the range is: -2^7~2^7-1
The int type data is 4 bytes, a total of 32 bits, the highest bit represents the symbol, then the range is: -2^31~2^31-1
The short type data occupies 2 bytes, a total of 16 bits, the highest bit represents the symbol, then the range is: -2^15~2^15-1
The long type data is 8 bytes, a total of 64 bits, and the highest bit represents the symbol, the range is: -2^63~2^63-1
The float data type occupies 4 bytes, a total of 32 bits, the range is: 10^-38~10^38 and -10^38~-10^-38
The double data type is 8 bytes, a total of 64 bits, and the range is: 10^-308~10^308 and -10^308~-10^-308
The char data type occupies 2 bytes, but the highest bit is not used to represent the symbol. Then it can represent the character of the 0~2^16-1 (0~65535) position in the Unicode set.
The char data type is applied in the following ways:
such as: Char a= ' a '; Char a=97 (cannot use the short type, because the highest bit represents the symbol, so the value is only 15 bits);
(2) data type conversion issues
Data types have precision, from low to high sort: byte short int long float double
When a variable of a low precision type assigns a value to a high-precision variable, it can be assigned directly, such as:
float a=100; output A is 100.0
When high-precision variables are assigned values to low-precision variables, display conversions must be performed, such as:
int a= (int) 123.345f;
The above is a personal learning harvest, if there are errors, please correct me.
Summary of Java data types and data type conversion issues