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考試中的幾點注意:
● 深刻理解面向?qū)ο蟮乃枷?nbsp;
java是一種純粹的面向?qū)ο蟮某绦蛟O(shè)計語言。在正式使用java做開發(fā)之前,必須將我們的思維方式轉(zhuǎn)入一個徹底的面向?qū)ο蟮氖澜纭W霾坏竭@一點,就無法體會java語言的精髓,寫不出地道的java程序。當(dāng)然,你也無法徹底理解java中的基本概念和他們之間的聯(lián)系與區(qū)別,如例題3、例題5。你可以學(xué)到j(luò)ava的語法規(guī)則,卻不能看到j(luò)ava的靈魂。
● 對概念細(xì)節(jié)的精確把握
通過例題我們可以看到,scjp的考察點相當(dāng)細(xì)致。如例題1、2、4、7、8。所以只有對java的概念、語法、規(guī)則了然于心,才能在考場上應(yīng)對自如。
● 適量的練習(xí)
程序設(shè)計是一項實踐性很強的技術(shù)。只有上機實踐,才能使課本中的理論、頭腦中的思想通過你的雙手成為一行行代碼,完成規(guī)定的目標(biāo)。雖然scjp考試不考操作與編程,但有大量的程序閱讀,如例題3、4、9、10。如果你自己寫過許多代碼的話,這種題就是小菜一碟。
● 廣泛的交流
善于交流是優(yōu)秀程序員必備的技能,也是你解決疑難,提高水平的捷徑。國內(nèi)外有很多與java認(rèn)證相關(guān)的優(yōu)秀網(wǎng)站和論壇,都是學(xué)習(xí)java的寶庫。同時,一些很棒的模考軟件,如jxam、jtest、 javacert等,以及著名的模考題如marcusgreen的三套題均可以找到。