First program in Java

Open an editor like: Notepad, Sublime etc and write.

class HelloWorld
   public static void main(String args[])
      System.out.println("Hello World!");

Save this file as “” (save as Class name)

Go to command prompt: (javac for compile and java for run)

D:/>java HelloWorld


D:/>java HelloWorld

Hello Java


Details first java program

Let’s see what is the meaning of class, public, static, void, main, String[], System.out.println().

  • class( keyword) is used to declare a class in java.
  • public keyword is an access modifier which is visible to all.
  • static keyword no need to create an object to call the static method. The main method is executed by the JVM.
  • void is the return type of the method which means return no value.
  • main is method where all program start.
  • String[] args is used for command line argument.
  • System.out.println() method is used print the statement.
java java tutorials learn java study java