File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Program might hang Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Program might hang" Watch "Program might hang" New topic

Program might hang

Kamil Wojcik
Ranch Hand

Joined: May 19, 2008
Posts: 78

I have doubt about question 9 from Self Test (K&B - Chapter 5). I'll put a piece of code:

Case 0 will initiate an endless loop, so the correct answer is: F - The program might hang without ever completing.
My question is if on the real exam we'll see endless loop in the code, will it be always correct to choose answer that program might hang?
I run that program few times and it's never hang.
Thanks for help!

SCJP 6.0 Passed | SCWCD Passed | PSM in progress...
Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

I do not have this book with me at this point in time. Can you please post the question in its entirely ?

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Kamil Wojcik
Ranch Hand

Joined: May 19, 2008
Posts: 78


And given that line 7 will assign the value 0, 1, or 2 to sw, which are true?

A. Compilation fails
B. A ClassCastException might be thrown
C. A StackOverflowError might be thrown
D. A NullPointerException might be thrown
E. An IllegalStateException might be thrown
F. The program might hang without ever completing
G. The program will always complete without exception
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
D will also be the correct answer because case 1: has expression int y= 7 * i; Since 'i' is an Integer and is never initialized explicitly and its default value is null so a null pointer exception will be thrown.

and as you said F is also a correct answer. So, the answer to this question is D & F.

SCJP 1.6 96%
I agree. Here's the link:
subject: Program might hang
It's not a secret anymore!