Java Tour (5) Basic Concept (below)

xiaoxiao2021-03-06  82

Test object's equality: although == and! = Can be used for all objects, but the resulting results are not necessarily what you want. In addition to the original data type, == and! = Both two objects are compared to the two objects of the reference, and we generally compare the content of the object, we can use the equals () method, but the method is still a comparison object in the Object base class. Reference, so you should implement this method when you compare your own class. It is good to implement the method in the vast majority of Java class libraries, and we only use it.

Short, bit operators, shift operators, three-yuan operators (? :), comma operators (Java only have applications in the for loop), String operators (automatic conversion).

Common use operators: while (x = y) {// do something}, oh, in C will not care about the mistake, Java will not appear, because the boolean in Java is False and True , Not 0 and non-0;

Type conversion: When the wide bit value is converted to a narrow bit value, Java requires you to make a clear display conversion otherwise an abnormality, thereby avoiding accidental errors.

Java has no sizeof (), and the things that have been speeched in the big section in "C high quality programming" finally have been clarified, really cool.

Control statement: if Else; for; while; do while; for (only for statement has the ability to define variables in "Control Expression", don't do this in other selection statements or cycle speech. Although variables can be defined But it can only be the same type); BREAK (jump out of the current loop); Continue (immediately enter the next round of loop); while == for (;;); switch case;

Goto later: C programmers are prudent to use it when they are worried about GOTO, or simply do not have, but sometimes it will have a good effect in place, (but I haven't used it yet. Java finally abandoned this double-edged sword while providing another similar functionality in order to make some appropriate role in proper places. Label ./// Label1: Outer-ity {inner-ity {// ...... Break; // Case 1 // ... Continue; // Case 2 // ..... CONTINUE LABEL1; // Case 3 // ... Break Label1; // Case 4 // ...}} / In Case 1 Break interrupt the internal loop, refunded to the external loop. CRS 2 Continue is still in the internal circulation. In the case 3 of Continue to Label1, restart the loop. The case 4 retired to Label1, but this time no longer entered the loop (incredible).

The above rules are equally applicable to the While cycle.

OK, now here, learn hidden realization tomorrow, the initialization and cleanup of the object.

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

New Post(0)