If you need to compile multiple Java files using a single command, then you can do the following.

First, it’s good to learn how to compile a Java file.

How to Compile a Java File

Let’s take the following Java code:

1
2
3
4
5
class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello World");
  }
}

To compile this, we simply do the following:

1
javac HelloWorld.java

Then when we need to run it, we do:

1
java HelloWorld

We now get the output of Hello World.

How to Compile All Java Files in the Current Directory

If you have multiple files in your current directory, then you can issue the following command:

1
javac *.java

Alternatively, you can specify a directory where your Java files live:

1
javac /some/directory/path/*.java