elementary data type
Java contains eight basic data types, namely:
boolean、byte、char、short、int、float、douboe、long
byte
Byte is the smallest data type in JAVA, occupying 8 bit of memory, and its value range is-128 to 127.
Assignment: byte I = 127
Short integer
The short type occupies 2 bytes in memory, and its value range is -32768 to 32767.
Assignment: short i = 32767
character type
Char type occupies 2 bytes in memory. Represents a character, or you can assign a value to a char type variable with a value in the ASCII code range. Because there is no negative range for character values in memory, all values range from 0 to 65535.
Assignment: char i =' a' a or char i = 97.
Int integer
The Int type occupies 4 bytes in memory. Values range from -2 147483648 to 2 147483647.
Assignment: int I =10;
Floating point single precision floating point type
Floating-point types occupy 4 bytes in memory. Values range from -3.4E38 to 3.4E38.
Assignment: float I =1.0f;
Long integer
Long type occupies 8 bytes in memory. Values range from -9223372036854775808 to 922375475757.
Double precision floating-point type
Double type occupies 8 bytes in memory. Values range from-1.7E308 to 1.7E308.
Boolean Boolean type
Boolean types have only two values: true and false.
Mutual conversion of basic data types
transformation rule
All numerical variables in JAVA are signed (positive and negative).
JAVA does not allow arbitrary conversion types. Only numeric variables can be converted, and they cannot be converted at will.
By default, numeric variables with decimal points are double-precision. Defining floating-point types requires forced type conversion.
When assigning numeric variables with fewer bytes to types with more bytes, there is no need to force type conversion. At this time, it is automatically converted.
When an int variable is assigned to a char variable, the JVM will use the int variable to look up the corresponding characters in the ASCII code table, and then assign them to the char variable. or vice versa, Dallas to the auditorium But follow rule 4.
When initializing simple data types, pay attention to the range of assignment, which will lead to compilation errors.
Default initial value of basic data type
Enter the initial value
Boolean false
Byte 0
Character 0
Short 0
int 0
Floating 0.0
Double 0.0
long 0
Default initial table of basic data types
Reference data type
In JAVA, all types of non-simple data types are reference data types.