Our first program obviously will print the classic “hello world” message. Here’s the full source code.


To run the program compile using javac command and run the compiled class using java command.

public class HelloWorld {
  // to run a Java program it should have a main method
  public static void main(String[] args) {
      // print line to stdout
      System.out.println("Hello, World!");
  }
}
  • compile and run
 javac HelloWorld.java # compile
 java HelloWorld # run
  • or run directly
java HelloWorld.java # compile and run
  • output
Hello, World!