Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Industrial programming >> Java

Java Hello World: Your First Program

Java Hello World: Your First Program

Discover how to write, compile, and run a classic “Hello World” program in Java—a cornerstone exercise for new developers.

The phrase Hello, World! represents the simplest executable program that outputs “Hello, World!” to the console. It’s widely used as an introductory exercise because it demonstrates the basic syntax of a language without extraneous complexity.

Below you’ll find a fully working example, followed by an in‑depth explanation of each component.

Tip: Try the code in our online Java compiler to see it run instantly.


Source Code

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

Output

Hello, World!

How the Hello World Program Works

  1. // Your First Program

    Lines that begin with // are comments. They are ignored by the compiler but serve as documentation for developers. Learn more about Java comments.

  2. public class HelloWorld { ... }

    Every Java application starts with a class definition. The class name must match the filename (HelloWorld.java). Here, HelloWorld is the entry point for the program.

  3. public static void main(String[] args) { ... }

    The main method is mandatory; it’s where the Java Virtual Machine begins execution. The signature is fixed: public static void main(String[] args).

  4. System.out.println("Hello, World!");

    This statement prints the string literal "Hello, World!" to the console. The System.out object is a PrintStream that writes to standard output.


Key Takeaways

Below is a minimal template you can use to scaffold future projects:

public class HelloWorld {
    public static void main(String[] args) {
        // Your code goes here
    }
}

Feel free to experiment with the code; you’ll soon understand how class structure, access modifiers, and methods shape a Java program.

Java

  1. C# Hello World – Building Your First C# Application
  2. Your First VHDL Program: A Step‑by‑Step Hello World Tutorial
  3. C++ Hello World Tutorial: Step‑by‑Step Code, Setup & Explanation
  4. C# Hello World: Building Your First Console Application
  5. C Hello World: Your First Program – A Step‑by‑Step Guide
  6. Java Hello World: Step‑by‑Step Guide to Writing Your First Java Program
  7. Constructor Overloading in Java – Explained with Practical Code Examples
  8. Java Program to Determine If a Number Is Prime
  9. Hello World: Building Your First Python Application
  10. Beginner’s Guide to Verilog: Hello World Example