1.Java data type (two types: base data type, reference type)
1.1 has 8 basic data Types
Byte,short,int,long,float,double,char,boolean
8 bit = 1 byte ( bytes )
1 kb=1024 Byte
1.2 cast
from low to high Turn: (Automatic conversion) no problem.
1.2.1 Two types must be compatible, and the target type is greater than the source type, for example:
Byte,char , and short types can all be promoted to int .
1.2.2 for an expression, the final result will be the same as the highest data type in the expression.
from high to low go: (cast) there is a problem.
If the data type of the converted value is greater than its target type, some information will be lost;
int x = 65;
char ch = (char) x;
Such statements will cause an error because the char type is less accurate than the int type, and the compiler cannot convert it automatically, only cast:
1.3 Reference type:
In addition to the 8 basic data types, it is the reference data type.
Including:
classes in 1.API, such as String,File , and so on
2. Arrays
3. custom classes, such as Cars,Student
4. objects are all reference data types
1.4 The reference type uses exactly the same scenario as the base data type
1. use as a type of attribute
2. Use the return value type as a method
3. use as a form parameter type for a method
Java data type