Java basic grammar-basic data types, Unicode encoding, basic data type conversion

java data type

The program defines a clear specific data type for each type of data, and allocates different sizes of memory space in the memory

Basic data type

byte byte type 1 byte

short 2 bytes

int shape 4 bytes

long 8 bytes

float single precision floating point number 4 bytes

double double-precision floating-point number 8 bytes

The char character type defaults to 2 bytes

boolean Boolean type 1 byte

The integer constants of the java language default to the int type, and the declaration of the long type constant can be followed by l or L

Sort by range size: byte<short<int<long<float<double

Unicode encoding

Unicode: Known as the universal code, it contains all the symbols in the world, and each symbol is encoded. Java uses unicode encoding, covering ASCII encoding. Among them, utf-8 is a variable byte encoding version in Unicode encoding. Use 1-6 bytes for encoding

Basic data type conversion

Java can be converted from any basic type to another basic type.
Exception  boolean type cannot be converted to other data types.
Conversion is divided into default conversion and forced conversion.
Default conversion
. Integer, character, and floating-point data are converted into each other in mixed operations. The conversion follows the following principles:
the type with small capacity is converted to the data type with large capacity by default; the data type is based on capacity The order of size is:
byte, short, char->int->long->float->double
byte, short, and char will not be converted to each other. The three of them will first be converted to int type during calculation.
Coercion of
large capacity When the data type is converted to a data type with a small capacity, a coercion symbol must be added, but it may cause a decrease in accuracy or overflow; pay special attention when using it.
When there are multiple types of data mixed operations, the system first automatically converts all data into the data type with the largest capacity, and then performs calculations.

Guess you like

Origin blog.csdn.net/m0_46958163/article/details/109136846