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

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

教材学习内容总结

  • Lambda 教材的引入循序渐近、深入浅出

    • Lambda去重复,回忆DRY原则
    • Lambda表达式可读性更好
  • Arrays.sort

    • Comparator: 对比C语言中使用函数指针
    • 匿名类与多态
  • 方法引用(Method Reference)

    • 新语法
    • 一条语句用Lambda表达式,多条语句用方法引用
  • 函数接口(Functional Interface)

    • 就是只有一个抽象方法的接口

      Runnable

      Callable

      Comparator

      ...

    • @FunctionalInterface
    • 可引用的包括类的静态方法、成员方法、构造方法
  • 接口默认方法(Default Method)

    • 不能使用类的成员变量
  • 使用Optional代替null

  • 标准API的函数接口

    • Consumer:一个参数,无返回值
    • Function:一个参数,有返回值
    • Predicate:一个参数,有返回值,返回值必须是boolean类型的
    • Supplier:无参数,有返回值
  • Stream与管道

  • 时间的度量

    • GMT(Greenwich Mean Time)时间:现在不是标准时间
    • 世界时(Universal Time,UT):1972年UTC出来之前,UT等价于GMT
    • 国际原子时(TAI):秒的定义
    • 世界协调时间(Corrdinated Universal Time, UTC): 闰秒
    • Unix时间: 1970.1.1 00:00:00开始的秒数
    • epoch: java.util.Date epoch毫秒数
  • 日历

    • 儒略历(Julian Calendar)
    • 格里高利历(Gregorian Calendar)
    • ISO8601 标准
  • 时区

  • Date与DateFormat

    • Date只用来获取epoch毫秒数
    • DateFormat来格式化成人类理解的年月日时分秒
  • Calendar: 时间的运算

    • getInstance(): GregorianCalendar
    • getTime()
    • get()
    • add()
    • roll()
    • after()
    • before()
    • ...
  • 机器时间 Instant

  • 人类时间(ISO8601 标准)

    • LocalDateTime
    • LocalDate
    • LocalTime
    • ZonedDateTime
    • OffsetdateTime
    • Year
    • YearMonth
    • Month
    • MonthDay
    • TemporalAmount
    • TemporalUnit
    • TemporalAccessor
    • Chronology

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

  • 问题1:将机器对时间的概念与人类对时间的概念区隔开来,让机器与人类对时间概念的界限变得分明,有什么意义?
  • 问题1解决方案:我没搞清楚......
  • 问题2:•如何计算一个程序的运行时间?
  • 问题2解决方案:
    • (1)以毫秒为单位计算:
long startTime=System.currentTimeMillis(); //获取开始时间

 doSomeThing(); //测试的代码段

 long endTime=System.currentTimeMillis(); //获取结束时间

 System.out.println("程序运行时间: "+(end-start)+"ms");

    • (2)以纳秒为单位计算:
long startTime=System.nanoTime(); //获取开始时间

  doSomeThing(); //测试的代码段

  long endTime=System.nanoTime(); //获取结束时间

  System.out.println("程序运行时间: "+(end-start)+"ns");

  • ...

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

因为是粘贴了课本上的代码,所以代码调试中并未出现什么问题

  • ...

代码托管

运行statistics脚本时出现中文乱码,再次运行时正常。

上周考试错题总结

  • 错题1及原因,理解情况

下面哪条命令可以把 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

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

  • 错题2及原因,理解情况

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

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

除了t1,t2, 不要忘了main所在的主线程

  • 错题3及原因,理解情况

Java中,可以继承()类定义线程

A . Runnable

B . Thread

C . Future

D . Executor

正确答案: B

  • 错题4及原因,理解情况

如果有以下代码段:

Thread thread = new Thread(new ________________() {
    public void run() {...} 
});

空白部分指定哪些类型可以通过编译?

A . Runnable

B . Thread

C . Future

D . Executor

正确答案: A B

查API文档,Thread 也实现了 Runnable 接口

  • 错题5及原因,理解情况

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

A . IOException

B . IllegalStateException

C . RuntimeException

D . InterruptedException

E . SecurityException

正确答案: D E

查看帮助文档

  • 错题6及原因,理解情况

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

