教材学习内容总结
本周学习第十一章异常和第十二章
第十一章-异常
| System.in |
标准输入流 |
| System.out |
标准输出流 |
| System.err |
标准错误流 |
第十二章-递归
- 递归是一种允许一个方法调用自己以达到最终目的的编程技术。
- 任何一个递归定义中必须有有称为基本情况的非递归定义部分,才能使递归最终结束。
- 每一次对方法的递归调用,都会创建新的局部变量。
- 递归和迭代
- 直接递归和间接递归
- 迷宫问题和汉诺塔问题
教材学习中的问题和解决过程
似乎书上给出的错误并没有像是系统自带的,难道是理解的偏差?
同时给出了例子,throw一般会用于程序出现某种逻辑时程序员主动抛出某种特定类型的异常,throws是方法可能抛出异常的声明。(用在声明方法时,表示该方法可能要抛出异常)


- 问题3:SR11.18解答中提到的对象fw和对象bw以及其他包括缓冲性能种种概念
- 问题3解决方案:在JDK中搜索到了close方法

我理解的该方法的意思就是,当调用该方法之后,将停止流对文件的输入或输出(关闭该流),清空缓存区的内容(释放与之关联的所有系统资源)
应该这里提到的fw和bw分别是指FileWriter和BufferedWriter吧,FileWriter 用于写入字符流而BufferedWriter将文本写入字符输出流,缓冲各个字符,从而提供单个字符、数组和字符串的高效写入。也就是说,BufferedWriter会先将流里的字符进行缓冲之后再输入或输出,这样可以提高写入速度。
- 问题4:字符流和字节流的区别
问题4解决方案:
在java.io包中操作文件内容的主要有两大类:字节流、字符流,两类都分为输入和输出操作。在字节流中输出数据主要是使用OutputStream完成,输入使的是InputStream,在字符流中输出主要是使用Writer类完成,输入流主要使用Reader类完成。
字节流可用于任何类型的对象,包括二进制对象,而字符流只能处理字符或者字符串;字节流提供了处理任何类型的IO操作的功能,但它不能直接处理Unicode字符,而字符流就可以
问题5:
每一次对方法的递归调用,都会创建新的局部变量与参数。
怎么理解这句话?
- 问题5解决方案:理解这个概念时让我联想起了小时候的玩具--俄罗斯套娃。每一个娃娃就相当于是新创建的一个局部变量,而空出的地方就用于存放一个参数,在进行递归运算时,不断拆开“娃娃”(进行局部变量的运算),直到遇到基本情况为止。所以要防止无限递归的出现,因为每次递归调用都需要新增内存空间,无穷递归会产生内存耗尽的错误。
代码调试中的问题和解决过程

上周考试错题总结
- 错题1: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
- 解析:不同的排序算法在执行时需要不同数量的指令。
例如,选择排序通常需要比插入排序更多的指令。
因此,我们将排序算法与每个执行来排序数组的指令的数量进行比较。
如果两个排序算法需要大致相同数量的指令来排序一个数组,那么我们也可以检查所需的内存空间。
- 错题2:Polymorphism is achieved by
A . overloading(重载)
B . overriding(重写)
C . embedding(嵌入)
D . abstraction(抽象)
E . encapsulation(封装)
- 解析:Java的方法重载,就是在类中可以创建多个方法,它们具有相同的名字,但具有不同的参数和不同的定义。调用方法时通过传递给它们的不同参数个数和参数类型来决定具体使用哪个方法。
在Java中,子类可继承父类中的方法,而不需要重新编写相同的方法。但有时子类并不想原封不动地继承父类的方法,而是想作一定的修改,这就需要采用方法的重写。重写提供了多态性,因为适当的方法是根据当前被引用的对象而调用的。
嵌入是类中包含的类。抽象与多态没有任何关系。封装是使用可见性修饰符(public、private、protected)实现的。
- 错题3:Comparing the amount of memory required by selection sort and insertion sort, what can one say?
A . Selection sort requires more additional memory than insertion sort
B . Insertion sort requires more additional memory than selection sort
C . Both methods require about as much additional memory as the data they are sorting
D . Neither method requires additional memory
E . None of the above
- 解析:选择排序和插入排序都不需要额外的内存。
- 错题4: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
- 解析:创建抽象类的惟一方法是在类中创建一些抽象方法。所以,答案B是正确的。当然,抽象类中的所有方法都不必是抽象的。
- 错题5: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
- 解析:虽然继承和接口支持多态,但只有在有后绑定时才会这样做。但是,重载是多态性的一种形式,只要程序使用重载,多态就在使用中。
- 错题6:What is the efficiency of binary search?
A . n^2
B . n
C . log2 n
D . n/2
E . none of the above
- 解析:每次二分搜索消除大约一半的剩余数据。这个过程一直持续到找到需要的元素,或者直到所有可能的数据被消除。因为有n个数据元素,所以在数据量小于一个元素之前,可以将数据减半的次数是log2n。
- 错题7:Binary search can be used on unsorted data it will just perform more slowly.
A . true
B . false
- 解析:二分搜索只能在有序的数组元素中进行。
结对及互评
博客中值得学习的或问题:
- 代码中值得学习的或问题:
- 基于评分标准,我给本博客打分:XX分。得分情况如下:xxx
** 点评过的同学博客和代码**
其他
本周学习了异常和递归两个章节的内容,总体来说不是特别难,只需要认真学习就能够基本掌握。同时本周还同时进行结对编程的练习。
学习进度条
| 目标 |
5000行 |
30篇 |
400小时 |
|
| 第一周 |
117/117 |
1/1 |
19/19 |
|
| 第二周 |
289/406 |
1/2 |
21/40 |
|
| 第三周 |
403/809 |
2/4 |
22/62 |
|
| 第四周 |
1783/2592 |
1/5 |
35/97 |
|
| 第五周 |
770/3362 |
1/6 |
25/122 |
|
| 第六周 |
734/4096 |
1/7 |
25/147 |
|
| 第七周 |
687 / 4783 |
1/8 |
25/172 |
|
| 第八周 |
824/5607 |
2/10 |
30/202 |
|
| 第九周 |
764/6371 |
2/12 |
30/432 |
|
参考资料
20172323 2017-2018-2 《程序设计与数据结构》第九周学习总结
原文:https://www.cnblogs.com/Lewandodoski/p/9032308.html