It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes program giving compile time errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "program giving compile time errors" Watch "program giving compile time errors" New topic
Author

program giving compile time errors

Venkat Ramsimha
Ranch Hand

Joined: Dec 28, 2004
Posts: 127
hi,anybody please provide the solution as why the below given program is giving compile time errors

public class A45 extends Thread
{
public void run()
{
synchronized (this)
{
try
{
wait(5000);
}
catch (InterruptedException ie)
{
}
}
}
public static void main(String[] args)
{
A45 a1 = new A45();
long startTime = System.currentTimeMillis();
a1.start();
System.out.print(System.currentTimeMillis() - startTime + ",");
try
{
a1.join(6000);
}
catch (InterruptedException ie)
{
}
System.out.print(System.currentTimeMillis()-startTime);
}
}
}
Ashok Kumar
Ranch Hand

Joined: Aug 27, 2004
Posts: 93
There is a problem with the braces.Always indent your code fro better redability.Heres the code that will compile correctly

public class A45 extends Thread
{
public void run()
{
synchronized (this)
{
try
{
wait(5000);
}
catch (InterruptedException ie)
{
}
}
}

public static void main(String[] args)
{
A45 a1 = new A45();
long startTime = System.currentTimeMillis();
a1.start();
System.out.print(System.currentTimeMillis() - startTime + ",");
try
{
a1.join(6000);
}
catch (InterruptedException ie)
{
}
System.out.print(System.currentTimeMillis()-startTime);
}
}


"Decide what you want, decide what you are willing to exchange for it. Establish your priorities and go to work."
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: program giving compile time errors