20175318 2018-2019-2 "Java Programming" six weeks learning summary

20175318 2018-2019-2 "Java Programming" six weeks learning summary

Learning content summary

This week learning the chapters VII and X, the main contents are as follows:
Chapter 7:

  • Learning another member of the class: inner classes, inner classes include classes called class fitted inside the class.

  • Fitted inner classes and class relations:
    • Class member variables are still valid fitted inside the class, inner class method can also be fitted class method invocation
    • Internal class not declare variables and class methods, class can be fitted inside the object class declaration class member as fitted
    • Only his inner class fitted using class
  • Class member variables fitted within the class are still valid, inner classes and make the interaction more convenient fitted class

Chapter X:
the program currently running, you may need to read from an external storage medium or other programs required data, which requires the use of an input stream. Pointing input stream is referred to as its source, the program reads the input data stream by the source. On the other hand, after the program processing the data may need to be written to the result of the process in a permanent storage medium or transferred to other applications, which requires the use of the output stream. Output stream directed referred to its destination, the program stream output by the data transfer to the destination. Although IO streams associated with frequently accessed disk files, but can also be a source and destination keyboard, memory, or the display window.

Code debugging and problem solving in the process

  • Problem:
    Upon completion of the job class definition does not cover the equalsmethod of
  • Problem Solution:
    equalsdid not learn before rewriting method too, and do exercises on the book before are mainly talking about how to use equalsthe method for how to rewrite not mentioned. I'm online reference "override equals method" of this blog, to complete this part of the code:
public boolean equals(Object obj) {    //覆盖了父类Object中的equlas方法。
      if (this == obj)  //判断是否为同一对象
         return true;
      if (obj == null )   //判断是否为空
         return false;
      if (getClass() != obj.getClass())   //判断是否属于同一个类
         return false;
      Book book = (Book) obj;   ////如果类型相同,比较内容
      if (bookName == null) {
         if (book.bookName != null)
            return false;
      } else if (!bookName.equals(book.bookName))
         return false;
      if (author == null) {
         if (book.author != null)
            return false;
      } else if (!author.equals(book.author))
         return false;
      if (press == null) {
         if (book.press != null)
            return false;
      } else if (!press.equals(book.press))
         return false;
      if (pubDate == null) {
         if (book.pubDate != null)
            return false;
      } else if (!pubDate.equals(book.pubDate))
         return false;
      return true;
   }

   public int hashCode() {    //重写hashcode
      final int prime = 31;
      int result = 1;
      result = prime * result + ((bookName == null) ? 0 : bookName.hashCode());
      result = prime * result + ((author == null) ? 0 : author.hashCode());
      result = prime * result + ((press == null) ? 0 : press.hashCode());
      result = prime * result + ((pubDate == null) ? 0 : pubDate.hashCode());
      return result;
   }

Cloud link code

https://gitee.com/lhr0321/20175318_JAVA

Code Screenshot

Guess you like

Origin www.cnblogs.com/L1079991001/p/10992581.html