Dabai became the fifth day of the Java software siege lion (char, escape, integer, precision loss)

type of data

About the default values ​​of the eight basic data types

type of data Defaults
byte,short,int,long 0
float,double 0.0
boolean false [true is 1, false is 0 in C language]
char \u0000

Member variables are not manually assigned, and the system will default to assign [local variables will not]
The default values ​​of the eight basic data types are all aligned with 0.

1, char type

A Chinese occupies 2 bytes, and the char type is exactly 2 bytes.
So the char type variable in Java can store a Chinese character
"ab" is a string and cannot be enclosed in single quotes

2. The escape character (\)

\: Backslash has an escape function in the Java language

\n:
The difference between a newline character System.out.println and print : a newline after println output, print means output, but no newline.
\t: Tab character, that is, the Tab key.
\': ordinary single quote
\ \: ordinary backslash
\ ": ordinary double quote

How to output "backslash character" in the console?

char k='\\';
System.out.println();

The first backslash has an escape function, and the following backslashes are escaped into p ordinary backslash characters.
Conclusion: So in Java, two backslashes represent an ordinary backslash character

How to output an ordinary single quote in the console?

char a='\''; / / 反斜杠具有转义功能,将第二个单引号转换成普通的单引号字符,第一个单引号和最后一个单引号配对。
System.out.println(a);

3. Integer type

1 The "integer literal" in the Java language is treated as an int by default. To make this "integer literal value" be treated as a long type, you need to add 1/L after the "integer literal value". It is recommended to use uppercase L.

2 There are three ways to express integer literals in the Java language:

The first method: decimal [is a default method] int i=10
The second method: octal [When writing an octal integer literal, you need to start with 0] int i=010 The
third method: Hexadecimal [When writing a hexadecimal integer literal, you need to start with 0x] int i=0x10

long y=2147483648L

long y=2147483648
2147483648 is an oversized integer, which is treated as 4 bytes of int type, but the literal value exceeds the range of int type.
Solution:
add L after the literal value and treat it as a long type, y is a type variable , There is no type conversion in the above program.

4. Loss of accuracy

There are three representations of computer binary:

Original code
Inverse code
Complement code

In any case, the computer adopts the form of complement when the bottom layer represents and stores data.

The complement of a positive number: the same as the original code.
The complement of a negative number: the absolute value of the negative number corresponds to all the binary digits of the binary inverted, plus 1

When the face value of an integer number does not exceed the value range of byte, short, and char, the literal value can be directly assigned to a variable of type byte, short, and char. This mechanism is allowed by SUN for the purpose of facilitating programmer programming.

char cc=65535 //Pass
char cc=65536 //Compile error

Sub-total of life events: I was ruthlessly rejected an interview in my life. Is it because I am a graduate student? To harm, you still need to improve your skills first, wait until the result of the postgraduate entrance examination is finalized, and then talk about finding a job or re-examination for postgraduates. I can't say whether I can pass the re-examination line o(╥﹏╥)o

Guess you like

Origin blog.csdn.net/qq2632246528/article/details/112426365