Hello World Program
All Java Topics
Last updated: May 21, 2026
Author: ManaCoding Team
The Hello World program is the first and most basic program written by beginners while learning Java. Java programs are written inside classes and executed using the Java Virtual Machine (JVM). This program prints "Hello World!" on the screen and helps beginners understand Java structure, syntax, main method, and execution flow.
Syntax
public class Main {
public static void main(String[] args) {
// code here
}
}
Example Program
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Structure of Hello World Program
- 1 public class defines the class.
- 2 main() is the entry point of Java execution.
- 3 System.out.println prints output to console.
- 4 Every statement ends with a semicolon.
Step 1: Write Code
- 1 Open any IDE or text editor.
- 2 Create a file named Main.java.
- 3 Write the Hello World program.
- 4 Save the file properly.
Step 2: Compile Code
- 1 Open terminal or command prompt.
- 2 Navigate to file location.
- 3 Run javac Main.java command.
- 4 This generates bytecode (.class file).
Step 3: Run Program
- 1 Run using java Main command.
- 2 JVM executes the bytecode.
- 3 Output is displayed on console.
- 4 Program runs successfully.
Important Rules
- 1 Java is case-sensitive.
- 2 Class name must match filename.
- 3 main() method is required.
- 4 Curly braces define code blocks.
Why Hello World is Important
- 1 Introduces Java programming basics.
- 2 Explains compilation and execution flow.
- 3 Builds confidence for beginners.
- 4 Foundation for all Java learning.
Quick Summary
- Java program execution starts from main() method.
- Code must be written inside a class.
- javac compiles Java code into bytecode.
- java runs the program using JVM.
FAQs
What is the entry point of a Java program?
The entry point of a Java program is the main method: public static void main(String[] args).
Why is the main method important?
The main method is important because it starts the execution of any Java program.
What is the use of javac command?
The javac command is used to compile Java source code into bytecode (.class files).
What happens when we run a Java program?
When a Java program runs, the JVM loads the class, starts the main method, and executes the bytecode step by step.
Interview Questions
Q1.
What is the entry point of a Java program?
Answer:
The entry point of a Java program is the main method: public static void main(String[] args).
Q2.
Why is the main method important?
Answer:
The main method is important because it starts the execution of any Java program.
Q3.
What is the use of javac command?
Answer:
The javac command is used to compile Java source code into bytecode (.class files).
Q4.
What happens when we run a Java program?
Answer:
When a Java program runs, the JVM loads the class, starts the main method, and executes the bytecode step by step.
Quiz
Which method is the entry point of a Java program?