Java-data types (eight basic data types)

Integer types: byte, short, int, long
byte: generally related to file operations, such as upload and download. 8-bit length, -128-127
short: very few used, rounding range is too small. 16-bit length, -32768-32767
int: most frequently used, ranging from -2.1 billion to 2.1 billion. 32-bit
long: Long types are used beyond the value range of int. 64 bit

1.byte numbyte1 = 133; Error: cannot convert from int to byte
cannot be converted from int type to byte type
integer constant as int type, but if the value range is between -128-127, it will automatically convert int to byte , But if it exceeds the range, the integer constant is of type int
2.long numlong1 = 1200000000000; the
integer constant defaults to int type, 120000000000 exceeds the value range of int, the error
modification method: add L or l, convert the constant to the corresponding long type

Floating point type: float, double (decimal)
double: the most commonly used by enterprise development, with a large value range and high precision
float: less used, the value range is too small, and the precision is not high

1.double num1 = 12;
12 is of type int. When 12 is assigned to num1 of double type, the system will automatically convert 12 from int type to double type, and output 12.0
2.float num2 = 12.2; Error: cannot convent from Double to float
12.2 is a floating-point constant, the default type is double type, the range of double type exceeds the range of float, the error
is added after 12.2 F or f, 12.2 is converted to float type, and then assign the
character type: char (single Character), length 16 bits
used to save text
usage rules: enclosed in "'", and then assigned
eg: char c1 =' a ';

1. char c1 = 'Qian';
System.out.println ((int) c1);
The essence of outputting 35878 characters is integer
forced type conversion (type to be converted) variable name
char c2 = '刘';
system.out .println (c2 + c1); The output is a number, connected with "+", and converted into
a single character of addition . The internal essence is an integer. If you connect two characters with "+", jdk will default to The characters are first converted to int type, and then the addition
characters are run inside the jdk, all executed in the form of integers

Boolean type: boolean, length 1 bit is
used to indicate right or wrong, the value is only true or flase

1. boolean flag1 = 1> 2;
the order of operations: first execute 1> 2, the result is flase, and finally assign the result flase to flag1

Guess you like

Origin www.cnblogs.com/peiya/p/12679523.html