日本国产亚洲-日本国产一区-日本国产一区二区三区-日本韩国欧美一区-日本韩国欧美在线-日本韩国欧美在线观看

當(dāng)前位置:雨林木風(fēng)下載站 > 技術(shù)開發(fā)教程 > 詳細(xì)頁面

SCJP考題中的陷阱

SCJP考題中的陷阱

更新時(shí)間:2022-05-08 文章作者:未知 信息來源:網(wǎng)絡(luò) 閱讀次數(shù):

最近在網(wǎng)上閑逛時(shí)偶然發(fā)現(xiàn)此文章,基本上指出了SCJP的出題陷阱,讀過后覺得其列的還比較詳細(xì),故貼與此,希望能對打算考SCJP的朋友有一些幫助.此文雖是E文,但句法簡單,很容易理解,而且我在大部分后面加了一些注釋"()",對新手可能會(huì)有幫助.
 SCJP考題中的陷阱
原著 Ajith Kallambella


(1) Two public classes in the same file. (illegal)

(2) Main method calling a non-static method. (illegal)

(3) Methods with the same name as the constructor(s). (這種題常有)

(4) Thread initiation with classes that do not have a run() method. (常考之題)

(5) Local inner classes trying to access non-final vars. (illegal)

(6) Case statements with values out of permissible range. (byte,int, short, chat)

(7) Math class being an option for immutable classes !! (totally wrong!)

(8) instanceOf is not same as instanceof.

(9) Private constructors. (legal)

(10) An assignment statement which looks like a comparison. (比如說if(a=true),對于這種題眼睛亮一點(diǎn))

(11) System.exit() in try-catch-finally blocks. (finally 不會(huì)執(zhí)行)

(12) Order of try-catch-finally blocks matters. (若順序錯(cuò)的話: error: No try before catch)

(13) main() can be declared final. (OK)

(14) -0.0 == 0.0 is true.

(15) A class without abstract methods can still be declared abstract.

(16) RandomAccessFile descends from Object and implements DataInput and DataOutput.

(17) Map does not implement Collection.

(18) Dictionary is a class, not an interface.

(19) Collection is an Interface where as Collections is a helper class. (這題我倒沒見過,但還真容易看混)

(20) Class declarations can come in any order.
(也就是說: class Child extends Parents{}
 class Parents{}
 這種順序是可以的.)

(21) Forward references to variables gives compiler error.

(22) Multi dimensional arrays can be sparce.
(這句話是說: 多維數(shù)組中子數(shù)組不一定必須有一定個(gè)數(shù)的元素,比如我們把一個(gè)二維數(shù)組看成一個(gè)矩陣,那么行與列中的元素可以不完整,可以不對齊.)

(23) Arrays, whether local or class-level, are always initialized.

(24) Strings are initialized to null, not empty string.

(25) An empty string is NOT the same as a null string.

(26) A declaration cannot be labelled.

(27) "continue" must be in a loop(for, do, while). It cannot appear in case constructs.

(28) Primitive array types can never be assigned to each other, eventhough the primitives themselves can be assigned.
(也就是說: ArrayofLongPrimitives = ArrayofIntegerPrimitives 會(huì)編譯出錯(cuò),但 longvar = intvar 是合法的)

(29) A constructor can throw any exception.

(30) Initilializer blocks are executed in the order of declaration.

(31) Instance initializer(s) gets executed ONLY IF the objects are constructed.

(32) All comparisons involving NaN and a non-Nan would always result false. (對大多數(shù)朋友來說這可是個(gè)盲點(diǎn)噢)

(33) Default type of a numeric literal with a decimal point is double.
(我在這里把Java成員變量默認(rèn)初始化原則寫一下:
 成員變量類型取值
 byte0
 short 0
 int 0
 long0L
 char'\u0000'
 float 0.0F
 double0.0D
 boolean false
 所有引用類型 null)

(34) integer (and long ) operations / and % can throw ArithmeticException while float / and % will never, even in case of division by zero.

(35) == gives compiler error if the operands are cast-incompatible.

(36) You can never cast objects of sibling classes( sharing the same parent ), even with an explicit cast.

(37) .equals returns false if the object types are different.It does not raise a compiler error.

(38) No inner class can have a static member.(but static inner class can)

(39) File class has NO methods to deal with the contents of the file.(also the existing directory)

