Java programming ideas-Chapter 3, 4 Operators & Control Flow

1, the difference between == and equals()

    Reference type == compares the reference of the object instead of the value of the object, and equals() compares the value of the object instead of the reference of the object. But the default behavior of equals() is to compare references. So unless you override the equals() method in your new class, it's still a reference. Covering will be introduced in the subsequent chapters.

2. If the "direct constant" is used in the program, the compiler can know exactly what type to generate, but sometimes it is ambiguous. If this happens, the compiler must be properly "guided." float f1 = 1f;

The uppercase and lowercase L stands for long, the uppercase D stands for double, and the uppercase L stands for long.

The beginning of 0x represents 16 progress; the beginning of 0 represents octal.

3. Among the bitwise operators, ~ is a unary operator and cannot be used in conjunction with "=".

4. << shift left, add 0 on the right, >> shift right, add the number of sign bits on the left. Java introduces an "unsigned" right shift operator >>>, which uses "zero extension": regardless of positive or negative, 0 is inserted in the high position.

5. Shift the values ​​of char, byte, and short types. Before shifting, they will be converted to int.

6. The java compiler is wrong to convert the int value into a boolean value. It does not allow us to randomly use one type as another type.

7. There is no sizeof operator in java. This is because the size of all data types in java is the same on all machines, so there is no need to consider the issue of transplantation. The main purpose of sizeof in c/c++ is to consider porting. One computer may use 32 bits to store integers, and another machine may use 16 bits.

8. The foreach syntax is the same as the range for in C++11.

9. Pay attention to the penetrating execution of switch.

 

Guess you like

Origin blog.csdn.net/xiaoan08133192/article/details/108332190