201671010116.2016-2017-6 "Java Programming" Sixth Week study summary

Source: Internet
Author: User

This week through the teacher's classroom explanation and the vacation study, the knowledge Point summarizes as follows:

1. A callback can indicate the action that should be taken when a particular event occurs.

Take the construction timer as an example:

In many programming languages, a function name can be provided, and the timer calls it periodically. However, classes in the Java Standard Class library take an object-oriented approach. Passing an object of a class to the timer, and then the timer, the timer invokes the method of the object. Because objects can carry some additional information, it is much more flexible to pass an object than to pass a function.

2. The interface is not a class, you cannot instantiate an interface with the new operator, but you can declare an interface variable, and the interface variable must refer to the class object that implements the interface.

3. One interface can contain multiple methods, you can also define constants, set public static final automatically

The inner class declared in the interface automatically becomes the static and public class.

An interface cannot contain an instance domain, nor can it implement a method in an interface. The task that provides the instance domain and method implementation should be done by the class that implements the interface.

An interface can be thought of as an abstract class without an instance domain.

When the method is called, the compiler checks to see if the method exists, and if it is an array of objects that implement the interface, the method is provided in the interface, so it is certain that the method must be present. Each class that implements an interface must provide all the methods defined in the interface.

In order for a class to implement an interface, you need 1: Declare the class to implement implements given interface 2: Define all the methods in the interface

4. Object cloning:

When copying a variable, the original variable references the same object as the copy variable, and changing the object referenced by one variable has an effect on the other variable.

All default cloning operations are shallow copies and do not clone the internal objects contained in the object.

You must redefine the Clone method to implement a deep copy of the cloned sub-object. The following judgments are made for each class:

1: Whether the default Clone method meets the requirements

2: Whether the default Clone method can be patched by invoking the clone of a mutable child object.

3: If clone should not be used

If you want to use clone, you must:

1: Implement Cloneable interface

2: Use the public access modifier to redefine the Clone method and declare the exception clonenotsupportedexception

Even if the default implementation of clone satisfies the requirement, you should implement the Cloneable interface, define clone as public, and then call Super.clone ();

The following issues are found in the learning process:

1. Ability to differentiate between shallow and deep copies in meaning, but not to use deep copies in programming

2. Programming syntax for dictionary ordering in Java I don't know how to write it.

201671010116.2016-2017-6 "Java Programming" Sixth Week study summary

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.