View Full Version : Compile many file.java

04-18-2004, 12:05 AM
My friend downloaded a java source game, my question is, is there a way to compile all .java files at one time?

I normally do this to a single file, javac file.java

what if there is 10 java files?

04-18-2004, 01:09 AM
If you have all the classes in one file like file.java then all the classes will compile into their respective class files. So for example if you had your Main.java file with this:

import java.io.*;

class Main{

public static void main(String args[]) throws IOException{

String name;
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

System.out.print("What is this new person's name: ");
name = stdin.readLine();
Person person = new Person(name);

System.out.println("A new person was created with the name " + person.getName());

class Person{

private String name;

public Person(String name){
this.name = name;

public String getName(){
return name;

Now when you compile Main.java you will notice that you end up with two files Main.class and Person.class.

04-18-2004, 01:28 AM

I am asking, is there a way to compile more than one .java file?

If I have 10 .java files, how do I compile them without known the order of it? some java file needs the java file to create an object.

04-18-2004, 01:41 AM
Well you don't have to know the order of the classes. Java handles all that. Ok then download some free java ide that has a feature for creating projects and will allow you to just compile everything in the project then just add all the java files to the project.

04-18-2004, 01:46 AM
ok, if I have num1.java and in num1.java has:
public num2 myObject = new num2();

but if I compile num1.java before num2.java, the compiler will say cannot file num2

so I have to compile num2.java, then compile num1.java

04-18-2004, 02:14 AM
You wouldn't be compiling more than one java file. As I showed in my first post all the classes are in the same java file. Then you compile just that one java file. Java will figure out where everything is at.

Anyways just download some free java ide as I mentioned and do it that way. JCreator is a popular one.


04-18-2004, 09:28 AM
You can just compile them like this:

javac *.java

The compiler takes care of the dependencies.


04-18-2004, 07:29 PM
javac *.java, that's cool, thanx :)