This chapter needs to summarize not much, but the details of things need attention, some are easy to forget.
Chapter III
Directory:
- 3.1 Simpler Print Statements
- 3.2 Using Java Operators
- 3.3 Priority level
- 3.4 Assigning values
- 3.5 Arithmetic operators
- 3.6 Auto Increment and decrement
- 3.7 Relational operators
- 3.8 Logical operators
- 3.9 Direct Constants
- 3.10 Bitwise Operators
- 3.11 Shift operator
- 3.12 Ternary operator If-else
- 3.13 string operator + and + =
- 3.14 mistakes often made using the operator
- 3.15 Type conversion operators
- 3.16 Java no sizeof
- 3.17 Operator Summary
- 3.18 Summary
3.2 Using Java Operators
The operators are "=", "= =" and "= =" to manipulate all objects.
3.4 Assigning values
If the object uses C=d, then both C and D point to the object that originally had only d pointing.
When T1 = T2 (aliasing), then modifying T1 also changes the T2, because T1, T2 contain the same reference, point to the same object.
If you want to keep two objects independent of each other, this t1.level = T2.level; 。
3.6 Auto Increment and decrement
A = 15,++a 、--a:system.out.printf ("~output:" + a++); // ~ output:15 = 15,a++, a--: System.out.printf ("~output:" + ++a); // ~ output:16
3.7 Relational operators
The above two integer objects are the same content, but the references are different, and = = and! = Compare the object references (the base type directly compares the values, and there is no reference). To compare object content, use the Equals () method.
Note:The default behavior of the Equals () method is to compare references, so you must overwrite the e quals () method in your new class, otherwise you will not see the effect you want. Most Java class libraries override the Equals () method so that you can compare the contents of an object. Examples are as follows:
3.9 Direct Constants
Hex: Prefix 0x, octal: prefix 0, binary does not have a direct constant representation method.
Exponential notation: 1.39e-43f indicates that 1.39 * 10-43 e stands for "power of 10".
3.10 Bitwise Operators
The bitwise operator is a binary bit (bit), and Java is designed to be embedded in the TV set-top box, so this bottom-oriented operation is still preserved. However, it is seldom used as a operator.
& with | or ^ xor/non, if the Boolean type is treated as a single-bit value, the non-bitwise (~) cannot be executedin order to avoid confusion with logical not. Bitwise operators are similar to logical operators, but have no short-circuit effects.
3.11 Shift operator
An operand is a binary "bit" that can only be used to handle integer types (not Boolean types).
Negative numbers must first be converted to complement before the operation is not introduced.
Shift Left ( n 0 of the high position is shed, minimum bit complement n 0) <<:
The binary form of 11 is 1011 11<<2 after the binary is 101100 so 11<<2 = 44 is equivalent to an integer 11*2n
Shift Right (the low n digits are shifted out, and N 0 in the high position) >>:
The binary form of 11 is 1011 11>>2 after the binary is 0010 so 11>>2 = 2 is equivalent to an integer 11/2n
Unsigned right-shift operator >>>: Move the n number to the lower position, either positive or negative, and fill n 0 at the high
Note: unsigned right shift (>>>) for a byte or short value may not be the correct result. They are first converted to the int type, then right-shifted, then truncated, assigned to the original type, in which case the result of 1 can be obtained, such as the following example:
Bit operation assembly level execution speed is very fast, so the interview may ask: In Java in the most efficient way to calculate 2 times 8 equals a few? Answer: 2 << 3
The actual meaning is not big, this point speed increase meaningless , code is not intuitive.
3.16 Java no sizeof
The sizeof () operator is not required for Java because all data types are the same size in all machines, regardless of the "porting" issue.
Summary: Too easy knowledge points, and often used to not appear in the notes, all appear as well as re-reading.
Today in a software to see such a spit groove
See the knowledge points in the second chapter of the idea of Java programming immediately:
When a variable is used as a member of a class, Java ensures that its default value is given to ensure that the base type member variable is initialized (the initial value may not be what you want, preferably initialized yourself). Note that the default initialization method does not apply to field variables that are not a class, forget initialization, and Java will return an error to you at compile time.
Stack: In the Universal RAM (Random Access Register), the Java compiler must know the size and life cycle of all data stored in the stack, the "stack pointer" moves down the allocation of new memory, moving up to free memory, the speed of the second only to register, Basic data types and references are stored here.
Local variable runs are allocated in the stack, the volume is large, the life cycle is short, if the virtual machine to each local variable is initialized, is a big overhead, but the variable is not initialized to the default value is not safe to use.
Reprint Annotated : http://www.cnblogs.com/wujiancheng/
Java Programming Thought summary note the first chapterJava Programming Thought summary Note Chapter 2
Java Programming Thought summary Note Chapter 3