
This tutorial is targeted for Java beginners. In this tutorial, we’ll walk you through how to write a simple Hello World Java program using Notepad, compile and run the Java program using command line.
What We Used
- Microsoft Windows 7
- Oracle JDK 1.7
- Notepad Text Editor
1. Install JDK
Download Oracle JDK 1.7 installer from Oracle JDK download page and install it on your Windows operating system.
2. Set Up JAVA_HOME and PATH
After JDK is installed, set up JAVA_HOME environment variable and add the JDK bin directory to the system’s PATH.
3. Write Hello World Program
Open Notepad text editor, write the Hello World program and save the file at any location you want with the file name HelloWorld.java. In this tutorial, I will save the file to C:\ directory.
C:\HelloWorld.java
// Java Hello World Program
public class HelloWorld {
public static void main(String[] args) {
// Display the message on command prompt
System.out.println("Chankok.com - Hello World!");
}
}
main method is the starting point of Java application when we run the Java program.4. Compile Java Program
Open command prompt window, go to the directory where the HelloWorld.java you saved in Step 3.
Compile the HelloWorld.java with the following command:
javac HelloWorld.java
javac is a Java compiler to transform the Java source code into bytecode.After compilation is complete, a HelloWorld.class file will be generated under the same directory. This compiled file will be used by JVM to run the Hello World program.
5. Run Java Program
Use the following command to run the Hello World program in the command prompt window:
java HelloWorld
A message Chankok.com - Hello World! will be displayed on the command prompt window. The output will look like this:

Summary
Congratulations! You have just learned to set up your Java development environment on Windows to develop your first Hello Word Java program using Notepad. You also have learned how to compile and run the Java program using command line.