🟢 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 namedHelloWorld.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.
mainis the entry point;System.out.printlnprints output.- Compile with
javac, run withjava.
आपका पहला 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 से मेल खाए।
mainentry point है;System.out.printlnoutput print करता है।javacसे compile,javaसे run।