JavaJava First Program

Java First Program

Understanding the Basics

Starting your journey with Java begins with writing your first program. This isn’t just tradition — it’s a practical way to understand how Java works under the hood. The classic "Hello, World!" program is simple, but it introduces key concepts that every Java developer must know.

What You’ll Learn
  • How to write and structure a basic Java program

  • The role of the main() method

  • How to display output using System.out.println()

  • How to compile and run Java code using the command line

The Code

HelloWorld.java

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

This code might look small, but it packs a punch. Let’s break it down:

  • public class HelloWorld — defines a class named HelloWorld. In Java, every program starts with a class.

  • public static void main(String[] args) — the entry point. Java looks for this method to begin execution.

  • System.out.println("Hello, World!") — prints the message to your screen.

Running the Program
  1. Install Java — download and install the Java Development Kit (JDK) from Oracle’s official site.

  2. Write the code — use any text editor (Notepad, VS Code, etc.) and save the file as HelloWorld.java.

  3. Compile the code — open a terminal in the file’s folder and run javac.

  4. Run the program — once compiled, run java HelloWorld.

Compile

Bash
javac HelloWorld.java

Run

Bash
java HelloWorld

Output

Text
Hello, World!
Why This Matters

This first program teaches you:

  • How Java syntax is structured

  • How to use the command line for compiling and running code

  • How output is displayed in Java

It’s your first step toward building real-world applications — from simple calculators to full-stack systems.

What’s Next?

Now that you’ve written and executed your first Java program, you’re ready to explore:

  • Variables and data types

  • Conditional logic

  • Loops and functions

  • Object-oriented programming