How to compile a Java program - javac

By: Abinaya Printer Friendly Format    

One source file,, defines a class called greetings.Hello. The greetings directory is the package directory both for the source file and the class file and is off the current directory. This allows us to use the default user class path. It also makes it unnecessary to specify a separate destination directory with -d.

C:> dir
C:> dir greetings
C:> cat greetings\
package greetings;

public class Hello {
    public static void main(String[] args) {
        for (int i=0; i < args.length; i++) {
            System.out.println("Hello " + args[i]);
C:> javac greetings\
C:> dir greetings
C:> java greetings.Hello World Universe Everyone
Hello World
Hello Universe
Hello Everyone

Most Viewed Articles (in Java )

Latest Articles (in Java)

Comment on this tutorial