20155314 2016-2017-2 《Java程序设计》第7周学习总结

教材学习内容总结

  • 了解Lambda语法
  • 了解方法引用
  • 了解Fucntional与Stream API
  • 掌握Date与Calendar的应用
  • 会使用JDK8新的时间API

教材学习中的问题和解决过程

课后习题

所谓“实践是检验认识真理性的唯一标准”,我在IntelliJ IDEA上把教材第三章课后练习题又敲了一

遍,给出了自己的答案,并加上了一些自己的分析,通过逐题进行代码调试实践的方式来深入对java类与对象的理解。小白在此恳请大家积极指出错误的地方(>_<)

9.4.1 选择题

  1. CD 分析:

     import java.util.*;
    import java.util.ArrayList;
    public class Exercise9411 {
    public static void main(String[] args) {
    foreach(new HashSet());
    foreach(new ArrayList());
    }
    private static void foreach(Collection elements) {
    for(Object o : elements) { }
    }
    }





  2. AB 分析:

     import java.util.*;
    //import java.util.ArrayList; public class Exercise9412 {
    public static void main(String[] args) {
    foreach(new HashSet() {
    });
    }
    private static void foreach(Iterable iterable) {
    for(Object o : iterable) { }
    }
    }







  3. C 分析:

     import java.util.*;
    public class Exercise9413 {
    public static void main(String[] args) {
    foreach(new HashSet());
    }
    private static void foreach(Collection collection) {
    Iterator elements = collection.iterator();
    while(elements.hasNext()) {
    System.out.println(elements.next());
    }
    }
    }





  4. D 分析:

     import java.util.*;
    class Student9414 {
    String number;
    String name;
    int score;
    Student9414(String number, String name, int score) {
    this.number = number;
    this.name = name;
    this.score = score;
    }
    }
    public class Exercise9414 {
    public static void main(String[] args) {
    Set<Student9414> students = new TreeSet<>();
    students.add(new Student9414("B1234", "Justin", 90));
    students.add(new Student9414("B5678", "Monica", 100));
    foreach(students);
    }
    private static void foreach(Collection<Student9414> students) {
    for(Student9414 student : students) {
    System.out.println(student.score);
    }
    }
    }

  5. D 分析:

     import java.util.*;
    class Student9415 {
    String number;
    String name;
    int score;
    Student9415(String number, String name, int score) {
    this.number = number;
    this.name = name;
    this.score = score;
    }
    }
    public class Exercise9415 {
    public static void main(String[] args) {
    Set<Student9415> students = new HashSet<>();
    students.add(new Student9415("B1234", "Justin", 90));
    students.add(new Student9415("B5678", "Monica", 100));
    students.add(new Student9415("B1234", "Justin", 100));
    students.add(new Student9415("B5678", "Monica", 98));
    students.add(new Student9415("B5678", "Monica", 100));
    System.out.println(students.size());
    }
    }

  6. A 分析:

     import java.util.*;
    public class Exercise9416 {
    public static void main(String[] args) {
    Set<Integer> numbers = new TreeSet<>();
    numbers.add(1);
    numbers.add(2);
    numbers.add(1);
    numbers.add(3);
    foreach(numbers);
    }
    private static void foreach(Collection<Integer> numbers) {
    for(Integer number : numbers) {
    System.out.println(number);
    }
    }
    }

  7. ABC

  8. C

     import java.util.*;
    public class Exercise9418 {
    public static void main(String[] args) {
    Set numbers = new TreeSet();
    numbers.add(1);
    numbers.add(2);
    numbers.add(1);
    numbers.add(3);
    for(Integer number : numbers) {
    System.out.println(number);
    }
    }
    }

  9. C 分析:

     import java.util.*;
    public class Exercise9419 {
    public static void main(String[] args) {
    Set<Integer> numbers = new TreeSet<>();
    numbers.add(1);
    numbers.add(2);
    numbers.add(1);
    numbers.add(3);
    for(Integer number : numbers) {
    System.out.println(number);
    }
    }
    }







  10. CD

    import java.util.*;
    public class Exercise94110 {
    public static void main(String[] args) {
    Map<String, String> messages = new HashMap<>();
    messages.put("Justin", "Hello");
    messages.put("Monica", "HiHi");
    foreach(messages.values());
    }
    private static void foreach(Iterable<String> values) {
    for(String value : values) {
    System.out.println(value);
    }
    }
    }





