20172313 2018-2019-1 "program design and data structure" Fourth Week study summary

Source: Internet
Author: User
Tags object serialization

20172313 2018-2019-1 "program design and data Structure" the fourth week study summary textbook study summary
    • List Collection
      • Ordered list: its elements are sorted by an intrinsic characteristic of the element. (an element in a sequence table has an intrinsic association that defines the order of elements)
      • unordered list: The elements do not have an intrinsic order between them, and the elements are sorted by their position in the list. (Elements in an unordered list are sorted in any way selected by the consumer)
      • Index list: its elements can be referenced by a numeric index. (The index list maintains a sequential numeric index value for its elements)
    • List in the Java Collection API
Method Description
Add (E Element) Add an element to the end of the list
Add (int index, E Element) Inserts an element at the specified index
Get (int index) Returns the element at the specified index
Remove (int index) Deletes the element at the specified index
Remove (O object) Overrides the element at the specified index
Set (int index,e element) Returns the number of elements in a list
    • List ADT
action
removefirst
removelast Remove the last element from the list
remove
first View elements at the front of the list
last view elements at the end of the list
contains
isEmpty Determine if the list is empty
size Determine the number of elements in the list
    • using an array implementation list
      • generic lists can add or remove elements from both ends, but they also have the ability to insert or delete elements from the middle of the list. Therefore, you cannot avoid moving elements. You can use the ring array method, but you still need to move the element when you insert or delete an element from the middle of the list.
      • overloading the Equals method and implementing the comparable interface is an excellent example of demonstrating object-oriented design. We can create implementations of collections to handle a variety of objects that are not yet designed, as long as they have the same definition and/or a method of providing some sort of comparison between objects in the class.
      • will have several benefits to separate private methods such as Find in the ArrayList class. First, it makes the definition of the already complex remove method very simple. Second, it allows us to use the Find method to implement contains operations and the Addafter method of Arrayunorderedlist. Note that the Find method does not throw a Elementnotfound exception, it simply returns the value (1) to indicate that the element was not found. In this way, the calling program can decide how to handle cases where the element is not found. In the Remove method, this means throwing an exception. In the Contains method, this means that the return is false.
      • in the case of the remove operation, if the element to be deleted is the last element of the list, the n comparison operation is required. It turns out that the implementation of this delete operation requires just n comparisons and panning operations, so the complexity of the operation is O (n). If you are using a ring array implementation, he simply improves performance by removing the first element in such a special case.
      • When performing a contains operation, because the method performs a linear lookup of the list, the worst case is that the found element is not in the list, in which case the n comparison operation is required, and the complexity of the operation is O (n).
      • As with remove, the comparison and panning are required each time the add operation is run, so the complexity of the operation is O (n).
    • When you use the list to implement lists
      • for a remove operation, unlike the person move operation implemented by the array, the remove operation of the linked list does not require a comment element to fill the air raid. However, in the worst case, n operations are still required, and the target element is determined not to be in the list, so the complexity of the remove operation is still O (n).
Problems in teaching materials learning and the solving process
  • Question 1: We can use arrays and linked lists to implement the list, so what is the difference between the spatial complexity and the time complexity of the ArrayList using the array implementation and the LinkedList implemented using the list?
  • Issue 1 Workaround: When each object is inserted into the list, the linked list implementation requires more space. The LinkedList class is actually a doubly linked list, so its reference takes twice times as much space. The ArrayList class is more efficient than array-based implementations in space management. This is because the ArrayList collection is variable-sized, so the space is allocated dynamically as needed. Therefore, there is no need to apply for large amounts of space at a time to create waste. The list increases the space when needed. The biggest difference between the two occurs when you access a particular index position in the list. If the index value is known, the ArrayList implementation can access any element in the list at the same time. The LinkedList implementation needs to traverse the list from one end or the other to reach a specific index value.
  • Question 2: When learning the code in the book, there is a passage:the Programofstudy and course classes implement the Serializable interface. In order for an object to be stored using serialization, its class must implement serializable. There is no method in erializable, it simply indicates that the object can be converted to a serialized representation. I don't know much about the serializable interface, and I'm not sure what serialization means here.
  • Issue 2 Workaround:

    What is the serializable interface?
    An interface for object serialization, a class whose objects can be serialized only if the serializable interface is implemented
    What is serialization?
    Converts the state information of an object into a form that can be stored or transmitted, during serialization, when an object writes its current state to a temporary store or a persistent store, and then can recreate the object by reading or deserializing the object's state information from the store
    What situations require serialization?
    When we need to transfer the state information of the object over the network, or persist the state information of the object, we need to serialize the object for future use.
    Serializable is primarily used to support two main features:
    1, Java RMI (remote method invocation), RMI allows the operation of objects on the remote machine as on the local computer, when sending a message to a remote object, it is necessary to use the serialization mechanism to send parameters and accept the return value
    2, Java Javabean,bean State information is usually configured at design time, the state information of the bean must be saved, so that when the program is run to restore these state information, which also requires the order serializable mechanism

  • Question 3: the example of a remove operation using a list of linked lists in a book has the following code, and I'm not quite sure if the condition is! Whether the Boolean value of the found itself or the current found value has changed.
