Java Hello World Program

โšก Smart Summary

Java Hello World Program walks new developers through writing, compiling, and running their first Java application on Windows using only Notepad, the JDK, and the command prompt for a clean, beginner-friendly introduction.

  • ๐Ÿ‘‹ What You Build: A minimal Java class that prints Hello World to the console using System.out.println inside the main method.
  • ๐Ÿ“ Tools Required: The Java SE Development Kit (JDK 17 or 21 LTS recommended) plus any plain text editor such as Notepad, Notepad++, or an online editor.
  • โš™๏ธ Compile and Run: Use javac FirstProgram.java to compile, then run java A to execute the generated bytecode class file.
  • โœ… Case Sensitivity: Java treats file names, class names, and commands as case sensitive, so FirstProgram and firstprogram are not equivalent identifiers.
  • ๐Ÿงช Command Line Arguments: Pass values after the class name to populate the String args array and read configuration directly from the terminal.

Java Hello World Program

What Is the Java Hello World Program?

The Java Hello World Program is the traditional first exercise for anyone learning Java. It is a tiny class that prints the text Hello World to the console and demonstrates the core moving parts of every Java application: a class declaration, a main method, and an output statement. Writing and running this program confirms that the JDK is installed correctly and that the javac compiler and java runtime are reachable from your terminal.

Software You Need Before You Start

You need the following two pieces of software to create your first Java program.

1. The Java SE Development Kit

Install a current JDK release. JDK 17 and JDK 21 are long-term-support (LTS) versions and remain the recommended choices for new learners in 2026. Please refer to our previous tutorial to download and install JDK.

2. A Text Editor

In this Java Hello World example, we use Notepad. It is a simple editor included with the Windows operating system. You can use a different text editor like Notepad++, Visual Studio Code, or an online Java compiler.

Hello World Java – Your First Java Program Video

This video will help you learn how to start a Java program.

Click here if the video is not accessible

Steps to Compile and Run the Hello World Program in Java

Here is a step-by-step process on how to write, compile, and run your first Java program.

Step 1) Open Notepad from the Start menu by selecting Programs > Accessories > Notepad.

Java Hello World Program

Step 2) Create the source code for your Hello World program in Java.

  • Declare a class with the name A.
  • Declare the main method public static void main(String args[]){.
  • Now type System.out.println(“Hello World”);, which will print Hello World in Java.

Java Hello World Program

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

Step 3) Save the file for your Java Hello World program as FirstProgram.java. Make sure to select the file type as All Files while saving the file in your working folder C:\workspace.

Java Hello World Program

Step 4) Open the command prompt. Go to the directory C:\workspace. Compile the code of your Hello World Java program using the command:

javac FirstProgram.java

Java Hello World Program

Verifying the Compiled Class File

Step 5) If you look in your working folder, you can see that a file named A.class has been created. This file holds the platform-independent bytecode produced by javac.

Java Hello World Program

Step 6) To execute the code, enter the command java followed by the class name. The expected output Hello World is displayed.

java A

Java Hello World Program

Note: Java is a case-sensitive programming language. All code, commands, and file names should use consistent casing. FirstProgram is not the same as firstprogram.

Step 7) If you copy and paste the same code into an IDE like Eclipse, compiling and execution are handled with the click of a button. Using an IDE is convenient and improves productivity, but since you are learning Java, we recommend you stick with Notepad for simple Java program execution.

Java Hello World Program

What Is a Command Line Argument in Java?

A command line argument in Java is information that is passed to the program when it is executed. The information passed is stored in the String array that is supplied to the main() method, and each value is stored as a string. It is the data that directly follows the program’s name on the command line when it is launched.

Example

While running a class Demo, you can specify command line arguments as follows.

java Demo arg1 arg2 arg3 ...

Command Line Arguments in Java: Important Points

  • Command line arguments can be used to specify configuration information while launching your application.
  • There is no restriction on the number of Java command line arguments. You can specify any number of arguments.
  • Information is passed as strings.
  • The values are captured in the String args array of your main method.

Example: Learn Java Command Line Arguments

Step 1) Copy the following code into an editor.

class Demo{
     public static void main(String args[]){
         System.out.println("Argument one = "+args[0]);
         System.out.println("Argument two = "+args[1]);
    }
}

Step 2) Save and compile the code.

Step 3) Run the code as java Demo apple orange.

Command Line Arguments in Java

Step 4) You should see the following output.

Command Line Arguments in Java

FAQs

The Hello World program is the smallest possible Java application that still exercises a class, a main method, and console output. Running it successfully confirms that the JDK, the javac compiler, and the java runtime are installed and working correctly.

If the class is declared public, the file name must exactly match the class name, including casing. For non-public classes such as the simple class A in this example, the file name can differ, but matching them is still considered best practice.

The javac command is the Java compiler that converts your .java source file into a .class bytecode file. The java command is the Java runtime launcher that loads a .class file into the JVM and executes its main method.

Beginners should install a long-term-support release such as JDK 17 or JDK 21. Both versions receive security updates for several years, are widely supported by IDEs and tutorials, and run every example shown in this Hello World walkthrough without modification.

Yes. AI coding assistants such as GitHub Copilot, Amazon Q Developer, and JetBrains AI can scaffold a Hello World class, explain each keyword, and flag missing semicolons or mismatched braces, helping beginners learn Java syntax faster while still writing the code themselves.

Yes. Modern AI assistants can auto-generate Hello World variations that accept command line arguments, loop over greetings, read user input, or format the output, which helps learners explore Java features quickly without leaving their editor.

Summarize this post with: