How do I compile a program with multiple classes in cmd?

Posted 22 April 2011 - 02:24 PM

When I try to compile a Java program with more than just the main class in the command prompt, I find that the classes other than the main one compile with no problem, but when I try to compile the main with variables connected to the other classes it doesn't know what the variables are. I compiled the other classes first, and all classes are in a directory together.

Sorry about the wording, I'm not sure what you would call 'classes other than main' and such. I'm clearly pretty new.

Re: How do I compile a program with multiple classes in cmd?

Re: How do I compile a program with multiple classes in cmd?

Posted 22 April 2011 - 02:57 PM

If you are compiling many classes in the same directory then say:

javac *.java

But what I know is that, if you only compile the class with the main method then the dependent classes are compiled together. If not working then try the above command which means every file with .java extension in that directory.

Re: How do I compile a program with multiple classes in cmd?

Posted 22 April 2011 - 03:50 PM

That did the trick, but I'm sort of confused about why the compiler can recognise that it is intended for one program by noticing that it is in the same directory when you use *.java but it can't recognise that the already compiled class is part of the main when you try to compile them seperately.

Re: How do I compile a program with multiple classes in cmd?

Posted 22 April 2011 - 04:03 PM

AVReidy, on 22 April 2011 - 05:50 PM, said:

That did the trick, but I'm sort of confused about why the compiler can recognise that it is intended for one program by noticing that it is in the same directory when you use *.java but it can't recognise that the already compiled class is part of the main when you try to compile them seperately.

Actually it depends
If every time you modify a that.java you >javac that.java it will work
If you modify 2 or more .java files without re-compiling every change then a > javac *.java is the easiest/laziest not expensive solution