Sun國(guó)際認(rèn)證考試試題_第1頁(yè)
Sun國(guó)際認(rèn)證考試試題_第2頁(yè)
Sun國(guó)際認(rèn)證考試試題_第3頁(yè)
Sun國(guó)際認(rèn)證考試試題_第4頁(yè)
Sun國(guó)際認(rèn)證考試試題_第5頁(yè)
已閱讀5頁(yè),還剩5頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Sun國(guó)際認(rèn)證考試試題例題1:Choose the three valid identifiers from those listed below.A. IDoLikeTheLongNameClassB. $byteC. constD. _okE. 3_case解答:A, B, D點(diǎn)評(píng):Java中的標(biāo)示符必須是字母、美元符($)或下劃線(_)開(kāi)頭。關(guān)鍵字與保留字不能作為標(biāo)示符。選項(xiàng)C中的const是Java的保留字,所以不能作標(biāo)示符。選項(xiàng)E中的3_case以數(shù)字開(kāi)頭,違反了Java的規(guī)則。例題2:How can you force garbage collection of an object

2、?A. Garbage collection cannot be forcedB. Call System.gc().C. Call System.gc(), passing in a reference to the object to be garbage collected.D. Call Runtime.gc().E. Set all references to the object to new values(null, for example).解答:A點(diǎn)評(píng):在Java中垃圾收集是不能被強(qiáng)迫立即執(zhí)行的。調(diào)用System.gc()或Runtime.gc()靜態(tài)方法不能保證垃圾收集器的

3、立即執(zhí)行,因?yàn)椋苍S存在著更高優(yōu)先級(jí)的線程。所以選項(xiàng)B、D不正確。選項(xiàng)C的錯(cuò)誤在于,System.gc()方法是不接受參數(shù)的。選項(xiàng)E中的方法可以使對(duì)象在下次垃圾收集器運(yùn)行時(shí)被收集。例題3:Consider the following class:1. class Test(int i) 2. void test(int i) 3. System.out.println(“I am an int.”);4. 5. void test(String s) 6. System.out.println(“I am a string.”);7. 8.9. public static void main(

4、String args) 10. Test t=new Test();11. char ch=“y”;12. t.test(ch);13. 14. Which of the statements below is true?(Choose one.)A. Line 5 will not compile, because void methods cannot be overridden.B. Line 12 will not compile, because there is no version of test() that rakes a char argument.C. The code

5、 will compile but will throw an exception at line 12.D. The code will compile and produce the following output: I am an int.E. The code will compile and produce the following output: I am a String.解答:D點(diǎn)評(píng):在第12行,16位長(zhǎng)的char型變量ch在編譯時(shí)會(huì)自動(dòng)轉(zhuǎn)化為一個(gè)32位長(zhǎng)的int型,并在運(yùn)行時(shí)傳給void test(int i)方法。例題4:Which of the following l

6、ines of code will compile without error?A.int i=0;if (i) System.out.println(“Hi”);B.boolean b=true;boolean b2=true;if(b=b2) System.out.println(“So true”);C.int i=1;int j=2;if(i=1| j=2)System.out.println(“OK”);D.int i=1;int j=2;if (i=1 &| j=2)System.out.println(“OK”);解答:B, C點(diǎn)評(píng):選項(xiàng)A錯(cuò),因?yàn)閕f語(yǔ)句后需要一個(gè)boolean

7、類型的表達(dá)式。邏輯操作有、&、| 和 &、|,但是“&|”是非法的,所以選項(xiàng)D不正確。例題5:Which two demonstrate a has a relationship? (Choose two)A. public interface Person public class Employee extends Person B. public interface Shape public interface Rectandle extends Shape C. public interface Colorable public class Shape implements Colora

8、ble D. public class Species public class Animalprivate Species species;E. interface Component class Container implements Componentprivate Component children;解答:D, E點(diǎn)評(píng): 在Java中代碼重用有兩種可能的方式,即組合(“has a”關(guān)系)和繼承(“is a”關(guān)系)?!癶as a”關(guān)系是通過(guò)定義類的屬性的方式實(shí)現(xiàn)的;而“is a”關(guān)系是通過(guò)類繼承實(shí)現(xiàn)的。本例中選項(xiàng)A、B、C體現(xiàn)了“is a”關(guān)系;選項(xiàng)D、E體現(xiàn)了“has a”關(guān)系。例

9、題6:Which two statements are true for the class java.util.TreeSet? (Choose two)A. The elements in the collection are ordered.B. The collection is guaranteed to be immutable.C. The elements in the collection are guaranteed to be unique.D. The elements in the collection are accessed using a unique key.