没有像 ParallelStream 这样的类, 所以 a 和 e 是不正确的。流类中定义的用于从现有流创建并行流的方法是平行的 ();因此, f 是正确的, c 是不正确的。在集合类中定义的用于从集合创建并行流的方法是 parallelStream ();因此, d 是正确的, b 是不正确的。

  • 错题7及原因,理解情况

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

以下关于可调用调用call () 和可执行运行run () 方法的语句中的哪一个是正确的?(选择适用的所有)

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

  • 错题8及原因,理解情况

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.)

在字节流, 例如 InputStream/OutputStream, 使用字符流的原因是什么?(选择适用的所有)

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

字符流类通常包括用于工作 withString 数据的内置方便方法, 因此 a 是正确的。他们也会自动处理字符编码, 所以 c 也正确。其余的语句是无关紧要的或不正确的, 不是属性而字符流。

  • 错题9及原因,理解情况

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

假定 zoo-data.txt 是一个多行文本文件, 下面的方法是什么?

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 不正确。它使用尝试使用资源块来打开 FileReader 和 BufferedReader 对象。因此, 两个 getclosed 自动, d 是不正确的。try 块的正文在第一个线文件中读取, 并将其输出给用户。因此, a 是正确的。由于文件的其余部分是 notread, b 不正确。

  • 错题10及原因,理解情况

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

这是正确的代码, 从控制台读取一行并将其写回 outto 控制台, 使选项 b 正确。选项 d 和 e 也是正确的。如果没有可用的鞋底, 就会抛出一个空指针异常。追加 append() 方法抛出 anIOException。

  • 错题11及原因,理解情况

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

一个控制台对象是由 jvm 创建的。因为只有一个存在, 它是一个单一的, mak 选项 c 正确。如果程序在没有控制台、系统的环境中运行. 控制台 () 返回 null, 使 d 也正确。有关控制台 areincorrect 的其他语句。

  • 错题12及原因,理解情况

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

引用为 InputStream 对象, 因此仅允许课高级输入流。b 不正确, 因为 FileInputStream是一个低级流,它interactsdirectly 文件资源, 而不是流资源。c 和 f不正确, 因为您不能直接在流上使用BufferedReader/BufferedWriter。e 是不正确的, 因为引用的是 InputStream, 而不是 OutputStream。a 和 d 是唯一的correctoptions。注意, BufferedInputStream 可以被包裹两次, 因为高水平的 streamscan 采取其他高水平的溪流。

  • 错题13及原因,理解情况

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.)

假定文件 c:\book\java 存在。下面哪行代码创建表示文件的对象?(选择适用的所有)

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

选项 b 是正确的, 因为 java 需要用 anotherbackslash 来转义一个反斜线。选项 c 也是正确的, 因为 java 会将斜线转换为使用路径的右侧 onewhen。

  • 错题14及原因,理解情况

Which of the following are built-in streams in Java? (Choose all that apply.)

下面是 java 中的内置流?(选择适用的所有)

A . System.err

B . System.error

C . System.in

D . System.input

E . System.out

F . System.output

正确答案: A C E

系统类有三个流: in 是用于输入, 错误是为出错, 而出是 foroutput。因此, a, c 和 e 是正确的。其他不存在。

结对及互评

评分标准

  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的时间80%都用来做这些了,但其实并没有太大的作用,我想我在经历了惨痛的教训之后终于明白自己其实一直在舍本逐末,代码量和博客对我来说其实没有我想的那么重要,毕竟学习是为了自己,而不是学给别人看的。

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 5000行 30篇 400小时
第一周 12/12 1/4 20/20
第二周 64/76 1/5 22/42
第三周 560/636 1/6 22/64
第四周 532/1168 1/7 20/84
第五周 510/1728 1/8 20/104
第六周 697/2425 1/9 15/119
第七周 269/2694 1/10 15/134

尝试一下记录「计划学习时间」和「实际学习时间」,到期末看看能不能改进自己的计划能力。这个工作学习中很重要,也很有用。
耗时估计的公式
:Y=X+X/N ,Y=X-X/N,训练次数多了,X、Y就接近了。

参考:软件工程软件的估计为什么这么难软件工程 估计方法

  • 计划学习时间:20小时

  • 实际学习时间:15小时

  • 改进情况:本周学习内容较少,学习效率有所提高。

(有空多看看现代软件工程 课件
软件工程师能力自我评价表
)

参考资料

posted @ 2017-04-09 16:50  弥光  阅读(272)  评论(8编辑  收藏  举报