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 Wait() doubt 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 "Wait() doubt" Watch "Wait() doubt" New topic

Wait() doubt

Mamadou Touré
Ranch Hand

Joined: Dec 27, 2007
Posts: 189
This question is from the examulator mock exam

public class Agg{
public static void main(String argv[]){
Agg a = new Agg();
public void go(){
DSRoss ds1 = new DSRoss("one");

class DSRoss extends Thread{
private String sTname="";
DSRoss(String s){
sTname = s;
public void run(){
public void notwait(){
}catch(InterruptedException ie){}


1 It will cause a compile time error
2 Compilation and output of "waiting"
3 Compilation and output of "waiting" followed by "finished"
4 Runtime error, an exception will be thrown

I choosed 1 (compile time error) because the wait is done without synchronize, but in the answer it's said the correct response is 4 (Runtime error) for the same reason (wait without synchronize).

When I try to compile this code, it shows a compile error (as I I reponded). So is the java.lang.IllegalMonitorStateException compile time or a runtime error ?

SCJP 5 (76%)
SCWCD 5 (86%)
SCBCD 5(70%)
"The greatest glory in living lies not in never falling, but in raising every time we fall.".. Nelson Mandela
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
I tried the code -> compiles without problems, but throws an llegalMonitorStateException. If you look in its API description, you see, that it's derived from runtime exception, so it is an unchecked exception.
[ July 19, 2008: Message edited by: Ralph Jaus ]

SCJP 5 (98%) - SCBCD 5 (98%)
I agree. Here's the link:
subject: Wait() doubt
It's not a secret anymore!