How do I compile and run the following programs:
Test1.java:
package A;
public class Test1
{
public int a = 1;
}
Test2.java:
You need to keep your java files in the correct directory structure:
A/Test1.java
B/Test2.java
It's usually sufficient to only invoke javac
on your main class, as all dependencies will be handled automatically. After I say javac B/Test2.java
, it looks like this:
A/Test1.class
A/Test1.java
B/Test2.class
B/Test2.java
And I can run the program with java B.Test2
.
If it's not enough just to run javac
on your main class, you'll probably need a build system.