20182324 2019-2020-1 《数据结构与面向对象程序设计》第6周学习总结
教材学习内容总结
1、利用继承和接口实现多态性
2、静态绑定与动态绑定
3、异常抛出的问题
4、处理异常的方法
5、try-catch 语句和 finally 子句
6、异常的传递
7、I/O 异常
8、S.O.L.I.D.原则
标准I/O流 | 描述 |
---|---|
System. in | 标准输入流 |
System. out | 标准输出流 |
System. err | 标准错误流(输出错误信息) |
教材学习中的问题和解决过程
- 问题1:方法重载与方法重写的区别
- 问题1解决方案:
区别点 | 方法重载 | 方法重写 |
---|---|---|
英文 | overload | override |
定义 | 方法名称相同,参数的类型或个数不同 对权限没有要求 | 方法名称、参数类型、返回值类型全部相同 被重写的方法不能拥有更严格的权限 |
范围 | 发生在一个类中 | 发生在继承类中 |
- 问题2:既然接口 interface 是一组常量和抽象方法的集合,不能被实例化,为什么在主方法中却可以 new 一个实例化对象
- 问题2解决方案:其实并不是对接口本身进行实例化,而是声明一个对象引用变量指向实现该接口的类的对象。
代码调试中的问题和解决过程
- 问题:课本第九章的 hourly 代码编译不通过
- 问题解决方案:将
count--
注释掉之后再编译。
代码托管
(statistics.sh脚本的运行结果截图)
上周考试错题总结
-
We compare sorting algorithms by examining
A. the number of instructions executed by the sorting algorithm
B. the number of instructions in the algorithm itself (its length)
C. the types of loops used in the sorting algorithm
D. the amount of memory space required by the algorithm
E. whether the resulting array is completely sorted or only partially sorted
解析:Different sorting algorithms require a different number of instructions when executing. The Selection Sort for instance usually requires more instructions than the Insertion Sort. So, we compare sorting algorithms by the number of instructions that each takes to execute to sort the array. We might count the maximum number of instructions that a sorting algorithm will execute in the worst case, or the minimum number in the best case, or count on average the number of instructions executed. If two sorting algorithms require roughly the same number of instructions to sort an array, then we might also examine the amount of memory space required. -
Which of the following statements is completely true?
A. If a class is declared to be abstract then every method in the class is abstract and must be overridden
B. If a class is declared to be abstract then some methods in the class may have their bodies omitted
C. If a class is declared to be abstract then all methods in the class must have their bodies omitted
D. If a class is declared to be abstract then all the instance variables must be overridden when a concrete class is derived from the abstract base class
解析:The only way to create an abstract class is to create some abstract method within the class. So, answer B is true. Certainly all the methods in an abstract class don't have to be abstract. -
Can a program exhibit polymorphism if it only implements early binding?
A. Yes, because one form of polymorphism is overloading
B. No, because without late binding polymorphism cannot be supported
C. Yes, because so long as the programs uses inheritance and/or interfaces it supports polymorphism
D. Yes, because early binding has nothing to do with polymorphism
E. none of the above
解析:While inheritance and interfaces support polymorphism, they only do so if one has late binding. But, overloading is a form of polymorphism one (method) name, multiple bodies so as long as the program uses overloading, polymorphism is in use. -
What is the efficiency of binary search?
A. n^2
B. n
C. log2 n
D. n/2
E. none of the above
解析:With each comparison binary search eliminates approximately half of the remaining data. This process continues until either the sought element is found or until all possible data has been eliminated. Since there are n data elements, the number of times one can halve the data before the amount of data is less than one element is log2 n. -
It is possible to sort an array of int, float, double or String, but not an array of an Object class such as a CD class.
A. true
B. false
解析:It is possible to sort any type of array as long as the type has some mechanism to compare two elements and determine their proper ordering (less than, equal, greater than). So, if the CD class has a compareTo method, then it would be possible to sort them. -
A Java program can handle an exception in several different ways. Which of the following is not a way that a Java program could handle an exception?
A. ignore the exception
B. handle the exception where it arose using try and catch statements
C. propagate the exception to another method where it can be handled
D. throw the exception to a pre-defined Exception class to be handled
E. all of the above are ways that a Java program could handle an exception
解析:A thrown exception is either caught by the current code if the code is contained inside a try statement and the appropriate catch statement is implemented, or else it is propagated to the method that invoked the method that caused the exception and caught there in an appropriate catch statement, or else it continues to be propagated through the methods in the opposite order that those methods were invoked. This process stops however once the main method is reached. If not caught there, the exception causes termination of the program (this would be answer a, the exception was ignored). However, an exception is not thrown to an Exception class. -
In order to have some code throw an exception, you would use which of the following reserved words?
A. throw
B. throws
C. try
D. Throwable
E. goto
解析:The reserved word throw is used to throw an exception when the exception is detected, as in: if (score < 0) throw new IllegalTestScoreException("Input score " + score + " is negative");
结对及互评
点评:
-
博客中值得学习的或问题:
- 图文并茂,有参考资料
- markdown 格式运用较为熟练
-
代码中值得学习的或问题:
- 代码格式规范,合理使用空白,便于阅读
-
基于评分标准,我给本博客打分:14分。得分情况如下:
- 1、正确使用Markdown语法(加1分)
- 2、模板中的要素齐全(加1分)
- 3、教材学习中的问题和解决过程(2分)
- 4、代码调试中的问题和解决过程(1分)
- 5、本周有效代码超过300分行的(加2分)
- 6、其他加分:
- 感想,体会不假大空的加1分
- 进度条中记录学习时间与改进情况的加1分
- 有动手写新代码的加1分
- 代码Commit Message规范的加1分
- 错题学习深入的加1分
- 点评认真,能指出博客和代码中的问题的加1分
- 结对学习情况真实可信的加1分
点评过的同学博客和代码
- 本周结对学习情况
-
结对学习内容
- 学习处理异常的基本方法
- 捕获异常,学习try-catch语句,还有finally的特点。
- 异常传播现象和异常的层次。
- throw、throws语句和异常的免检、必检。
- IO异常,以及文件的输入输出。
- 多态的运用,继承的多态。
- 接口和多态接口的使用,还有接口的层次。
其他(感悟、思考等,可选)
面向对象三要素是封装、继承、多态,在面向对象程序设计中这三个要素尤其重要,需要着重学习;异常的捕获与处理也是日常编写程序中值得注意的地方。总的来说近期的 Java 学习不管是对于当前的学习还是日后的程序设计都是十分有帮助的。
学习进度条
代码行数(新增/累积) | 博客量(新增/累积) | 学习时间(新增/累积) | 重要成长 | |
---|---|---|---|---|
目标 | 10000行 | 30篇 | 400小时 | |
第一周 | 109/109 | 2/2 | 28/28 | 学习了Java的基本语法格式,熟练使用 Linux Bash 命令 |
第二周 | 550/659 | 1/3 | 23/51 | 学习掌握JDB调试命令 |
第三周 | 1028/1687 | 2/5 | 30/81 | 学习类的编写与使用 |
第四周 | 542/2229 | 2/7 | 22/103 | 学习方法重载,类的继承、聚合等 |
第五周 | 1197/3426 | 2/9 | 15/118 | 学习 Java Socket ,了解加密算法 |
第六周 | 1344/4770 | 1/10 | 22/140 | 学习多态与异常处理 |
-
计划学习时间:20小时
-
实际学习时间:22小时
-
改进情况:
(有空多看看现代软件工程 课件 软件工程师能力自我评价表)