SUN認證Java2程式設計師考試(SCJP) 試題解析(3)

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. 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(“interr 
upted”); 
16. } 
17. catch (exception e) { 
18. system.out.println(“other exception”); 
19. } 
20. finally { 
21. system.out.println 
(“finally”); 
22. } 
23. } 
24. system.out.println(“all done”); 
25. } 
26. } 
a. the application compiles but doesn’t 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 “interrupted” 
解答:a 
點評:在java中,每一個對象都有鎖。任何時候,該鎖都至多由一個線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. 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(“interr 
upted”); 
16. } 
17. catch (exception e) { 
18. system.out.println(“other exception”); 
19. } 
20. finally { 
21. system.out.println 
(“finally”); 
22. } 
23. } 
24. system.out.println(“all done”); 
25. } 
26. } 
a. the application compiles but doesn’t 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 “interrupted” 
解答:a 
點評:在java中,每一個對象都有鎖。任何時候,該鎖都至多由一個線ent(te),註冊的listener將不會被喚醒。 

scjp考試中的幾點注意: 

● 深刻理解面向對象的思想 
java是一種純粹的面向對象的程式設計語言。在正式使用java做開發之前,必須將我們的思維方式轉入一個徹底的面向對象的世界。做不到這一點,就無法體會java語言的精髓,寫不出地道的java程式。當然,你也無法徹底理解java中的基本概念和他們之間的聯繫與區別,如例題3、例題5。你可以學到java的語法規則,卻不能看到java的靈魂。 

● 對概念細節的精確把握 
通過例題我們可以看到,scjp的考察點相當細緻。如例題1、2、4、7、8。所以只有對java的概念、語法、規則瞭然於心,才能在考場上應對自如。 

● 適量的練習 
程式設計是一項實踐性很強的技術。只有上機實踐,才能使課本中的理論、頭腦中的思想通過你的雙手成為一行行代碼,完成規定的目標。雖然scjp考試不考操作與編程,但有大量的程式閱讀,如例題3、4、9、10。如果你自己寫過許多代碼的話,這種題就是小菜一碟。 

● 廣泛的交流 
善於交流是優秀程式設計師必備的技能,也是你解決疑難,提高水平的捷徑。國內外有很多與java認證相關的優秀網站和論壇,都是學習java的寶庫。同時,一些很棒的模考軟體,如jxam、jtest、 javacert等,以及著名的模考題如marcusgreen的三套題均可以找到。