Showing posts with label java examples. Show all posts
Showing posts with label java examples. Show all posts

Saturday, September 3, 2011

Hello World program in Java


Here is the basic java program which will help java beginners.
In every programming language when we initially starts learning,
we always find the "Hello World" program in books.
So in java same program is the first step for you to start with.


Here is the sample "Hello World" Program:

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


Please follow these steps to compile and execute this HelloWorld program.
  1. Open notepad or any type of text editor.
  2. Copy and paste above code into that text editor.
  3. Save that file and named it as "HelloWorld.java"
  4. Goto command prompt and compile this program using javac command 
    • c:\path\to\file\>javac HelloWorld.java
    • This will generate a HelloWorld.class file
  5. Now for executing that class file you have to issue following java command
    • c:\path\to\file\>java HelloWorld
  6. You will see Hello, World as the output.
I hope this post helped you in your learning. Please ask your questions by comments.