One. Java data types are divided into
1. Native data types
Also called basic data type, divided into shaping, floating-point type, character type, Boolean type. There are byte,short,int,long in shaping, floating-point type has float,double, character type has char, Boolean type has Boolean.
2. Reference data types
Includes class, interface, array
Two. Constants and variables
A constant is the amount of value that does not change, and a variable is the amount to which the value can vary.
Three. Declaration and initialization of variables
Example: int A;
a=0;
int b=0;
Four. Size of data type
In memory, the Byte,boolean type of data accounts for 1 bytes, or 8 bits;
The data of the Short,char type is 2 bytes, i.e. 16 2 binary bits;
The data of the Int,float type is 4 bytes, i.e. 32 2 binary bits;
The data for the long,double type is 8 bytes, or 64 2 binary bits.
Five. Type conversion
Type conversions are divided into forced type conversions and automatic type conversions.
When a type with a small precision is assigned to a variable with a high precision, it will be converted automatically, and the precision can be lost if the assignment of high precision to a variable with small precision requires forced type conversion.
Example: int i = (byte) 1; That's right
float a= 1; Correct, 1 The default is int type
float b=1.0; Error, 1.0 The default is double type, precision is higher than float, should be float b=1.0f;
int x = 5.5; Error, mandatory type conversion required, int x = (int) 5.5;
Java Base 1_java data type