Mar 4, 2010

Java Hello Word

1) Download JDK
Just download SUN JDK from http://java.sun.com/javase/downloads/index.jsp
Choose the latest version of JDK, download and install to your PC.

2) Test JDK
You may now test the JDK to make sure you have installed it correctly.
Open your Command Prompt, and type : java -version
This command will show you the java version installed in your PC.

3) Hello World
Yes, hello world again... Open your note pad or other writing software, type in the following :

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

Save it as HelloWorld.java in a particular folder, let say in C:\Java

4) Compile & Run
Open Command Prompt again, and change directory to C:\Java.
Type : javac HelloWorld.java (To Compile the source)
A HelloWorld.class file will be generated in
C:\Java
Type : java HelloWorld (To Run the class file)

You will see this on the Command Prompt :

Hello, world!






No comments: