20172313 2017-2018-2 "Program Design and Data Structure" Week 8 Learning Summary

20172313 2017-2018-2 "Program Design and Data Structure" Week 8 Learning Summary

Textbook learning content summary

  1. Learned the concept of late binding in polymorphic references.
  2. Learn how to use inheritance to implement polymorphism.
  3. Learn how to use interfaces to implement polymorphism.
  4. Preliminary learning algorithm, understanding and learning two methods of sorting elements in an array.
  5. Learned two methods of finding a specified target element in a set of elements.
  6. Learn to judge when to use polymorphic design to solve problems, and appreciate the benefits of using polymorphism.

Problems and Solving Processes in Teaching Materials Learning

  • Question 1: It feels strange when I just started learning to use interfaces to implement polymorphism, because when I originally learned interfaces, I knew that an interface in Java is a collection of constants and abstract methods, and an interface cannot be instantiated. I was confused when I saw the example Speak special() = new Philosopher(); on the tree, and I didn't understand why the interface could be instantiated.
  • Solution to problem 1: With the deepening of learning, I learned that this is not an instantiation of the interface itself, but is used to declare an object reference variable to point to the object of the class that implements the interface.
  • Question 2: There is such a piece of code when learning to sort a set of elements
 public static void selectionSort(Comparable[] list) {
        int min;
        Comparable temp;
        
        for (int index = 0; index < list.length - 1; index++) {
            min = index;
            for (int scan = index + 1; scan < list.length; scan++)
                if (list[scan].compareTo(list[min]) < 0)
                    min = scan;
           
            // Swap the values
            temp = list[min];
            list[min] = list[index];
            list[index] = temp;
        }
    }
  • The temp here is an object of the Comparable class, I don't understand why it can be assigned with list[min].
  • Solution to problem 2: After continuing to learn the knowledge from the book and combining with the video learning on the blue ink cloud, the list array here is a formal parameter, and the actual parameter array passed in is saved one by one Contact objects, here It is the use of polymorphism to make object reference variables point to other objects.
  • Question 3: When I started to learn the binary search method, when I saw the example given in the book, I thought that if the number of elements to be searched is even, there will be two midpoint values, so how to take the midpoint at this time ? Although it is explained later in the book, I don't quite understand what the book wants to express.
  • Solution to problem 3: Mr. Wang answered this question in class. Because the midpoint is taken, the average of the two numbers is converted into an int line by type conversion. At this time, the decimal part is ignored. , which is what the book says to take the first of the two midpoints as the new midpoint.

Problems and solutions in code debugging

  • Question 1: When I was working on the programming project pp10.4, I found that the results obtained by sorting by the two methods were inconsistent.

  • Solution to problem 1: I checked the code of the algorithm, because it was rewritten according to the example in the book, so I put my eyes on the test code. After careful inspection, I found that when I did the second sorting When the actual parameters passed in are wrong, the code can be successfully run by correcting the parameters.

  • Question 2: Exception in thread "main" java.lang.NullPointerException is prompted when running the code when working on the programming project pp10.5

  • Solution to problem 2: At the beginning, I thought it was because I didn't write the sorting method in the Movies class, and I completed the sorting operation by calling the methods of other classes during the test. I modified the code, but the problem is still not solved.


  • I really couldn't find any problem, so I turned to Baidu and found the following explanation. I started to follow this idea to find my problem. It turned out that there was a code to expand the capacity of the array in the example in the book. Since the initialized size of the array is 100, when sorting, the array does not store all elements, and some It is empty so it caused the above problem. I modified this piece of code as follows, and the problem was solved.

code hosting

Summary of last week's exam mistakes

  • 错题1: Inheritance through an extended (derived) class supports which of the following concepts?
    A . interfaces
    B . modulary
    C . information hiding
    D . code reuse
    E . correctness
  • Parsing By extending a class and inheriting it, the new class does not have to reimplement any of these inherited methods or instance data, saving the programmer's workload. So code reuse is the benefit of reusing other code for extending it for your needs.
  • Reason uh...I don't understand what the title is trying to convey.
  • 错题2: Which of the following is an example of multiple inheritance?
    A . A computer can be a mainframe or a PC
    B . A PC can be a desktop or a laptop
    C . A laptop is both a PC and a portable device
    D . A portable device is a lightweight device
    E . Macintosh and IBM PC are both types of PCs
  • Resolution Multiple inheritance means that a given class inherits from multiple parent classes. Of those options listed above, laptops inherit features from PCs and portable devices. The answers in A, B, and E are all examples of single inheritance, where a class has at least two subclasses (in A, computer has children mainframe and PC, B, PC has children desktop and laptop, E, PC Has kids Macintosh and IBM PC). Answer D represents an attribute of a class.
  • Cause Confusion about the concept of inheritance.
  • 错题3: A variable declared to be of one class can later reference an extended class of that class. This variable is known as
    A . protected
    B . derivable
    C . cloneable
    D . polymorphic
    E . none of the above, a variable declared to be of one class can never reference any other type of class, even an extended class
  • Analysis Polymorphism means that variables can take many forms. In the ordinary case, Java is strongly defined that a variable once declared of a certain type can never be changed to a different type. This is an exception, a polymorphic variable can be a derived class of any type (although not at the same time, a variable can change from one type to another).
  • Reason I thought this question was asking what type of variable should be declared before, but I didn't understand the meaning of the question.
  • 错题4: If you instantiate an Abstract class, the class or object you wind up with
    A . is also an Abstract class
    B . is a normal class
    C . is an Interface
    D . is a reference to an Object
    E . can't exist you cannot instantiate an Abstract class
  • Resolution You can only instantiate concrete classes not abstract classes. But you can extend abstract classes and interfaces.
  • The reason I understand the idea as what is the type of the subclass of the abstract class... (bad English is a flaw)

Pairing and mutual evaluation

  • Worth learning or questions from the blog:
    • The layout is beautiful, the research is very detailed, and the answers are very comprehensive.
  • Worth learning or problems in the code:
    • The code is well written and the thinking is clear, keep going!

Reviewed classmates blog and code

  • Pair study this week
    • 20172332
    • Pair learning content
      • Chapter 10 Polymorphism

other

I feel that this week's learning tasks have been improved to a certain extent compared to last week, and it is more difficult to learn, but at the same time, I am more aware that Java learning can be improved through continuous personal practice and practice. The content and what the teacher talks about in class is just theory, it can only assist you in your study, and you cannot rely entirely on listening to lectures in class and devour books. At the same time, in this week's test, I also realized a problem. Many of the mistakes in the questions were caused by my misunderstanding of the meaning of the questions due to the inaccurate translation of the questions. I hope to continue in the future. Improve your English ability. I also hope that I can continue to improve through hard work in the future!

learning progress bar

Lines of code (added/accumulated) Blog volume (new/cumulative) Study time (added/accumulated) important growth
Target 5000 lines 30 articles 400 hours
the first week 126 1/1 20/20
the second week 388/466 1/2 15/35
The third week 706/1162 1/3 17/52
the fourth week 1104/2266 1/4 20/72
fifth week 1126/3392 1/5 15/87
Week 6 906/4298 1/6 20/107
Week 7 1233/5531 1/7 20/127
eighth week 1391/6922 1/8 24/151
  • Planned study time: 24 hours

  • Actual study time: 24 hours

  • Improvement situation:
    It has been nearly half a semester since the start of school. Although my learning status has improved to a certain extent compared to when the school started, I still feel that I have not enough time to study and my attitude is not correct. of learning is learning more Java in life,I love Java, Java makes me happy, Java makes me happy!

References

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325166408&siteId=291194637