20145129 Java Programming 4th Week of study summary

Source: Internet
Author: User

20145129 "Java Program Design" The 4th Week study summary textbook Learning content Summary
  • Inheritance and polypeptide
      The
      • inheritance common behavior
        1. inheritance is to avoid duplicate definitions of common behavior among multiple classes. (Promote the same code to the parent class) The
        2. keyword extends: Indicates that this class extends the behavior of another class as inherited.
        3. Advantage: You only need to modify the parent class for maintenance, inheriting the subclass of the parent class without modification.
      • polymorphism and is-a
        1. is-a: Java subclasses can inherit only one parent class, because there is a "is-a" relationship between the subclass and the parent class, and Chinese is "one."
        2. uses "is a" to determine if a compilation fails and to play (Cast) as a syntax for a program to shut up.
        3. and pay attention to the actual types of objects referenced, determine when to play a success, and when to throw "classcastexception" (failure).
        4. Polymorphism: Manipulate multiple types of objects using a single interface, which refers to an actionable method on an object.
      • redefine behavior
        1. after inheriting the parent class, define the same method deployment as the parent class, but the execution content is different.
        2. Callout @override: Indicates that the compiler is required to check if the method really redefined a method in the parent class, and if not, a compilation error is thrown.
        3. to get the method definition in the parent class, you can add the Super keyword before calling the method and cannot be defined as private.
        4. can only expand but not shrink the method permissions in the parent class.
        5. When redefining a method, the other part must be fully consistent with the method signature in the parent class, in addition to the ability to define a keyword with a larger permission.
        6. When redefining a method, it can be compiled if the return type is a subclass of the method return type in the parent class.
      • Abstract method, abstract class
        1. Abstract abstract Method: A class in Java that contains abstract methods must be marked abstract in front of class to indicate that this is an incomplete and undefined class. (If there is really no program code action in a method block that can be used in this way)
        2. creates an instance with an abstract class that throws a compilation error. If the
        3. subclass inherits an abstract class, there are two ways to abstract the method: First, continue to mark the method as abstract, and manipulate the abstract method.
  • Inheritance syntax details
      • Protected members
        1. In different package classes only subclasses can be accessed directly.
        2. There are actually 4 permission scopes in Java, except the one previously learned, where the default is that the package scope is not accessible when the different package classes are not defined by the keyword.
      • Redefined details (refer to above)
      • constructor function
        1. Constructors can be overloaded, and multiple constructors can be overloaded in a parent class, and a parameterless constructor in the parent class is called by default if the subclass constructor does not specify which constructor to execute in the parent class.
        2. If you define a constructor with parameters, you can add a parameterless constructor, even if the content is empty, and increase the use of elasticity.
      • Final keyword
        1. After specifying the value of the variable, you do not want to change the value of the variable, you can declare the variable with the final qualification, if you later modify the final variable, a compilation error occurs.
        2. If the object data member is declared final, but is not explicitly used = specified value, that indicates the delay of the object member's designation, in the constructor execution process, must have the value of the data member to specify the action, or compile the error.
        3. Class is defined with the final keyword, which means that the class is the last, and there are no subclasses, that is, not inherited.
        4. Defining a method can also qualify the method as final, indicating that this is the last time the method is defined, and the subclass cannot redefine the final method.
      • Java.lang.Object
        1. If you are defining a class without inheriting any classes using the Extends keyword, it must be inherited java.lang.Object.
        2. Java.lang.Object is the top-level parent class for all classes.
        3. (?? The part that defines the ArrayList class is somewhat blurred. )
        4. Redefine toString ()
        5. Redefine Equals ()
      • About garbage collection
        1. For objects that are no longer useful, the JVM has a garbage collection mechanism, and the collected garbage objects occupy a memory space that is freed by the garbage collector.
  • Interface and polymorphism
    • Interface definition Behavior
      1. You can use the interface keyword to define behavior in Java.
      2. Interfaces can be used to define behavior but do not define operations.
      3. class to manipulate interfaces, the Implements keyword must be used. When you manipulate an interface, there are two ways to define the interface: First, the method defined in the Operation interface, and the method as abstract.
      4. The operation interface represents the "owning behavior".
    • Polymorphism of behavior
      1. Similar to the polymorphism mentioned above. But in the judgment of "is a" to "have ... Behavior ".
    • Address demand changes
      1. A class can manipulate more than two classes, which means more than two behaviors.
      2. A class can inherit a class at the same time and manipulate some interfaces.
      3. The program needs to be written to ensure flexibility.
  • Interface Syntax details
    • The default of the interface
      1. When a method in an interface is not operational, it must be public and abstract, and the compiler will automatically add it at this point, and the default is publicly.
    • Anonymous inner class
      1. When there is a need to temporarily inherit a class or manipulate an interface and establish an instance, because such subclasses or interface operation classes can only be used once, and you do not need to define names for those classes, you can use anonymous inner classes at this time.
    • Enumerate constants using enum
      1. Using the Enum enumeration constants, the enum actually defines a special class that inherits from Java.lang.Enum, which is handled by the compiler, and the direct writer inherits the Enum class and is rejected by the compiler.
      2. The enum actually defines the class, and the constants enumerated in the enum are actually "public static final", and as an enumeration type instance, it is not possible for the writer to instantiate the enumeration type directly because the constructor permission is set to private and only the class can be instantiated.
Problems in teaching materials learning and the solving process

In the sixth chapter of the study on the definition of the ArrayList category that part is somewhat vague, specifically still ask classmates.

Problems in code debugging and the resolution process

There was no big problem in writing the code. (For code hosting)

Other (sentiment, thinking, etc., optional)

After the actual operation of the code in the book, it is found that not all the code should be written again ... Always after writing a piece of code to read the book found that the code does not make much sense, and the real need to operate the part is still behind, so efficiency is a lot lower. For this week's study I basically spend 80% of my spare time in learning Java is not only reading books and watching videos and surfing the Internet to understand the contents of the book however, although the two chapters are not the first few chapters but the amount of information is very large need to contact the first two chapters, at the end of this week I can not completely digest it. It means I tried my best.

Learning progress Bar

| | Lines of code (new/cumulative) | Blog volume (Add/accumulate) | Learning time (NEW/cumulative) | Important growth |

| -------- | :----------------:|:----------------:|:---------------: |:-----:|

| Target | 3000 Rows | 15 articles | 300 Hours | |

| First week | 50/50 | 2/2 | 14/14 |

| Second week | 100/150 | 1/3 | 10/24 |

| Third week | 300/450 | 1/4 | 15/39 |

| Week Four | 350/800 | 1/4 | 50/74 |

20145129 Java Programming 4th Week of 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.