201521123092 Java programming Fifth week of study summary

Source: Internet
Author: User
Tags access properties comparable set time

1. Summary of this week's study

#1.1 Try using the mind map to summarize the knowledge points about polymorphism and interfaces.

2. Written work

#1. Code reading: Child compressed in-package source code
# #1.1 com.parent The Child.java file in the package can be compiled and passed? Which sentence will be wrong? Try to correct the error. and analyze the output results.

A: cannot compile through. Error in Syatem.out.println (i). The parent Class I is defined as private, so I cannot be used in child subclasses.

To change the private to protected, the output is: 1 2 2 1 1 2 1

# #1.2 Outofparentpackage.java In another package, can it be compiled and passed? What errors are prompted? Analyze the cause.

A: cannot compile through. Hint error: The type Parent is not visible.

Reason for analysis: The parent class cannot be accessed outside the package. You can add public in front of the parent to increase permissions.

# #1.3 Answer: What should I do if I want to access properties or methods that are protected decorated?

A: Other classes or subclasses within the same package are called.

#2. Abstract Advanced: Reading Guessgame abstract class design and use of source code

# #2.1 Guess the Pre-transformation code is simple, and the modified code uses abstract classes and abstract methods to look complicated, so what is the benefit of such a transformation?

A: Before the transformation, do not use abstract classes, only console output, after the transformation of the use of abstract classes, can be output through the console, but also through the dialog box graphical interface and other input.
# #2.2 What should you do if you want to transform the game into a graphical interface?

A: Design a class for a graphical interface.
# #2.3 in combination with this example, when do you think you should use abstract?

A: Abstract is primarily used for abstraction classes. An abstract class must be inherited, and it can only be used as a parent class for other classes. Abstract methods only declarations, no specific definitions, we can according to the specific requirements of the topic specific definition.
# #2.4 Important: In this case, what is the change and what is the invariant? Attempt to combine abstract, inheritance and other concepts to illustrate.

A: The change is the specific method of operation, the way the input and output changed. The functionality of the code implementation has not changed.

#3. Comparable and comparator
# #3.1 describes the purpose of the comparable interface. Why does a class implement the comparable interface so that it can be sorted directly using Arrays.sort?

A: The comparable interface can implement an overall sort of object for each of his classes. A class implements the comparable interface, which shows that his instance has an intrinsic sort relationship and can be sorted directly with Array.Sort.
# #3.2 Why do I need an comparator interface with the comparable interface?

A: Two interfaces are used to implement sorting in the collection. The limitations of the comparable interface can only be sorted by one rule, and the comparator interface may be sorted in a variety of ways, enriching the comparable interface.
# #3.3 Optional: Use an anonymous inner class, lambda expression to implement PTA programming 5-2.

#4. Interface-oriented case studies
Read the Case-studentdao.zip case
# #4.1 draw a class diagram that describes the role of each class and interface.


# #4.2 What is the difference between Studendaolistimpl and Studentdaoarrayimpl?

A: Studendaolistimpl is implemented with ArrayList, Studentdaoarrayimpl is implemented with an array.

#5. What is interface-oriented programming? What are the benefits of interface-oriented programming?
Discuss the analysis with the code of Test.java in topic 3 and 4. Do not copy Baidu intact!

A: interface-oriented programming is to first extract the customer's business, as an interface. The specific implementation of the business is accomplished through the implementation class of the interface.

Benefit: When modifying a module, you do not have to make big changes to other modules.

#6. Pair programming: Object-oriented design (big job 2-very important)

Content: Use Java code to complete the object-oriented design work done last week, you need to have a preliminary interface. Realize the function as simple as possible, few but good, only contains the necessary functions, do not pursue high Daquan.
Write: Class diagram (as concise as possible, not too many sub-categories, two can), system common function description, key code and interface
Form: Two people rely on the code cloud cooperation to complete. Please post your study number, name and division of duties here.
Note: After a few more classes to talk about Java Graphics interface programming, the time to upgrade the system to a graphical interface. The business logic part of the system should not change much, the change is the input and output part. So when coding, input (Scanner) and output (System.out) code, please do not bind it to a business handler function to die.

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

#3.1. Codes Cloud Code submission record

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

#3.2. Experimental Summary of PTA experiment

5-1 sort using the interface comparable just learned. Once the comparable interface is implemented, you can use Arrays.sort to sort the personsortable directly.

5-2 Learn how to use comparator to write Namecomparator and Agecomparator separately.

201521123092 Java programming Fifth 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.