10、E. The elements in the collection are guaranteed to be synchronized解答:A, C點(diǎn)評(píng):TreeSet類實(shí)現(xiàn)了Set接口。Set的特點(diǎn)是其中的元素惟一,選項(xiàng)C正確。由于采用了樹(shù)形存儲(chǔ)方式,將元素有序地組織起來(lái),所以選項(xiàng)A也正確。例題7:True or False: Readers have methods that can read and return floats and doubles.A. TureB. False解答:B點(diǎn)評(píng): Reader/Writer只處理Unicode字符的輸入輸出。float和double可以通

11、過(guò)stream進(jìn)行I/O.例題8:What does the following paint() method draw?1. public void paint(Graphics g) 2. g.drawString(“Any question”, 10, 0);3. A. The string “Any question?”, with its top-left corner at 10,0B. A little squiggle coming down from the top of the component.解答:B點(diǎn)評(píng):drawString(String str, int x, i

12、nt y)方法是使用當(dāng)前的顏色和字符,將str的內(nèi)容顯示出來(lái),并且最左的字符的基線從(x,y)開(kāi)始。在本題中,y=0,所以基線位于最頂端。我們只能看到下行字母的一部分,即字母y、q的下半部分。例題9:What happens when you try to compile and run the following application? Choose all correct options.1. public class Z 2. public static void main(String args) 3. new Z();4. 5.6. Z() 7. Z alias1 = this;8

13、. Z alias2 = this;9. synchronized(alias1) 10. try 11. alias2.wait();12. System.out.println(“DONE WAITING”);13. 14. catch (InterruptedException e) 15. System.out.println(“INTERRUPTED”);16. 17. catch (Exception e) 18. System.out.println(“OTHER EXCEPTION”);19. 20. finally 21. System.out.println(“FINALL

14、Y”);22. 23. 24. System.out.println(“ALL DONE”);25. 26. A. The application compiles but doesnt print anything.B. The application compiles and print “DONE WAITING”C. The application compiles and print “FINALLY”D. The application compiles and print “ALL DONE”E. The application compiles and print “INTER

15、RUPTED”解答:A點(diǎn)評(píng):在Java中,每一個(gè)對(duì)象都有鎖。任何時(shí)候,該鎖都至多由一個(gè)線程控制。由于alias1與alias2指向同一對(duì)象Z,在執(zhí)行第11行前,線程擁有對(duì)象Z的鎖。在執(zhí)行完第11行以后,該線程釋放了對(duì)象Z的鎖,進(jìn)入等待池。但此后沒(méi)有線程調(diào)用對(duì)象Z的notify()和notifyAll()方法,所以該進(jìn)程一直處于等待狀態(tài),沒(méi)有輸出。例題10:Which statement or statements are true about the code listed below? Choose three.1. public class MyTextArea extends TextA

16、rea 2. public MyTextArea(int nrows, int ncols) 3. enableEvents(AWTEvent.TEXT_EVENT_MASK);4. 5.6. public void processTextEvent(TextEvent te) 7. System.out.println(“Processing a text event.”);8. 9. A. The source code must appear in a file called MyTextArea.javaB. Between lines 2 and 3, a call should b

17、e made to super(nrows, ncols) so that the new component will have the correct size.C. At line 6, the return type of processTextEvent() should be declared boolean, not void.D. Between lines 7 and 8, the following code should appear: return true.E. Between lines 7 and 8, the following code should appe

18、ar: cessTextEvent(te).解答:A, B, E點(diǎn)評(píng):由于類是public,所以文件名必須與之對(duì)應(yīng),選項(xiàng)A正確。如果不在2、3行之間加上super(nrows,ncols)的話,則會(huì)調(diào)用無(wú)參數(shù)構(gòu)建器TextArea(), 使nrows、ncols信息丟失,故選項(xiàng)B正確。在Java2中,所有的事件處理方法都不返回值,選項(xiàng)C、D錯(cuò)誤。選項(xiàng)E正確,因?yàn)槿绻患觕essTextEvent(te),注冊(cè)的listener將不會(huì)被喚醒。SCJP考試中的幾點(diǎn)注意 深刻理解面向?qū)ο蟮乃枷隞ava是一種純粹的面向?qū)ο蟮某绦蛟O(shè)計(jì)語(yǔ)言。在正式使用Java做開(kāi)發(fā)之前,必須將我們的思維方式轉(zhuǎn)入一個(gè)徹底的面向?qū)ο蟮氖澜纭W霾坏竭@一點(diǎn),就無(wú)法體會(huì)Java語(yǔ)言的精髓,寫(xiě)不出地道的Java程序。當(dāng)然,你也無(wú)法徹底理解Java中的基本概念和他們之間的聯(lián)系與區(qū)別,如例題3、例題5。你可以學(xué)到Java的語(yǔ)法規(guī)則,卻不能看到Java的靈魂。 對(duì)概念細(xì)節(jié)的精確把握通過(guò)例題我們可以看到,SCJP的考察點(diǎn)相當(dāng)細(xì)致。如例題1、2、4、7、8。所以只有對(duì)Java的概念、語(yǔ)法、規(guī)則了然于

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論