代码调试中的问题和解决过程

  • 帮助20155324王鸣宇同学解决了Linux命令行下git commit和git push的问题~为此鸣宇还专门写了一篇博客记录下我们探索的详细过程~总之挺有成就感的嘻嘻( ̀⌄ ́)

    如何解决无法成功git commit 和git push

  • 关于20155322秦诗茂同学macOS下Vim编码问题(已解决,改为UTF-8即可)

代码托管

(statistics.sh脚本的运行结果截图)



上周考试错题总结

本周第二次采用了在蓝墨云班课上考试的形式,在45分钟的时间里需要作答20道选择题,而且还有不少多选题,甚至大多都是程序分析题,一道一道敲到电脑上再去运行肯定是来不及的(>_<),更要命的是很多题不去跑程序的话我根本无从下手(>o<)所以还是老老实实学扎实才是万全之策啊~

  • 下面哪条命令可以把 f1.txt 复制为 f2.txt ?

    • A .cp f1.txt f2.txt
    • B .copy f1.txt f2.txt
    • C .cat f1.txt > f2.tx
    • D .cp f1.txt | f2.tx
    • E .copy f1.txt | f2.tx

    正确答案: A C

    我的答案: C

    分析:copy是Windows下的命令。cat f1.txt > f2.tx 通过输出重定向实现了复制。

  • 下面代码中共有()个线程?

      public class ThreadTest {
    public static void main(String args[]){
    MyThread myThread =new MyThread();
    Thread t1=new Thread(myThread);
    Thread t2=new Thread(myThread);
    t1.start();
    t2.start();
    }
    }
    class MyThread extends Thread {
    ...
    }
    • A .1
    • B .2
    • C .3
    • D .4

    正确答案: C

    我的答案: B

    分析:除了t1,t2, 不要忘了main所在的主线程。

  • 调用线程的interrupt()方法 ,会抛出()异常对象?

    • A .IOException
    • B .IllegalStateException
    • C .RuntimeException
    • D .InterruptedException
    • E .SecurityException

    正确答案: D E

    我的答案: D

    分析:查看帮助文档

  • Given an instance of a Stream, s, and a Collection, c, which are valid ways of creating a parallel stream? (Choose all that apply.)

    给定一个Stream的实例s, 一个Collection的实例c, 下面哪些选项可以创建一个并行流?

    • A .new ParallelStream(s)
    • B .c.parallel()
    • C .s.parallelStream()
    • D .c.parallelStream()
    • E .new ParallelStream(c)
    • F .s.parallel()

    正确答案: D F

    我的答案: B

    分析:D, F. There is no such class as ParallelStream, so A and E are incorrect. The method defined in the Stream class to create a parallel stream from an existing stream is parallel(); therefore F is correct and C is incorrect. The method defined in the Collection class to create a parallel stream from a collection is parallelStream(); therefore D is correct and B is incorrect.

  • Which of the following statements about the Callable call() and Runnable run() methods are correct? (Choose all that apply.)

    • A .Both can throw unchecked exceptions.
    • B .Callable takes a generic method argument.
    • C .Callable can throw a checked exception.
    • D .Both can be implemented with lambda expressions.
    • E .Runnable returns a generic type.
    • F .Callable returns a generic type.
    • G .Both methods return void

    正确答案: A C D F

    我的答案: C E

  • What are some reasons to use a character stream, such as Reader/Writer, over a byte stream, such as InputStream/OutputStream? (Choose all that apply.)

    • A .More convenient code syntax when working with String data
    • B .Improved performance
    • C .Automatic character encoding
    • D .Built-in serialization and deserialization
    • E .Character streams are high-level streams
    • F .Multi-threading support

    正确答案: A C

    我的答案: F

    分析:Character stream classes often include built-in convenience methods for working withString data, so A is correct. They also handle character encoding automatically, so C is also correct. The rest of the statements are irrelevant or incorrect and are not properties of all character streams.

  • Assuming zoo-data.txt is a multiline text file, what is true of the following method?

    private void echo() throws IOException {

    try (FileReader fileReader = new FileReader("zoo-data.txt");

    BufferedReader bufferedReader = new BufferedReader(fileReader)) {

    System.out.println(bufferedReader.readLine());

    }

    }

    • A .It prints the first line of the file to the console.
    • B .It prints the entire contents of the file.
    • C .The code does not compile because the reader is not closed.
    • D .The code does compile, but the reader is not closed.
    • E .The code does not compile for another reason.

    正确答案: A

    我的答案: C

    分析:This code compiles and runs without issue, so C and E are incorrect. It uses a try-with- resource block to open the FileReader and BufferedReader objects. Therefore, both get closed automatically, and D is incorrect. The body of the try block reads in the first line of the file and outputs it to the user. Therefore, A is correct. Since the rest of the file is not read, B is incorrect.

  • Assuming / is the root directory, which of the following are true statements? (Choose all that apply.)

    • A ./home/parrot is an absolute path.
    • B ./home/parrot is a directory.
    • C ./home/parrot is a relative path.
    • D .The path pointed to from a File object must exist.
    • E .The parent of the path pointed to by a File object must exist.

    正确答案: A

    我的答案: E

    分析:Paths that begin with the root directory are absolute paths, so A is correct and C is incorrect. B is incorrect because the path could be a file or directory within the file system. A File object may refer to a path that does not exist within the file system, so D and E are incorrect.

  • What is the result of executing the following code? (Choose all that apply.)

    String line;

    Console c = System.console();

    Writer w = c.writer();

    if ((line = c.readLine()) != null)

    w.append(line);

    w.flush();

    • A .The code runs without error but prints nothing.
    • B .The code prints what was entered by the user.
    • C .An ArrayIndexOutOfBoundsException might be thrown.
    • D .A NullPointerException might be thrown.
    • E .An IOException might be thrown.
    • F .The code does not compile.

    正确答案: B D E

    我的答案: C

    分析:This is correct code for reading a line from the console and writing it back out to the console, making option B correct. Options D and E are also correct. If no con- sole is available, a NullPointerException is thrown. The append() method throws anIOException.

  • Which of the following are true? (Choose all that apply.)

    • A .A new Console object is created every time System.console() is called.
    • B .Console can only be used for reading input and not writing output.
    • C .Console is obtained using the singleton pattern.
    • D .When getting a Console object, it might be null.
    • E .When getting a Console object, it will never be null.

    正确答案: C D

    我的答案: B D

    分析:A Console object is created by the JVM. Since only one exists, it is a singleton, mak- ing option C correct. If the program is run in an environment without a console, System. console() returns null, making D also correct. The other statements about Console are incorrect.

  • Which classes will allow the following to compile? (Choose all that apply.)

    InputStream is = new BufferedInputStream(new FileInputStream("zoo.txt"));

    InputStream wrapper = new _____(is);

    • A .BufferedInputStream
    • B .FileInputStream
    • C .BufferedWriter
    • D .ObjectInputStream
    • E .ObjectOutputStream
    • F .BufferedReader

    正确答案: A D

    我的答案: A B

    分析:The reference is for an InputStream object, so only a high-level input Stream class is permitted. B is incorrect because FileInputStream is a low-level stream that interacts directly with a file resource, not a stream resource. C and F are incorrect because you can- not use BufferedReader/BufferedWriter directly on a stream. E is incorrect because

    the reference is to an InputStream, not an OutputStream. A and D are the only correct options. Note that a BufferedInputStream can be wrapped twice, since high-level streams can take other high-level streams.

  • Suppose that the file c:\book\java exists. Which of the following lines of code creates an object that represents the file? (Choose all that apply.)

    • A .new File("c:\book\java");
    • B .new File("c:\book\java");
    • C .new File("c:/book/java");
    • D .new File("c://book//java");
    • E .None of the above

    正确答案: B C

    我的答案: A

    分析:Option B is correct because Java requires a backslash to be escaped with another backslash. Option C is also correct because Java will convert the slashes to the right one when working with paths.

结对及互评

评分标准

  1. 正确使用Markdown语法(加1分):

    • 不使用Markdown不加分
    • 有语法错误的不加分(链接打不开,表格不对,列表不正确...)
    • 排版混乱的不加分
  2. 模板中的要素齐全(加1分)

    • 缺少“教材学习中的问题和解决过程”的不加分
    • 缺少“代码调试中的问题和解决过程”的不加分
    • 代码托管不能打开的不加分
    • 缺少“结对及互评”的不能打开的不加分
    • 缺少“上周考试错题总结”的不能加分
    • 缺少“进度条”的不能加分
    • 缺少“参考资料”的不能加分
  3. 教材学习中的问题和解决过程, 一个问题加1分

  4. 代码调试中的问题和解决过程, 一个问题加1分

  5. 本周有效代码超过300分行的(加2分)

    • 一周提交次数少于20次的不加分
  6. 其他加分:

    • 周五前发博客的加1分
    • 感想,体会不假大空的加1分
    • 排版精美的加一分
    • 进度条中记录学习时间与改进情况的加1分
    • 有动手写新代码的加1分
    • 课后选择题有验证的加1分
    • 代码Commit Message规范的加1分
    • 错题学习深入的加1分
    • 点评认真,能指出博客和代码中的问题的加1分
    • 结对学习情况真实可信的加1分
  7. 扣分:

    • 有抄袭的扣至0分
    • 代码作弊的扣至0分
    • 迟交作业的扣至0分

