< Java Tutorial

Java first program

← Previous Next →


Let us Look a simple Java Program

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

Steps to run above program :

Step 1: Open a text editor and paste the above code. 

Step 2: Save the file as HelloWorld.java

 

Step 3: Open command prompt and go to the directory where you saved your first java program assuming it is saved in  C:\java

 

 Step 4:  Type javac Hello.java and press Enter to compile your code.

This command will call the Java Compiler asking it to compile the specified file. If there are no errors in the code the command prompt will take you to the next line.

 

Step 5: Now type java HelloWorld on command prompt to run your program.

 

Step 6: You will be able to see "Hello, World"  printed on your command prompt.

← Previous Next →