I have both JDK 1.2.2 and JDK 1.3 in my machine. I think that there is no path setup problem because I have completed
Java projects for the Java-fundamental course I took, and I have written numeous small Java programs
ant tested them out.
Nevertheless, I have problems with compiling
Thread programs (all the small Thread programs that I have). Finally, I tried to copy and paste one of the example programs in the book entitled "Java How to Program" by Dietel and Dietel. I believe there is nothing wrong with that program (see below), and I was not able to compile that program either, especially the name of the program is ThreadTester. The error message was:
file C:\javaprj\Thread.java does not contain type Thread as expected. Please adjust the class path so that the file does not appear in the unnamed package.
Here is the program:
public class ThreadTester {
public static void main(
String args[] )
{
PrintThread thread1, thread2, thread3, thread4;
thread1 = new PrintThread( "thread1" );
thread2 = new PrintThread( "thread2" );
thread3 = new PrintThread( "thread3" );
thread4 = new PrintThread( "thread4" );
System.err.println( "\nStarting threads" );
thread1.start();
thread2.start();
thread3.start();
thread4.start();
System.err.println( "Threads started\n" );
}
}
class PrintThread extends Thread {
private int sleepTime;
// PrintThread constructor assigns name to thread
// by calling Thread constructor
public PrintThread( String name )
{
super( name );
// sleep between 0 and 5 seconds
sleepTime = (int) ( Math.random() * 5000 );
System.err.println( "Name: " + getName() +
"; sleep: " + sleepTime );
}
// execute the thread
public void run()
{
// put thread to sleep for a random interval
try {
System.err.println( getName() + " going to sleep" );
Thread.sleep( sleepTime );
}
catch ( InterruptedException exception ) {
System.err.println( exception.toString() );
}
// print thread name
System.err.println( getName() + " done sleeping" );
}
}
Would anybody kindly give a hand.