点评模板:

  • 博客中值得学习的或问题:

    • xxx
    • xxx
    • ...
  • 代码中值得学习的或问题:

    • xxx
    • xxx
    • ...
  • 基于评分标准,我给本博客打分:XX分。得分情况如下:xxx

  • 参考示例

点评过的同学博客和代码

感悟

也许是进入了瓶劲期了吧,感觉Java真的学不动了,难受(>_<)目前已经离老师布置的教学进程差了整整两章:(那又有什么办法呢只能老老实实按照自己的进度龟速向前爬呗~希望自己能在清明假期调整一下状态,争取迎头赶上吧……(。ì _ í。)

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 5000行 20篇 300小时
第一周 34/34 1/4 12/12
第二周 360/394 1/5 16/28
第三周 701/1018 1/6 19/ 47 代码量激增( ̀⌄ ́)
第四周 608/1375 1/7 18/55 ①蹭了一节张健毅老师的Java课;②自己将数据结构课上所学的排序算法除了基数排序之外全部用C语言实现了一遍(`_´)ゞ;③本次博客史无前例的长:)
第五周 1205/2580 1/8 9/64 蹭了一节张健毅老师的Java课
第六周 826/3339 1/9 8/72
第七周 / 2/11 13/85 ①蹭了一节张健毅老师的Java课;②在写了无数篇实验报告之后还写了两篇博客!!
  • 计划学习时间:10小时

  • 实际学习时间:13小时

参考资料

20155314 2016-2017-2 《Java程序设计》第7周学习总结的更多相关文章

  1. 20155336 2016-2017-2《JAVA程序设计》第九周学习总结

    20155336 2016-2017-2<JAVA程序设计>第九周学习总结 教材学习内容总结 第十六章 JDBC(Java DataBase Connectivity)即java数据库连接 ...

  2. 20145213《Java程序设计》第九周学习总结

    20145213<Java程序设计>第九周学习总结 教材学习总结 "五一"假期过得太快,就像龙卷风.没有一点点防备,就与Java博客撞个满怀.在这个普天同庆的节日里,根 ...

  3. 20145213《Java程序设计》第二周学习总结

    20145213<Java程序设计>第二周学习总结 教材学习内容总结 本周娄老师给的任务是学习教材的第三章--基础语法.其实我觉得还蛮轻松的,因为在翻开厚重的书本,一股熟悉的气息扑面而来, ...

  4. 20145213《Java程序设计》第一周学习总结

    20145213<Java程序设计>第一周学习总结 教材学习内容总结 期待了一个寒假,终于见识到了神秘的娄老师和他的Java课.虽说算不上金风玉露一相逢,没有胜却人间无数也是情理之中,但娄 ...

  5. 21045308刘昊阳 《Java程序设计》第九周学习总结

    21045308刘昊阳 <Java程序设计>第九周学习总结 教材学习内容总结 第16章 整合数据库 16.1 JDBC入门 16.1.1 JDBC简介 数据库本身是个独立运行的应用程序 撰 ...

  6. 20145330孙文馨 《Java程序设计》第一周学习总结

    20145330孙文馨 <Java程序设计>第一周学习总结 教材学习内容总结 刚开始拿到这么厚一本书说没有压力是不可能的,开始从头看觉得很陌生进入不了状态,就稍微会有一点焦虑的感觉.于是就 ...

  7. 20145337 《Java程序设计》第九周学习总结

    20145337 <Java程序设计>第九周学习总结 教材学习内容总结 数据库本身是个独立运行的应用程序 撰写应用程序是利用通信协议对数据库进行指令交换,以进行数据的增删查找 JDBC可以 ...

  8. 20145337 《Java程序设计》第二周学习总结

    20145337 <Java程序设计>第二周学习总结 教材学习内容总结 Java可分基本类型与类类型: 基本类型分整数(short.int.long).字节(byte).浮点数(float ...

  9. 20145218《Java程序设计》第一周学习总结

    20145218 <Java程序设计>第一周学习总结 教材学习内容总结 今天下午看了Java学习的视频,感觉很是新奇,之前觉得Java学起来是艰难枯燥的,但通过第一章的学习觉得如果自己可以 ...

  10. 《Java程序设计》第九周学习总结

    20145224 <Java程序设计>第九周学习总结 第十六章 整合数据库 JDBC入门 ·数据库本身是个独立运行的应用程序 ·撰写应用程序是利用通信协议对数据库进行指令交换,以进行数据的 ...

随机推荐

  1. 由Windows开发平台向Linux平台转移的一些想法

    从毕业到现在已经快20年了,一直在从事Windows平台上的开发工作.刚毕业那会大约是97,98年左右,工作的平台除了Windows平台还有Dos平台,因为在学校学习时,也是从Dos开始的.因此对于从 ...

  2. Bloom Filter解析

    布隆过滤器简介:https://www.cnblogs.com/Jack47/p/bloom_filter_intro.html 布隆过滤器详解:原文链接:http://www.cnblogs.com ...

  3. 微软职位内部推荐-Senior Software Engineer-Eco

    微软近期Open的职位: The MOD Ecosystem team is dedicated to expanding the reach and value of Office by enabl ...

  4. App Inspector 功能详解

    前言: App Inspector:浏览器端的移动设备 UI 查看器,使用树状态结构查看 UI 布局,自动生成 XPaths 官网:https://macacajs.github.io/app-ins ...

  5. 启动Tomcat 卡在 Initializing Spring FrameworkServlet 'SpringMVC'

    使用Myeclipse进行项目开发时莫名其妙启动项目卡在 Initializing Spring FrameworkServlet 'SpringMVC' ,然后等待几分钟后项目才启动起来. 在之前也 ...

  6. 设置macbook休眠模式

    前言: macbook默认合上盖默认是进入混合休眠模式模式(mode 3),此时电脑还会供电.不想耗电的话关机的话当前的工作状态就丢失了. macbook实际上是可以进入休眠模式的,只是没开放出来,我 ...

  7. OneZero第五周第一次站立会议(2016.4.18)

    1. 时间: 13:00--13:15  共计15分钟. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http ...

  8. 在laravel中,使用DB查询数据库后,返回的对象,可以用下面的办法变为数组

    $nodes = Db::table('account')->orderBy('sort', 'asc')->orderBy('id' ,'asc')->get()->map( ...

  9. group replication && Galera replication

    不愧是 Oracle 的 MySQL Community Manager,把对手的 Galera Cluster 讲得一无是处. http://lefred.be/content/group-repl ...

  10. #LOJ2564 SDOI2018 原题识别 主席树

    转载请注明原文地址:http://www.cnblogs.com/LadyLex/p/9057297.html 原题链接: 今天考试考了前天的SDOI考题 天啊我菜爆,只有T2拿了30分 然后考试后半 ...