Java journey (5) Basic concepts (II)

Source: Internet
Author: User

Equality of test objects: Although = and! = Can be used for all objects, but the result may not be what you want. Except for the original data type,
= And! = When two objects are compared, the reference of the two objects is compared, but what we need to compare is the object content. We can
The equals () method is used, but the default behavior of this method in the object base class is to compare the reference of the object, so the object of the self-created class is compared.
You should implement this method by yourself. Fortunately, the majority of Java class library classes have implemented this method, and we just need to use it.

Short answer, bitwise operator, shift operator, ternary operator (? :), Comma operator (Java only applies to the for loop), string
(Automatically converted and then added ).

Common Errors in operators: While (x = y) {// do something }.
This occurs because the values of Boolean in Java are false and true, rather than 0 and non-0;

Type conversion: When the width value is converted to a narrow value, Java requires you to explicitly convert the display value. Otherwise, an exception is generated, thus avoiding unexpected errors.

Java does not have sizeof (). What I once talked about in "C ++ high quality programming" was finally stunned.

Control statement: If else; For; while; do while; For (only the for statement can define variables in the control expression. Never
Do this in other select statements or loop statements. Although variables can be defined, they can only be of the same type); break (jump out of the current loop)
; Continue (enter the next loop immediately); While (true) = for (;); Switch case;

Later in Goto: when programming, C ++ programmers are very cautious about using goto because they are worried about its side effects.
Good results are appropriate (but I haven't used it yet). Java finally abandoned this double-edged sword and provided another similar function.
So that you can play an appropriate role in a proper place. Label.
///////////////////////////////
Label1:
Outer-Iteration
{
Inner-Iteration
{
//......
Break; // case 1
//......
Continue; // case 2
//......
Continue label1; // case 3
//......
Break label1; // case 4
//......
}
}
/////////////////////////////////
In Case 1, break breaks the internal loop and moves back to the External Loop. In Case 2, continue is still circulating internally. In case 3, continue to label1
And start the loop again. Case 4 is removed to label1, but this time it is no longer in a loop (incredible ).

The preceding rules apply to the while loop.

OK. Here we are today, we will learn how to hide and implement object initialization and cleaning tomorrow.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.