201521044091 Java Study notes Sixth week of study summary

Source: Internet
Author: User
Tags set time

1. Summary of this week's study
    • 1.1 Object-oriented learning to be over, use mind map to draw a mind map with encapsulation, inheritance, polymorphism as the core concept, and summarize the object-oriented thought.
      Note 1: Keywords and content do not ask for much, but the relationship between the concept of clear, content coverage to the core content of the object can be.
      NOTE 2: Less color, not complicated wiring, when necessary to be on the line to explain.
2. Written work 1.clone method
  • 1.1 The methods in the object objects clone are protected decorated, what do you need to be aware of when overriding the Clone method in your custom class?

     答:(1)自定义的类中要实现Cloneable接口,如果没有实现这个接口就会出现异常     (2)在覆盖时要声明为public     (3)调用的时候要用super.clone();
  • 1.2 When you design your own class, what kind of method is generally used to modify the protected? Take the job Shape as an example to illustrate.

    A: The title of the protected modified variable or method can only be inherited or used by the same package class or descendant class, in the case of job shape, we have designed the circle class and the rectangle class respectively, because the circle class and the rectangle class inherit shape type, and getperimeter and Getarea in shape are methods for calculating area and perimeter, so you can call Getperimeter () and Getarea () directly, where you can use protected decoration.

  • 1.3 Writing a simple class in the Test1 package, Employee creating a new class in the Test2 package, TestProtected and attempting to invoke the Clone method of the employee in the Test1 package in main to clone an object, can it succeed? Why?

    答:不能成功。

2. Using an anonymous class with a lambda expression to overwrite a set of objects 2-advanced-polymorphic interface topics for internal classes 5-2

Just paste the key code and run the results, the picture is not too large.

  • Anonymous inner class

      NameComparator a = new NameComparator();Arrays.sort(persons,a);for(PersonSortable2 personSortable2 : persons){ System.out.println(personSortable2);}AgeComparator b = new AgeComparator();Arrays.sort(persons,b);for(PersonSortable2 personSortable2 : persons){ System.out.println(personSortable2);}
  • LAMDA-expression

     arrays.sort ( Span class= "Hljs-selector-tag" >persons, (o1,o2) Span class= "Hljs-selector-tag" >->o1.compareto (o2.getname ())); arrays.sort ( Persons, (o1,o2) ->o1-o2.getage ();      

Experimental results:

3. Analyze the following code to answer shapeComparatorWhat does the object pointed to have to do with the comparator interface?

Comparator<Shape> shapeComparator = new Comparator<Shape>() { @Override public int compare(Shape o1, Shape o2) { //你的代码 } };

     答:让`shapeComparator`所指向的对象实现了`Comparator`接口,  public int compare(Shape o1, Shape o2)使用匿名内部类的方法进行排序。          就如同上一题,可以直接使用Arrays.sort()进行排序。
Event Handling in 4.GUI
  • 4.1 Write out the most important keywords in the event-handling model.

    答:事件:描述发生了什么;事件源:事件的产生器;事件监听器:根据某种类型的事件XXX,定义对应的事件监听器类,该类需要实现针对特定事件的特定接口。
  • 4.2 Use code and annotations to prove that you understand the event-handling model.

      PublicClassEventMainGUI1Extendsframe{Staticint count=1;PublicEventMainGUI1(String title) {Super (title); }PublicStaticvoidMain(String args[]) {EventMainGUI1 f=New EventMainGUI1 ("Hello"); F.setlayout (New FlowLayout ());final JButton b = new JButton ( "1"); //event source, create a button B.addactionlistener (new ActionListener () { Span class= "hljs-function" >public void actionperformed (ActionEvent evt) {B.setlabel (new Integer (++count). toString ()); //every click of the button, the number on the button will be added 1}); F.add (b); //Add button f.setsize (100,200); //set Form size f.setbackground (Color.pink); //set the form color f.setvisible (true); //set form Visible}}            
5. Pair programming: Object-oriented design (big job 2-very important, unfinished-2)

Continue to refine last week's project assignments. The assessment points are as follows:

    • 5.1 Try overwriting using the graphical interface.
    • 5.2 Gives a record of the same item on the code cloud for two people.
    • 5.3 What are the major changes to the project compared to last week?

       
3. Code submission record on code Cloud and PTA Experiment Summary

Topic set: jmu-java-04-Object-oriented 2-advanced-polymorphic interface inner class

    • 3.1. Code Cloud codes Submission record

In the Code cloud Project, select statistics-commits history-set time period, and then search for and

    • 3.2. PTA Experiment

function (Optional: 4-1), Programming (5-3, 5-4)
There must be an experimental summary.

    答:(1)继续学习comparable与comparator        (2)感觉接口用起来更加方便,本周实验比较简单,但是在编写的时候仍然觉得基础不扎实,有待提高。

201521044091 Java Study notes Sixth 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.