1. 程式人生 > >20172330 2017-2018-1 《Java程序設計》第四周學習總結

20172330 2017-2018-1 《Java程序設計》第四周學習總結

類結構 sage ide 同時 muc ngs out rop tps

20172330 2017-2018-1 《Java程序設計》第四周學習總結

教材學習內容總結

這一周的內容還是比較多的,而且很復雜,包含第四和第七章。

  • 第四章向我們介紹了類結構的定義與概念,同時舉出了好多個例題向我們展示自定義類的方法與應用,對於方法定義的結構與用途進行了討論:包括return語句,參數,局部數據等方面。
  • 第七章的主要內容則是面向對象設計。通過書本的介紹了,我們探討了面向對象軟件設計的主要問題,了解了確定程序所需要的類和對象的技術,對類之間的關系進行了探討,詳細的學習了static修飾符作用在方法和數據上的效果和枚舉符類,最後對建立形式化對象接口的方法進行了學習。

    教材學習中的問題和解決過程

  • 問題1:編寫類是由哪些東西構成的,各個部分起到什麽作用?
  • 問題1解決方案:我也沒有太理解,大概覺得編寫類中大致起關鍵作用的包括兩個內容:構造函數和方法。它們可以使這個類變得有效,可以在程序中利用。

  • 問題2:靜態變量和實例變量的區別
  • 問題2解決方案:在查閱資料後發現
    實例變量必須創建對象後才可以通過這個對象來使用,靜態變量則可以直接使用類名來引用。就跟靜態方法可以直接通過類名調用類似。
    靜態變量是所有對象共有的,某一個對象將它的值改變了,其他對象再去獲取它的值,得到的是改變後的值;
    實例變量則是每一個對象私有的,某一個對象將它的值改變了,不影響其他對象取值的結果,其他對象仍會得到實例變量一開始就被賦予的值。

代碼調試中的問題和解決過程

  • 問題1:在編寫課堂作業暨pp47的時候,我編寫的book類其他都沒有什麽問題,運行也是成功的,但是在Java編譯的時候顯示的就是null,我換了好幾種方式不管是toString還是set。
    技術分享圖片

  • 問題1解決方案:然後在學長的指導下發現我編寫的類和定義的方法名字是一樣的導致錯誤最終輸出null,於是改為This.順便看到了課本上7.4.4對於this的引用,this引用是可以允許對象引用自己的,這也就解決了我的問題,而且this引用還可以引用於當前正在運行的對象。
    技術分享圖片

  • 問題2:當你把你編好的類javac到你的bin文件之後你再去測試你的text文件會顯示找不到類,而且在javac -d 的時候也會出現問題
  • 問題2解決方案:然後只有把他放在一個文件夾中你的類才會起到效果。

代碼托管

技術分享圖片
技術分享圖片

上周考試錯題總結

  • 1In 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
    在JAVA中變量只能包含一個值或一個引用。所以應該選a的。

  • 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,那麽對象將變成一個“孤兒”。

  • 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 true
    他們的長度永遠不會改變,最短的字符串長度為零。字符串是不可變的。這意味著, 一旦創建了字符串對象, 就不能更改它。因此, 字符串的長度在創建後不會更改。最短長度字符串為 "", 引號之間沒有字符, 因此長度為零。

  • 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
    編譯器多次能夠檢測到未初始化變量的嘗試使用, 在這種情況下會產生語法錯誤。如果編譯器使用轉義檢測, 則在使用時會發生運行時錯誤。

  • 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的。

  • Unlike the String class where you must pass a message to an object (instance) of the class, as in x.length( ), in order to use the Math class, you pass messages directly to the class name, as in Math.abs( ) or Math.sqrt( ).
    A .true
    B .false
    數學類使用被稱為靜態方法 (或類方法) 的方法, 通過將消息直接傳遞到類名本身而不是類的對象來調用。

  • 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
    這道題是Float,我沒有註意到。

  • 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
    s1和s2是對不同對象的引用,無論s1和s2對應的變量是否相等。所以這道題應該是選c的。

  • 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
    string類的compareTo方法中如果兩個字符串是相同的,則得到0。而不是對與錯。

  • 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
    偽隨機數生成器相對於Math.random的優勢在於:可以創建幾個隨機數生成器,可以在一個範圍內生成隨機的int,floats和ints。所以應該包括A與B。

  • If you need to import not only the top-level of a package, but all its secondary levels as well, you should write: import package..;
    A true
    B false
    如果您不僅需要導入包的頂層, 而且還要輸入所有的輔助級別, 則應編寫: 導入包. ;(false);導入包.

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

這周的任務量挺大,而且很多東西都需要自己去編寫類並且進行調試,感覺到還有很多不足存在覺得還是要把書上的例題認認真真的敲一遍才會懂得,然後再去做課後習題。

學習進度條

代碼行數(新增/累積) 博客量(新增/累積) 學習時間(新增/累積) 重要成長
目標 5000行 30篇 400小時
第一周 180/180 2/2 20/25
第二周 312/414 2/4 20/45
第三周 557/971 2/6 25/70
第四周 1217/2242 2/8 44/114
  • 計劃學習時間:44小時

  • 實際學習時間:25小時

參考資料

  • (http://www.cnblogs.com/rocedu/p/5182332.html)

20172330 2017-2018-1 《Java程序設計》第四周學習總結