zoukankan      html  css  js  c++  java
  • 20172323 2017-2018-2 《程序设计与数据结构》第四周学习总结

    教材学习内容总结

    学习第四章以及第七章

    • 类的分析:类的数据和方法成为类的成员。面向对象程序设计基于类的定义,类代表定义了合理的状态和行为的对象。
    • UML类图:有助于描述程序的类结构及类间的关系。
    • 封装:Java使用修饰符实现对象封装,修饰符是Java的保留字,用于规定程序设计语言构造的具体特征。访问器和修改器的概念。
    public private
    变量 违反封装性 强化封装性
    方法 为客户提供服务 为类中其他方法提供支持
    • 方法的分析:返回值的类型可以是基本数据类型,类名或保留字void。当方法不返回任何值时,用void作为返回值类型(main方法)。要返回值的方法必须有一条return语句。形式参数和实际参数以及局部数据概念。
    • 软件开发的4个基本过程。
    • 静态类成员(使用static修饰符):静态变量和静态方法的含义。
    • 类间关系:基本的三种关系依赖,聚合和继承。
    • this引用:一是可用于引用当前正在运行的对象,二是区分同名的构造方法参数和实际变量。
    • 接口:接口是抽象方法的集合,不能被实例化。(如setXXX,getXXX)
    • 方法设计,方法重载

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

    • 问题1: 最初对于定义一个toString方法的作用不能理解。
    • 问题1解决方案:通过完成例4.1和例4.2以及之后的编程中的实践,逐渐了解到了定义此方法的用处。在例4.1中,编写
    System.out.println(“Die One:” + die1 + “,Die Two: ” + die2);
    

    如果没有定义一个toString方法,die1和die2将输出错误。
    如图所示

    • 问题2:变量的作用域取决于声明该变量的位置,作用域确定了何处可以引用该变量。对其中变量的作用域理解不够。
    • 问题2解决方案:变量的引用范围是该变量在程序中可以引用的区域。声明在类级的实例变量,可以被类中的任何方法引用。声明在一个特定方法中的局部变量(包括形式参数),都只能被该方法引用。如例4.2中,facevalue的作用域就是整个类。

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

    • 问题1:在做例4.3-例4.4时,Account.java编译成功后,运行时出现如图所示的情况。

    • 问题1解决方案:编辑Account.java的目的是定义一个Account类,使Transaction类可以运用其中定义的方法从而顺利运行,所以Account类不需要main方法,所以单独编译此Java文件会出现如此错误提示。

    代码托管

    上周考试错题总结


    • 错题1: If two variables contain aliases of the same object then
      A.the object may be modified using either alias
      B.the object cannot be modified unless there's but a single reference to it
      C.a third alias is created if/when the object is modified
      D.the object will become an "orphan" if both variables are set to null
      E.answers A and D are correct

    • 解析:对象可以使用别名进行修改,但如果两个变量都设置同样的名称null,变量将无法被调用,系统自动将其当作垃圾处理。

    • 错题2:What happens if you attempt to use a variable before it has been initialized?
      A.A syntax error may be generated by the compiler
      B.A runtime error may occur during execution
      C.A "garbage" or "uninitialized" value will be used in the computation
      D.A value of zero is used if a variable has not been initialized
      E.Answers A and B are correct

    • 解析:在初始化之前尝试运用变量会发生什么?首先在编译时肯定会提示语法错误,如果跳过检测,则会出现运行错误。在做题时我没考虑到逃脱检测这种情况,故正确答案应该选择E。

    • 错题3:Say you write a program that makes use of the Random class, but you fail to include an import statement for java.util.Random (or java.util.*). What will happen when you attempt to compile and run your program.
      A.The program won't run, but it will compile with a warning about the missing class.
      B.The program won't compile-you'll receive a syntax error about the missing class.
      C.The program will compile, but you'll receive a warning about the missing class.
      D.The program will encounter a runtime error when it attempts to access any member of the Random class
      E.none of the above

    • 解析:Java程序中,java。lang包中的类自动成为可用类,如果使用其他包中的类必须完整的声明相应类的引用,否则编译器无法识别方法,会出现无法编译且收到语法错误的提示。故答案选择B。

    • 错题4:Which of the following will yield a pseudorandom number in the range [ -5, +5 ) given the following:
    Random gen = new Random( );
    

    A.gen.nextFloat( ) * 5
    B.gen.nextFloat( ) * 10 - 5
    C.gen.nextFloat( ) * 5 - 10
    D.gen.nextInt( ) * 10 - 5
    E.gen.nextInt(10) - 5


    • 解析:Int和Float没分清所以这道题选B。

    • 错题5:An "alias" is when
      A.two different reference variables refer to the same physical object
      B.two different numeric variables refer to the same physical object
      C.two different numeric variables contain identical values
      D.two variables have the same names
      E.none of the above

    • 解析:概念不清。答案选择B

    • 错题6:These two ways of setting up a String yield identical results:
      a) String string = new String("123.45");
      b) String string = "" + 123.45;
      A.true
      B.false

    • 解析:这个在命令行中尝试一下,发现输出结果是一样的。故选A。

    感悟

    本周的学习内容实在有点多,所以其实有很多内容没有来得及细细思考,应该很多知识还没有完全掌握,所以这个假期要好好加班了。而且一直在向前看,忘了记录来时的路,所以这次的博客写的也比较肤浅。

    学习进度条

    代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
    目标 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
    • 计划学习时间:20小时

    • 实际学习时间:35小时

    参考资料

  • 相关阅读:
    转 oracle catalog 库常用脚本
    转 【ORACLE】ORA-12537 问题整理
    转 Trace a specific ORA- error
    15%
    MySQL 存储过程
    MySQL 命令行客户机的分隔符
    MySQL 连接join
    MySQL 正则表达式
    MySQL 日期时间函数
    Arthas 快速入门
  • 原文地址:https://www.cnblogs.com/Lewandodoski/p/8718881.html
Copyright © 2011-2022 走看看