Eight data types numeric: Integer type: Byte, shot, int, long
Byte: Length is 28 ( -27~27-1)
Shot: Length 216 ( -215~215-1)
int: Length 232 ( -231~231-1)
Long: Length 264 ( -263~263-1)
Float type: float, double
float: Length 232 (initialization required to add F after decimal, example: float num=3.14f)
Double: Length 264 (both forms of initialization can be, example 1:double num=3.1415926d; 2:double num=3.1415926)
Character type: Char
Char: Stores a single character, occupying 16 bits (two bytes) of memory space.
(The Java language can also treat characters as integers, because Unicode encoding uses unsigned encoding, and characters in Java correspond to integers between 0~65536, so char and int can show conversions to each other)
Boolean Type: Boolean
Boolean: The value is divided into: true and false;
Type conversion of numeric type
In expressions, such as:c=a+b;a>b?c:d;
Two number has a double type and the other is also converted to double type
Two numbers have one float type and the other is converted to float type
There is a long type in the two number and the other is also converted to a long type
Otherwise it will be converted to int type;
Converting a large range of numeric types to a small range of numeric types requires an explicit conversion and may be accompanied by a loss of precision.
Examples of interview questions
1. (false?) 10.9:9) What is the value?
Java is automatically type-converted based on the precision type of the operator, and 9 is automatically converted to 9.0 due to the presence of 10.9. So the result is 9.0.
2. Char x= "9"; (false?) X:10) The value of why?
When there is a constant expression in the expression (this is titled 10), the other type is T (this is the char type), and the constant expression can be represented by T, and the output is of type T.
The result of the subject is "10" of char type;
Java Fundamentals-Basic data types