20172306《Java程序设计》第四周学习总结

20172306 《Java程序设计》第四周学习总结

教材学习内容总结

  第四章:
 1. 类和对象的回顾:除了看书,我还上网找了一下两者的一些区别。
 2. 编写类时,了解到初始化、形式参数、实例数据、返回语句等的位置。
 3. UML类图包含数据和方法,在我们编写时,看到这个可以更加的清晰。
 4.封装,这个问题,书中介绍不是很多,但是做测试题发现好几道都和封装有关,所以封装还挺重要的。
 5.构造方法中,没有返回值类型,要充分考虑toString和return的应用,还有要避免明明是输出一句话,却用了Integer,这会产生不必要的麻烦。

  第七章:(第七章的内容我是在老师讲完第七章之后才阅读的,在课上对第七章已经有了一些理解)
 1.有关静态变量和静态方法的使用
 2. 类与类之间的关系:依赖关系、聚合关系、(继承关系)聚合是依赖的一种特殊的关系。
 3.this的引用
 4.接口,头一回引用了接口进行编写。
 5.枚举型,在前面已经有枚举型,但是我觉得这个更加的明晰和方便。
 6.对于一个方法,后面讲了很多,大致就是讲了方法的几种使用。
 7.最后是测试和审查,这也是一个软件设计需要的部分,这部分文字较多,但是还是比较容易理解的。     

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

  • 问题1:对于形式参数和实际参数还有实例数据还有变量还有类与对象之间概念的混淆。
  • 问题1解决方案:形式参数就是方法声明的参数;实际参数就是方法定义的参数;实例数据我认为通俗的说就是你在调用一个类时自己所赋予形式参数的一个实际的数据;变量这个,最开始我以为他们应该是平等的关系,后来问了同学,才发现其实很多东西都可以叫做变量,因为他们在整个代码中被赋予了某些东西;类是同一类对象的原型,或者说,对象就是一个类的具体的实例,而对于对象而言,它自身有一系列的动作和行为。
  • 问题2:在利用接口的时候,十分的疑惑,为什么我们不能直接的就将一个方法直接就表示出来,反而还要再弄一个接口
  • 问题2解决方案:一开始我觉得接口是一个很麻烦的东西,认为它只是针对某各类可以进行作用,呈现一一对应的关系,但是后来,我知道一个接口可以用在多个编写的类中,反而是更加的方便。同时又学习了几个比较常见的接口。
  • 问题3:方法参数之间的传递问题
  • 问题3解决方案:对于这个方法参数之间的传递,即使现在为止,我也依旧很懵。,在ParameterModifier.java 中,就是运用了这个,在这里我大致懂了它的整个传递情况,但是当我自己编的时候就变得很懵很懵,这个还有待解决

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

  • 问题1:我在做Car的那个试验时,发现可以编译成功,可以运行出来却是这种情况
  • 问题1解决方案:后来我发现,我在调用类的时候,是先编译了类,然后又编译运行的test,发现出现了空,但是如果一起编译就可以得到自己想要得到的了。
  • 问题2:
  • 问题2解决方案:对于以上这两张图片,是马虎的问题,一个是将main打成了mian,一个是它的对象名写错了,这是不该犯的错误。
  • 问题3:
  • 问题3解决方案:这个就是我在前面写的,要分清int、double、string等的区别,不能混淆。
  • 问题4:
  • 问题4解决方案:这个问题是我在做PP4.9的时候遇到的,看到了之后,我一开始以为我是应该创建一个接口或者怎么样,后来我才发现是我多用了一个 }
    导致了整个程序分家了,才出现了这样的问题。

代码托管

其实我觉得我这周有关代码的问题都比较普通,也和自己马虎有关,因为书中的例题很多,所以基本在敲例题时遇到的问题是不大的,而且其实在自己编写的过程中,遇到了很多编译就错误的情况,但是基本都在一点点的改正中解决了,就忘记截图了。

