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

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

教材学习内容总结

第十二章 Lambda

Lambda表达式会使程序更加地简洁,在平行设计的时候,能够进行并行处理。

第十三章 时间与日期

13.1Time&&Date

13.1.1时间的度量

1、Greenwich Mean Time(格林威治时间)简称GMT时间 观察太阳得来
2、Universal Time(世界时)UT
3、International Atomic Time(国际原子时)TAI
4、Coordinated Universal Time(世界协调时间) UTC
5、Unix时间 以1970年1月1日00:00:00为起点
6、epoch
目前实际上指的时间是UTC时间

13.1.2年历

1、Julian Calendar(儒略历)四年一闰
2、Gergorian Calendar(格里高利历)
3、ISO 8601标准

13.1.3Time Zones(时区)

一年的毫秒数不是简单的3652460601000

13.2Date&&Calendar

13.2.1Date

使用Date实例的各getTime可以获得epoch毫秒数,**Data实例只用来当做时间轴上的某一瞬间

13.2.2DataFormat(格式化时间日期)

利用DataFormat可以对字符串格式进行处理,分别有GetDateInstance、GetTimeInstance、GetDateTimeInstance直接构建SimpleDateFormat,可以自定义字符串格式 parse方法可以将指定的字符串剖析Date实例。

13.2.4TimeZone

TimeZone的getdefault可以取得默认时区的信息

13.3新时间日期API

13.3.1机器时间观点

Date实例只代表机器观点的时间信息

13.3.2人类时间观点

LockalDateTime、LocalDate、LocalTime是没有时区信息的
在上面那些类的基础上可以使用ZonedDateTime等来进行补充
取得月份要通过getValue()方法,而不是使用oridinal()(从0开始)方法

13.3.3对时间的运算

使用Calendar可以进行时间运算,jdk8中也提供了更加方便的时间运算方法以及输出格式,操作相应的temporal类即可

13.3.4年历系统设计

java.time.chrono类中有相关的年历系统的类

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

Date实例只能用来当作时间轴上的某一个瞬间,需要进行转换,并且一年的时间并不是3652460601000,这里面还是有许多的不一样。机器时间和人类时间还是有不同,设计程序时要正确地使用,在人类时间观点上还要注意各种历法的不同以及时区的问题,要不然还是会有些不准确。

错题

错题1
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()
答案:DF
解析:D,F.没有ParallelStream等类,所以A和E是不正确的。流类中定义的方法来创建一个 parallel stream 从现有parallel(); ;因此C是正确的,F是不正确的。集合类中定义的方法来创建一个parallel stream 从收集parallelStream();因此D是正确的,B错误的。
错题2
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
错题3
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
答案:AC
错题4
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和E是不正确的。它使用一个来try-with- resource打开FileReader和BufferedReader对象。因此,自动关闭,D是不正确的。的主体try块读入文件的第一行和输出给用户。因此,A是正确的。因为其余的文件不读,B是不正确的。
错题5
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.
答案:CD
解析:一个控制台JVM创建对象。因为只有一个存在,它是一个单例,mak - ing选项C正确的。如果程序运行的环境中没有一个控制台,系统。控制台()返回null,D也正确。其他报表控制台是不正确的。

代码托管

结对及互评

结对搭档

  • 20155226基于评分标准,我给本博客打分:(10)。得分情况如下:
  1. 正确使用Markdown语法(加1分)
  2. 模板中的要素齐全(加1分)
  3. 排版精美的加一分
  4. 代码Commit Message规范的加1分
  5. 进度条中记录学习时间与改进情况的加1分
  6. 感想,体会不假大空的加1分
  7. 教材学习中的问题和解决过程。
  8. 动手写新代码的加1分
    9.代码超过300行加2分

上周点评博客

其他(感悟、思考等,可选)

这周的学习内容主要是时间和日期,其实java就有这样的一些类,操作这些类就可以表示出相应的时间以及进行时间的一些输出格式的表示,还有就是对时间进行运算,最关键的就是善于利用API帮助文档,在需要的时候能够灵活地使用这些类。

学习进度条

代码行数(新增/累积) 博客量(新增/累积)
目标 5000行 30篇
第一周 3/3 1/1
第二周 105/108 1/2
第三周 205/313 1/3
第四周 402/710 1/4
第五周 327/1037 1/5
第六周 900 /1937 1/6
第七周 631/2568 2/8

参考资料

posted @ 2017-04-09 10:45  zdyt  阅读(170)  评论(6编辑  收藏  举报