🟢 Foundation  ·  Lesson 04

Hello World Program in Java

Hello World Program in Java

Your First Java Program

Every Java program lives inside a class, and execution starts from the main method. Here is the classic first program.

The Program

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

Line-by-Line Explanation

  • public class HelloWorld — defines a class; the file must be named HelloWorld.java.
  • public static void main(String[] args) — the entry point; the JVM starts here.
  • System.out.println(...) — prints the text and moves to a new line.
  • Every statement ends with a semicolon ;.

Compile and Run

javac HelloWorld.java   # compiles to HelloWorld.class
java HelloWorld          # runs it

Summary

  • Java code lives inside a class; the file name must match the public class.
  • main is the entry point; System.out.println prints output.
  • Compile with javac, run with java.

आपका पहला Java Program

हर Java program एक class के अंदर रहता है, और execution main method से शुरू होता है। यह रहा classic पहला program।

Program

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

Line-by-Line Explanation

  • public class HelloWorld — class define करता है; file का नाम HelloWorld.java होना चाहिए।
  • public static void main(String[] args) — entry point; JVM यहीं से शुरू होता है।
  • System.out.println(...) — text print करके नई line पर जाता है।
  • हर statement semicolon ; से खत्म होती है।

Compile और Run

javac HelloWorld.java   # HelloWorld.class में compile
java HelloWorld          # चलाएं

सारांश

  • Java code class के अंदर; file नाम public class से मेल खाए।
  • main entry point है; System.out.println output print करता है।
  • javac से compile, java से run।
← Back to Java Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n