if(!found)   throw new ElementNotFoundException("LinkedList");
    • Problem 3 Solution:! is a unary operator, which is a Boolean, and returns False if the operand is true, or false if the operand is true.!value if value is a Boolean value, you can perform the operation.
      The example below, if (file!=null), is if the file object is not empty, execute the IF statement below.
      if (!value.equal ("")) it is obvious that value is a string type, here! The operator does not operate on value, but rather on value.equal ("").
      The value returned by the equal () method is of type Boolean
      if (!value.equal ("")) the entire meaning is if value is not an empty string (note that it is not NULL, this is a difference), then execute if the following is the statement.
Problems in code debugging and the resolution process
    • Issue 1: During the completion of the PP6_11 programming project, when the Addafter () method is called, I will be prompted to appear with a null pointer.
    • Problem 1 Workaround: After I debug, I find that after I call the Addafter () method, if the newly added number is at the end of the list, then I have nothing to do with tail this tail pointer, tail does not really point to the tail of the list at this time. After that, when you call the Removelast () method, you cannot perform the correct operation on the tail node, and a null pointer appears.

    • Question 2: During the completion of the PP6_17 programming project, when I call the contains () method to determine if a node exists, I find that the node I have clearly deleted is still true at the time of judgment.

    • Problem 2 Workaround: When I am surprised, when I print out the entire list, I have deleted the node will not appear, I call the last () method to print the final node of the list of saved elements found also no problem. I have changed a few sets of nodes to determine whether the existence of, but also let me strange things happen, only when the judgment of the node is the last and the node is deleted when the problem occurs. I did the debug operation, and when I judged the end of the list I thought it would continue to loop and point to the node that I thought was deleted! I finally found the problem, when the end of the deletion of the node, although the tail point to the node before it, but not the tail point to null, so in the loop when the pointer is still pointing to the node to be deleted. As shown, I just have to point the tail again to null on the line.

Code Hosting

Last week's summary of the wrong quiz
    • Wrong title 1::A reference variable can refer to any object created from any class related to it by inheritance.
      A. True
      B. False
    • The wrong Problem analysis: This translation came to be very straightforward, the subclass by inheriting the parent class can call all methods of the parent class, in the test when the English is not very understanding what meaning, resulting in doing wrong.
    • Wrong Title 2: A Well-defined interface masks the implementation of the collection.
      A. True
      B. False
    • The wrong problem analysis: A well-defined interface can better help the implementation of the collection, testing without a good understanding of the meaning of the topic.
    • The wrong title 3:common features should be located as low in a class hierarchy as is reasonable, minimizing maintenance efforts.
      A. True
      B. False
    • Error Analysis: Public features should be as high as possible in a reasonable hierarchy to minimize maintenance.
Pairing and mutual evaluation
    • Blogs that are worth learning or questions:
      • Beautifully typesetting, the study of the problem is very detailed, the answer is also very thoughtful.
    • Something worth learning or doing in your code:
      • Code writing is very standardized, the idea is clear, continue to refuel!
reviewed the classmates blog and code
    • This week's study of the knot
      • 20172332
      • 20172326
      • Pairs of learning content
        • 6th Chapter List
Other (sentiment, thinking, etc., optional)

?? Have to say that the national day seven days vacation in the study efficiency is very low (do not want to learn!) Don't want to learn! Don't want to learn! )。 But still have to finish the programming task, finished writing blog. Nor did it take much effort to expand the study. In general, this seven days of study time is not enough, I hope in the past after the holidays, their learning status has picked up, continue to progress!

Learning progress Bar
lines of code (new/cumulative) Blog Volume (Add/accumulate) Learning Time (new/cumulative) Important Growth
First week 200/200 1/1 5/20
Second week 981/1181 1/2 15/20
Third week 1694/2875 1/3 15/35
Week Four 3129/6004 1/4 15/50
    • Planned study time: 15 hours

    • Actual learning time: 15 hours

Resources
    • Why some Java classes implement the Serializable interface
    • Use in Java!

20172313 2018-2019-1 "program design and data structure" Fourth 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.