Skip to content

Compile Java programs using javac

javac is a Java compilers.

This page describes how to compile Java code using javac.

Procedure

1. Load a GCC module

Before compiling a java program, the java module has to be loaded. To load the java module, enter the command:

module load java

2. Create a Java source file

Create and write a Java source file called hello_world.java:

nano hello_world.java

In nano, write the Java program as such:

class hello_world
{
  public static void main(String[] args)
  {
    System.out.println("hello, world");
  }
}

3. Compile the source file

To compile, enter the command:

javac hello_world.java

4. Run

to run, enter:

java hello_world