上周考试错题总结

  • 1.In Java a variable may contain
    A a value or a reference
    B a package
    C a method
    D a class
    E any of the above 本题选E变量包括一个值或一个引用或一个包或一个方法或一个类
  • 2.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 本题选E 可以利用别名修改对象,这是书中写的 ,所以选了A,根据定义,别名提供了一种可以修改对象的方法(别名就像一个指针)。如果两个变量都被设置为null,那么该对象就不会被任何变量引用(通过任何别名),而且它确实会变成一个“孤儿”,并且在将来的某个时候会被垃圾收集所以选了D。
  • 3.Which properties are true of String objects?
    A Their lengths never change
    B The shortest string has zero length
    C Individual characters within a String may be changed using the replace method
    D The index of the first character in a string is one
    E Only A and B are truereplace 本题选E 方法允许您从原始的字符串中创建一个新的字符串,替换一些字符。
  • 4.What is the function of the dot operator?
    A It serves to separate the integer portion from the fractional portion of a floating point number
    B It allows one to access the data within an object when given a reference to the object
    C It allows one to invoke a method within an object when given a reference to the object
    D It is used to terminate commands (much as a period terminates a sentence in English)
    E Both B and C are correct 本题选E 点操作符被直接附加在对象引用之后,然后是需要访问的数据或方法。在数据的情况下,访问可能是为了阅读或写作。在方法的情况下,存取是允许一个人调用该方法。浮点数中的点是一个小数点,而不是点运算符。
  • 5.In the StringMutation program shown in Listing 3.1, if phrase is initialized to "Einstein" what will Mutation #3 yield if Mutation #1: mutation1 = phrase.concat(".")?
    A Einstein.
    B EINSTEIN.
    C XINSTXIN.
    D einstein.
    E xinstxin. 本题选C 这道题我认为和上述的第3题的错误点是一样的。
  • 6.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 本题选B 因为并没有这个类,所以就不可能会运行,而且也不是语法上的错误,所以它会有错误信息,收到关于丢失的类的语法错误。
  • 7.Consider the following two lines of code. What can you say about s1 and s2?
    String s1 = "testing" + "123";
    String s2 = new String("testing 123");
    A s1 and s2 are both references to the same String object
    B the line declaring s2 is legal Java; the line declaring s1 will produce a syntax error
    C s1 and s2 are both references to different String objects
    D s1 and s2 will compare "equal"
    E none of the above 本题选C 对于这两条语句,都是合法的,但是不同之处是,第二个在testing和123 之间有一个空格符
  • 8.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 本题选A 两个不同的参考变量引用相同的物理对象,应该是参考变量,而不是数值变量。
  • 9.The String class' compareTo method
    A compares two string in a case-independent manner
    B yields true or false
    C yields 0 if the two strings are identical
    D returns 1 if the first string comes lexically before the second string
    E none of the above 本题选C
  • 10.Java.text's NumberFormat class includes methods that
    A allow you to format currency
    B allow you to format percentages
    C round their display during the formatting process
    D truncate their display during the formatting process
    E A, B, C, but not D 本题选E 这个主要是对于NumberFormat的理解不够
  • 11.The advantages of the DecimalFormat class compared with the NumberFormat class include
    A precise control over the number of digits to be displayed
    B control over the presence of a leading zero
    C the ability to truncate values rather than to round them
    D the ability to display a % automatically at the beginning of the display
    E only A and B 本题选E 这个和第10题是差不多的。
  • 12.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 Java理解+操作符,当使用数字与数字组合时,意味着数字应该被转换成一个数字字符串,然后就会出现连接。
  • 13.You may use the String replace( ) method to remove characters from a String.
    A true
    B falsereplace()方法仅用其他单个字符替换单个字符。replace()方法不会将字符添加或删除字符串;字符串长度将保持不变
  • 14.All the methods in the Math class are declared to be static.
    A true
    B false数学类方法被设计成在算术表达式中通常有用,因此不需要任何实例来使用它们。这是通过确保所有的数学方法都是静态的来实现的。

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

 我觉得,这一周半的时间学习这两章的内容,说实话,真的是很累。而且事情很多,确实对于这两章学习的内容学习的不如前几章学习的好,自己十分的后悔当初为什么要抽风的选了大物和高数两门课程,除此之外,还有很多其他的活动,最近对于java的练习确实很少,这是我应该反思的东西,我越来越觉得java是一个不断动手做的过程,所以希望在接下来的日子里能分更多的时间给java。

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
目标 5000行 30篇 400小时
第一周 193/200 1/1 20/20
第二周 193/440 1/1 22/38
第三周 445/895 2/2 20/60
第四周 885/1780 1/1 43/90

参考资料

原文地址:https://www.cnblogs.com/lc1021/p/8697739.html