標籤:correct 導致 可變 top 通過 bin sage 產生 nes
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 |
|
參考資料
- (http://www.cnblogs.com/rocedu/p/5182332.html)
20172330 2017-2018-1 《Java程式設計》第四周學習總結