(40) InputStream and OutputStream are abstract classes, while DataInput and DataOutput are interfaces.


當(dāng)然以上這些都是從題目中總結(jié)出來的技巧,其實(shí)書上也都有,大家還是多看看書噢.


真不錯(cuò)。。。早點(diǎn)出來就好了。。。呵呵。。。偶幫忙翻譯一下。。。
有 “(請?zhí)嵋庖?” 的,大家討論一下。謝謝
(1) Two public classes in the same file. (illegal)
 同一個(gè)文件里有兩個(gè)public類。(非法)

(2) Main method calling a non-static method. (illegal)
 在main(String[] args)方法內(nèi)調(diào)用一個(gè)非靜態(tài)方法。(非法)

(3) Methods with the same name as the constructor(s). (這種題常有)
 與Constructor(s)有相同名字的方法。

(4) Thread initiation with classes that do not have a run() method. (常考之題)
 初始化了一個(gè)沒有run()方法的線程類。

(5) Local inner classes trying to access non-final vars. (illegal)
 內(nèi)部類嘗試訪問非final變量(非法)

(6) Case statements with values out of permissible range. (byte,int, short, chat)
 選擇語句case中,沒有使用允許的值。如(byte,int,short,char)等

(7) Math class being an option for immutable classes !! (totally wrong!)
 Math類作為不可改變類。(完全錯(cuò)誤) (請?zhí)嵋庖?

(8) instanceOf is not same as instanceof.
 instanceOf 不是 instanceof。

(9) Private constructors. (legal)
 私有 的Constructor。 (合法)

(10) An assignment statement which looks like a comparison.
一個(gè) 賦值語句 看起來像 比較語句。
比如說if(a=true),和if(a==true)。對于這種題眼睛亮一點(diǎn)。

(11) System.exit() in try-catch-finally blocks. (finally 不會(huì)執(zhí)行)
在try-catch-final塊中的退出語句。 (finally不會(huì)執(zhí)行)

(12) Order of try-catch-finally blocks matters. (若順序錯(cuò)的話: error: No try before catch)
try-catch-final塊的順序問題。

(13) main() can be declared final. (OK)
main()方法 可以聲明為 final.

(14) -0.0 == 0.0 is true.
如題。

(15) A class without abstract methods can still be declared abstract
沒有 抽象方法的類,仍然可以定義為抽象類。

(16) RandomAccessFile descends from Object and implements DataInput and DataOutput.
RandomAccessFile 類繼承Object,并且實(shí)現(xiàn)了DataInput和DataOutput接口。

(17) Map does not implement Collection.
Map 并不實(shí)現(xiàn) Collection.

(18) Dictionary is a class, not an interface.
Dictionary 是一個(gè)類,不是接口。

(19) Collection is an Interface where as Collections is a helper class. (這題我倒沒見過,但還真容易看混)
Collection是一個(gè)接口,但 Collections卻是一個(gè)輔助類。

(20) Class declarations can come in any order.
 (也就是說: class Child extends Parents{}
class Parents{}
這種順序是可以的.)
可以以任何順序申明類。

(21) Forward references to variables gives compiler error.
把 reference 給 變量,會(huì)產(chǎn)生編譯錯(cuò)誤。 (請?zhí)嵋庖?

(22) Multi dimensional arrays can be sparce.
(這句話是說: 多維數(shù)組中子數(shù)組不一定必須有一定個(gè)數(shù)的元素,比如我們把一個(gè)二維數(shù)組看成一個(gè)矩陣,那么行與列中的元素可以不完整,可以不對齊.)
如jiayuan所說。

(23) Arrays, whether local or class-level, are always initialized.
數(shù)組,無論是當(dāng)前的,還是類等級的,都會(huì)被初始化。

(24) Strings are initialized to null, not empty string.
String 是被初始化為 null,不是空字符。

(25) An empty string is NOT the same as a null string.
一個(gè)空字符串 不是 一個(gè)null字符。

(26) A declaration cannot be labelled.
一個(gè)聲明語句不能被標(biāo)記。

(27) "continue" must be in a loop(for, do, while). It cannot appear in case constructs.
“continue”已經(jīng)要在一個(gè)循環(huán)里(如for,do,while),它不能在case語句中出現(xiàn)。

