I have created classes in eclipse under package "first" inside src. I will execute fine in eclipse. But when I tried to run from the command prompt it will say
"Error: Could not find or load main class CreatingThread".
But when I copy out same classes into some other folder and remove package first
it will work fine.
I have set environment variables as below:
path %JAVA_HOME%\lib;C:\Program Files\Java\jre1.8.0_144\bin
classpath %JAVA_HOME%\lib\tools.jar;.;
And these are the classes
package first;
public class CreatingThread {
public static void main(String[] args) {
System.out.println(Thread.currentThread().getName());
System.out.println(Thread.currentThread().getPriority());
System.out.println(Thread.currentThread().getThreadGroup());
for(int i=0;i<=25;i++) {
System.out.println(Thread.currentThread().getName()+" "+i);
}
MyThread myThread= new MyThread();
myThread.setName("Child Thread");
myThread.getThreadGroup();
myThread.start();
System.out.println("Done");
}
}
Second class
package first;
public class MyThread extends Thread {
@Override
public void run() {
for(int i=0;i<=25;i++){
System.out.println("child thread "+i);
}
}
}