Write Your First Java Hello World Program Using Notepad

Write Java Using Notepad

This tutorial is targeted for Java beginner. 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

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 installed, set up JAVA_HOME environment variable and add the JDK bin directory to the system’s PATH.

Note: This set up is required for you to compile and run Java program using command line.

3. Write Hello World Program

Open Notepad text editor, write the Hello World program and save the file at any location you want with 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!"); 

    }	

}

Tip: The main method is the starting point of Java application when we run the Java program.

Note: Java file name must same with Java class name.

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

Tip: javac is Java compiler to transform the Java source code to bytecode.

After compilation complete, a HelloWorld.class file will be generated under same directory. This compiled file will used by JVM to run the Hello World program.

5. Run Java Program

Use the following command to run the Hello World program in command prompt window:

java HelloWorld

A message Chankok.com - Hello World! will be displayed on command prompt window. The output will look like:

Run Java Command Using Command Line

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.