Java basic data type packaging classes and escape characters, type conversion

##1. Java basic data type packaging classes and escape characters
1. Each basic type of Java has a corresponding packaging class in the java.lang package
2. The function of the packaging class:
(1). Provides a series of practical Method
(2). The collection is not allowed to store basic data type data. When storing numbers, use the packaging type
(). The packaging class provides many methods.
Insert picture description here
3. The parent classes inherited by these eight packaging classes are not all the same.
(1). Integer, Byte, Float, Double, Short, and Long are all subclasses of the Number class. The Number class itself provides a series of operations that return the above six basic data types.
(2).Character belongs to Object subclass.
(3).Boolean belongs to Object subclass.
4. Boxing and unboxing:
(1). Turning the basic data type into a packaging class is called boxing.
(2). Changing the type of packaging class into a basic data type is called unboxing.
(3). After JDK1.5, automatic boxing and automatic unboxing functions are provided.
Example:
Insert picture description here
5. The Java language provides some special escape character sequences:
(1).\n: line feed (0x0a), \r: carriage return (0x0d), \f; page feed (0x0c), \b: Backspace (0x08)
(2). \0: empty character (0x20), \s: string, \t: tab, ": double quote,': single quote
(3). \: backslash, \ddd: octal character (ddd), \uxxxx: hexadecimal Unicode character (xxxx)

##二. Java data type conversion
1. Type conversion:
(1). Coercive type conversion (explicit type conversion)
1. Explicit conversion requires manual conversion from a small type to a large type requires a forced conversion, or you can use the static package class Method for conversion.
2. Integer conversion element can also be used for explicit conversion, floating-point conversion belongs to implicit conversion.
Insert picture description here
3. The conversion of other types to string types is basically done through "String.valueOf" conversion.

Insert picture description here
(2). Automatic type conversion (implicit type conversion)
1. Implicit type conversion undergoes two conversions in the conversion process, the first conversion is converted from byte type to int type, and the second time is calculated by int type. Then convert to long type.
Insert picture description here
2. Char can be implicitly converted, and the Unicode corresponding code of the "中" character can be obtained through the Unicode code.
Insert picture description here
3. The conversion from small to large is automatic conversion without loss of precision, such as from large to small, the forced conversion will have precision loss.
4. Automatic conversion rules:
(1). Small types are automatically converted to large types
(2). Integer types can be automatically converted to floating-point types, which may cause rounding errors
(3). Characters can be automatically promoted to integers
5. Coercive type conversion can cause overflow or loss of precision:
(1). Coercive type conversion must be used when converting a type with a large capacity to a type with a small capacity.
(2). The conversion of floating-point numbers to integers is obtained by discarding decimals instead of rounding.
Insert picture description here
6. Memory overflow caused by forced conversion:
(1). Original code: Use the first bit to represent the symbol, and the remaining bits to represent the value. Because the first bit is the sign bit, the value range of the 8-bit binary number is [1111 1111 ,0111 1111] is [-127,127].
(2). Inverse code: the inverse code of the complement of a positive number is itself, the inverse code of a negative number is the sign bit remains unchanged, and the remaining bits are inverted, such as the original code number [0000 0001] of the positive number 1, its inverse The code number itself is [0000_0001], the original code of -1 is [1000_0001], and the inverse code is [1111 1110].
(3). Complement: The complement of a positive number is itself, and the complement of a negative number is +1 on the basis of its inverse code. For example, the original code of a positive number 1 is [0000_0001], and its inverse code is itself [ 0000_0001], the complement of -1 [1111 1111].
(4) The binary value of 128 (original code): 00000000 00000000 00000000 10000000 The original code of 128.
(5). Converting from large to small will remove the excess, so the final number 128 is the complement of -128.
(6) The result of the forced conversion of .129 is -127, after the complement calculation result, the inverse code is performed.

Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/Pzz_Lite/article/details/112916450