try-catch
语句
unchecked
(免检)异常,其他属于checked
(必检)异常checked
异常不进行处理或抛出的话,没法经过编译throw
和throws
的做用
throw
用来抛出一个异常对象throws
用来声明异常(必检异常),throws Exception
紧跟在方法以后InputStream
,OutputStream
是全部字节流的父类解决方案:我到云班课上提问,老师提示我查查10在ASCII码中的含义,因而我查了ASCII码表,发现10是换行符。因而我在虚拟机中用od命令查看from.txt文件的内容,发现最后果真有个换行符。
但是我并无敲回车,也没有换行,为何会有换行符呢?老师在讲解说,在Linux下,文件的每行会自动加一个换行符,咱们是看不到的,要用od命令查看才能知道,并且若是实在Windows下,是自动加回车(“/r”)。html
问题2:书上的程序10.2有一行代码,用到了这样一个方法:Integer.praseInt();
,不明白这个方法的做用。java
解决方案:查找API帮助文档。praseInt()
是Integer
类中的一个静态方法,返回值类型为Int,做用是将字符串参数做为有符号的十进制整数进行解析。
书上的代码是要将一串String
类型的数字转化成Int
类型git
import java.util.Scanner; public class AverageNumberException { public static void main (String[] args) { String num; int num1, sum = 0, average, i = 0; final int TIMES = 10; Scanner scan = new Scanner(System.in); System.out.println("Enter 10 integers: "); System.out.print(" "); num = scan.nextLine(); while (i>=0 && i<10) { try { num1 = Integer.parseInt(num); sum += num1; i++; } catch(NumberFormatException e) { System.out.println("The integer you entered is invalid! Please input again."); } System.out.print(" "); num = scan.nextLine(); } average = sum / TIMES; System.out.println("Average: " + average); } }
运行结果
我输了出去异常的数字以外,我输了11个数程序才结束数据结构
我把循环条件改了一下:ide
import java.util.Scanner; public class AverageNumberException { public static void main (String[] args) { String num; int num1, sum = 0, average, i = 0; final int TIMES = 10; Scanner scan = new Scanner(System.in); System.out.println("Enter 10 integers: "); while (ture) { try { System.out.print(" "); num = scan.nextLine(); num1 = Integer.parseInt(num); sum += num1; i++; } catch(NumberFormatException e) { System.out.println("The integer you entered is invalid! Please input again."); } if (i==9) { break; } } average = sum / TIMES; System.out.println("Average: " + average); } }
但结果倒是只能输9个数,我想确定是循环出了问题,因而我把if(i==9)
改为了if(i==10)
,改好以后就能输入10个数了(除了那个异常的数)。我想缘由是输入第一个整数后,i自加1,从0变成1,这样循环下去,到第九个有效整数时,i就变成了9,也就退出循环了。我又看了一下最初的代码,发现是一样的问题,因而也改了一下工具
import java.util.Scanner; public class AverageNumberException { public static void main (String[] args) { String num; int num1, sum = 0, average, i = 0; final int TIMES = 10; Scanner scan = new Scanner(System.in); System.out.println("Enter 10 integers: "); System.out.print(" "); num = scan.nextLine(); while (i>=0 && i<9) { try { System.out.print(" "); num = scan.nextLine(); num1 = Integer.parseInt(num); sum += num1; i++; } catch(NumberFormatException e) { System.out.println("The integer you entered is invalid! Please input again."); } } average = sum / TIMES; System.out.println("Average: " + average); } }
可结果倒是,能够输10个整数了,但算出的结果却不对。我又仔细看了一下代码,发现虽然循环对了,可是,我在循环外输入了第一个整数,这个整数没有被转化成Int类型的值并加到sum中去,因此至关于少加了一个数。因而我在循环外加上了num1 = Integer.parseInt(num);
和sum += num1;
,这样就没有问题了。学习
(statistics.sh脚本的运行结果截图)测试
Which of the following methods are included with any object that implements the Iterator interface? (下面哪一个方法包含了实现Iterator接口的对象?) A .next B .hasNext C .toString D .all of the above(以上都正确) E .a and b(a和b) 正确答案: D
分析:next
和hasnext
是Iterator
中的抽象方法,toString
是Object
中的方法,而全部类都是Object
的子类,因此Iterator
中也有toString
方法。this
Suppose Animal is an interface that specifies a single method – speak. Now suppose the Dog class implements the Animal interface. In addition to the speak method, the Dog class also has a method called wagTail. Now consider the following code(假设Animal是一个指定了单一方法的接口--speak。如今假设Dog类实现了Animal接口。除了speak方法外,Dog类还有一个方法wagTail。如今思考下面的代码:). Animal a = new Dog(); a.wagTail(); Which of the following is true about this code?(关于这段代码,下面哪项是正确的) A .It will result in a compile-time error(这段代码会引发编译时错误). B .It will result in a run-time error.(这段代码会引发运行时错误) C .It will call the speak method defined in the Animal interface. (这段代码将会调用Animal接口中的speak方法) D .It will call the wagTail method defined in the Dog class(这段代码将会调用Dog类中的wagTail方法). E .none of the above are true. (以上都正确) 正确答案: A
分析:这段代码会出现编译时错误,Animal
接口中没有定义wagTail
方法。能够将其显式转换为Dog
类来调用wagTail
方法。.net
An interface cannot declare any instance variables(接口不能声明任何实例变量). A .true B .false 正确答案: A
分析:接口不能声明任何实例对象,但可用来声明对象引用变量。
FHS(英文:Filesystem Hierarchy Standard 中文:文件系统层次结构标准)定义了两层规范,第一层是()? A ./etc 应该放置设置文件 B ./ 下面的各个目录应该要放什么文件数据 C .针对 /usr 及 /var 这两个目录的子目录来定义 D ./bin 与 /sbin 则应该放置可执行文件 E ./var/log 放置系统登陆文件 F ./usr/share 放置共享数据 正确答案: B
分析:这是Linux的目录结构,参考Linux 基础入门(新版)中的第四节。
Java是一门工具,从云班课里的视频能够看出,理论的东西较少。视频的大部分时间都是在用敲代码,也就是实践。因此向要学好Java,必须得多用,在运用的过程当中找问题,从而学习到更多的东西。所以,不能仅仅照着书上的代码敲,还要多作课后的程序设计题目,培养本身的面向对象程序设计的思想,这样才能不断进步。
代码行数(新增/累积) | 博客量(新增/累积) | 学习时间(新增/累积) | 重要成长 | |
---|---|---|---|---|
目标 | 5000行 | 30篇 | 400小时 | |
第一周 | 113/113 | 1/1 | 10/10 | |
第二周 | 294/407 | 1/2 | 15/25 | |
第三周 | 433/840 | 1/3 | 15/40 | |
第四周 | 1169/2009 | 2/5 | 30/70 | |
第五周 | 825/2834 | 1/6 | 15/85 | |
第六周 | 331/3165 | 1/7 | 13/98 | |
第七周 | 738/3903 | 2/9 | 22/120 | |
第八周 | 428/4331 | 1/10 | 20/140 |
计划学习时间:15小时
实际学习时间:20小时
改进状况:在PP上花的时间占大部分,主要仍是作的少,本身写代码时经常要翻翻笔记,或者从新看一遍视频,毕竟只看一次记不住。这样在作PP时免不了花费大量时间。之后还应当在看视频时就跟着老师一块儿作测试,这样能较快地掌握相关知识。同时书上的内容也要弄懂,否则作PP时还要不停地翻书,查找相关资料。