I am new to Eclipse and java programming, so please be gentle and any help is highly appreciated.
I recently wrote a program using java and Eclipse IDE.
I made the following class:
package Test;
import java.util.*;
import Test.AnotherClass;
public class Program{
public static void main(String[] args){
AnotherClass ac = new AnotherClass();
ac.callingAMethod();
}
}
This class resides in a file named Program.java and I made another file named AnotherClass.java which is implemented like this:
package Test;
import java.util.*;
public class AnotherClass{
public void callingAMethod(){
System.out.println("Hello, World!");
}
}
Now, if I use Eclipse then the program runs perfectly and even shows the output as "Hello, World!" in the console of Eclipse. But if I use Terminal and javac to compile it gives me the following error:
Program.java:3: error: cannot find symbol import Test.AnotherClass; ^ symbol: class AnotherClass location: package Test Program.java:58: error: cannot find symbol AnotherClass ac = new AnotherClass(); ^ symbol:
class AnotherClass location: class Program Program.java:58: error: cannot find symbol AnotherClass ac = new AnotherClass(); ^ symbol: class AnotherClass location: class Program 3 errors
Another issue is Eclipse creates built in .class files in /bin and if i execute then on the Terminal then it gives me the following error:
Error: Could not find or load main class Program
I can not happen to find the issue, how come the program can compile in Eclipse IDE and show the output as well, whereas when I use 'javac' to compile and then use 'java' to run it is throwing errors.
Any help is appreciated. Thank you.
javac?