Tuesday, November 22, 2011

The first Java program - Hello World

Once you have the Java program properly installed, you are ready to try out the "Hello World". Open an text editor and enter the following,

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

and save it as HelloWorld.java. Be sure the extension name is java.

Then open the command prompt and move to the directory where HelloWorld.java is saved. To compile the java program, run the command "javac HelloWorld.java". You should get another file named HelloWorld.class if the program has be successfully compiled. Then issue the command "java HelloWorld" and you will see "Hello World" printed out on the screen.











No comments:

Post a Comment