Im trying to open a java file where I reference an other java file. Setup as follows: I have classes A, B and C like the following:
class A:
package proj;
public class A {
public static void main(String[] args) {
B b = new B();
}
}
class B:
package proj;
public class B {
C c;
}
class C:
package proj;
public class C {
B b;
}
When I try to type in terminal javac A.java
, an error occurrs (see below). Same when I try javac B.java
or javac C.java
. How can I start my java programm?
error:
Desktop\test\proj> javac A.java
A.java:5: error: cannot find symbol
B b = new B();
^
symbol: class B
location: class A
A.java:5: error: cannot find symbol
B b = new B();
^
symbol: class B
location: class A
2 errors
You can compile the set of files – A.java, B.java, and C.java – by using javac
and a wildcard, like this:
javac *.java
To run (or "start") your program, you would use java
to start the Java Virtual Machine, followed by whatever classes or jars you want to run in the JVM.
Here's a section in the Java Tutorial which includes examples for compiling and running in Windows, and a similar example for Mac, Linux and Solaris.