Thinking in Java Reading Note 3

xiaoxiao2021-03-06  70

Control process

1. Give Primitive assignments to copy the content from one place to another, without affecting each other. To assign an Object, it is a copy of Object's Reference, for example,

Two objects C and D, C = D, the results C and D point to the object that is only D pointing, that is, C and the original pointing object is detached.

2. Java does not allow the number as Boolean, this is different from C.

3. == and! = Compare two object references, that is, two references point to the same object. Equals () compares whether the actual content of the two objects is equal.

For example: integer a = new integer (9);

Integer b = new integer (9);

a == b; // false

a! = b; // true

a. Equals (b); // true

But if it is a class defined:

Yourclass a = new Yourclass ();

YourClass B = New Yourclass ();

A.i == B.I == 9;

a == b; // false

a! = b; // true

a.equals (b); // false

Because Equals () default behavior is the comparison object's Reference, you must override the equs () method of the Override class to compare content.

The vast majority of Java class libraries are equally equals (), so they will compare the contents of the object rather than reference. So, the class defines the best class.

Also rewrite the equsls () method to get the correct behavior.

4. Break ignores the loop code that has not been executed and exits the loop. Continue will skip the code that has not yet executed, interrupt this loop, and enter the next loop.

5. In Java, the only place that can be labeled is the outside of the cycle statement, and must be placed directly outside the loop statement, and they can't have anything else. such as:

Label1:

Outer-ity {

Inner-ity {

// ....

Break; // 1

// ....

CONTINUE; // 2

// ....

Break label1; // 3

// ....

Continue label1; // 4

// ..........

}

}

In the above example, 1 exits the inner layer cycle, continue the next loop from the outer layer cycle; 2 Introducing this cycle starts the next loop from the inner layer cycle; 3 exiting the inner layer cycle and the outer cycle, will not enter again cycle;

4 Return to the label and continue the outer loop.

6.switch statement decides which code to run according to the "value of integer expressions". The value of Integral-Seletor can only be int or CHAR type, string and floating point, etc. cannot be used in Switch. format:

Switch (Integral-selector) {

Case Integral-Value1: Statement; Break;

Case Integral-Value2: statement;

..........

DEFAULT: STATEMENT;

}

7. When converting Float and Double into an integer INT, it always cuts the decimal decimal. For example: int a = (int) 0.7 // a = 0

4.Math.random (); value domain is [0, 1).

转载请注明原文地址:https://www.9cbs.com/read-85258.html

New Post(0)