(28) Primitive array types can never be assigned to each other, eventhough the primitives themselves can be assigned.
 (也就是說: ArrayofLongPrimitives = ArrayofIntegerPrimitives 會(huì)編譯出錯(cuò),
但 longvar = intvar 是合法的)

 Primitive(int,char,long等)數(shù)組是不能互相賦值的,即使它們本身可以。
 解釋見jiayuan所說。

(29) A constructor can throw any exception.
一個(gè)Constructor可以拋出任何異常。

(30) Initilializer blocks are executed in the order of declaration.
初始化塊是按照聲明的順序執(zhí)行的。(請?zhí)嵋庖?

(31) Instance initializer(s) gets executed ONLY IF the objects are constructed.
實(shí)例初始化語句塊只有在它建立后才會(huì)被執(zhí)行。

(32) All comparisons involving NaN and a non-Nan would always result false. (對大多數(shù)朋友來說這可是個(gè)盲點(diǎn)噢)
所有關(guān)于 NaN(Not a Number) 和 non-NaN 的比較,都返回false.
這條很重要。

(33) Default type of a numeric literal with a decimal point is double.
我在這里把Java成員變量默認(rèn)初始化原則寫一下:
 成員變量類型取值
byte0
 short 0
 int 0
 long0L
 char'\u0000'
 float 0.0F
 double0.0D
 boolean false
 所有引用類型null

(34) integer (and long ) operations / and % can throw ArithmeticException while float / and % will never, even in case of division by zero.
integer和long 操作 /和% 的話, 會(huì)拋出ArithmeticException,
 但是 float形不會(huì),即使是除以0。

(35) == gives compiler error if the operands are cast-incompatible.
==會(huì)產(chǎn)生編譯錯(cuò)誤,如果兩邊 不兼容的話。

(36) You can never cast objects of sibling classes( sharing the same parent ), even with an explicit cast.
 你永遠(yuǎn)不可能 轉(zhuǎn)化具有同一個(gè)超類的類的對象,即使是刻意轉(zhuǎn)化。(請?zhí)嵋庖?

(37) .equals returns false if the object types are different.It does not raise a compiler error.
equals() 返回 false 如果對象類型不同,但不產(chǎn)生 編譯錯(cuò)誤。

(38) No inner class can have a static member.(but static inner class can)
沒有內(nèi)部類 可以擁有 靜態(tài)成員。(但靜態(tài)內(nèi)部類可以)

(39) File class has NO methods to deal with the contents of the file.(also the existing directory)
File類沒有 任何 處理文件內(nèi)容的方法。(當(dāng)然,存在的目錄也一樣)

(40) InputStream and OutputStream are abstract classes, while DataInput and DataOutput are interfaces.
InputStream 和 OutputStream 是 抽象類,
 但是 DataInput 和 DataOutput是 接口。

當(dāng)然以上這些都是從題目中總結(jié)出來的技巧,其實(shí)書上也都有,大家還是多看看書噢.

溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統(tǒng)下載排行

主站蜘蛛池模板: 天天干天天色天天射 | 亚洲另类在线视频 | 久久久久久久岛国免费观看 | 成人手机在线观看 | 日韩一二区 | 边摸边操| 青青草国拍2019 | 一级毛片日韩a欧美 | 久久99久久精品视频 | 国产精品18久久久久久久久久 | 免费三级大片 | 精品国产成人a区在线观看 精品国产成人高清在线 | 国产无遮挡又黄又爽在线视频 | 亚洲国产日韩精品怡红院 | 国产一区二区三区精品视频 | 污污短视频 | 久久精品国产福利国产琪琪 | 精品免费久久久久久影院 | 精品999久久久久久中文字幕 | 韩国一级网站 | 亚洲成年人在线观看 | 亚洲视频日韩 | 91天堂在线观看 | 精品国产一区二区三区免费 | 国产免费一区二区三区免费视频 | 国产成人一区二区三区影院免费 | 国产精品一区二区三区免费 | 一区二区三区影视 | 国产精品夜夜春夜夜爽久久 | 欧美中文综合在线视频 | 国产3344永久在线观看视频 | 999久久狠狠免费精品 | 91免费视频网 | 夜夜骑日日操 | 欧美日产欧美日产精品 | 亚洲视频在线免费 | 久久久久亚洲国产 | 亚洲国产精品大秀在线播放 | 日本中文字幕在线看 | 日本三级香港三级网站 | 在线日韩国产 |