Java Hello World Program
// Java program to print "Hello, World!"
public class HelloWorld {
/**
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello World");
}
}
Let’s break this “Java Hello World program” line by line to print Hello World.
Step 1: The first step in the Java hello world program is to create a Class.
In Java, the class name should always start with a capital letter, and the name of the Java file should be the same as the class name.
public class HelloWorld
In the above Code, Helloworld is the class name, and public is an access modifier used to define the class’s access level.
Note: Learn about Access modifiers in Java
Step 2: Main Method in Java
public static void main(String[] args)
public static void main(String[] args) is a method. A method is a block of code that can be executed in a program by calling its name.
public – It is an Access modifier that determines what outside classes can use/call the method.
static means that the method is class-related and not instance-related. For now, you can use it to mean that you can call static methods of a class without creating them with the “new” keyword first, like with the main(String[] args) method.
void is the method’s return type; as expected, void means the method returns nothing.
main is the name of the method, and it is also a unique name, as the Java Virtual Machine uses the primary method as the start of a program.
String[] args is an array of strings used as arguments for the primary method.
Step 3: Print Statement
System.out.println("Hello World");
System.out.println supports various objects and data types. The println method invokes the toString() method of any objects passed as an argument to display details of instances of Java classes.
Java is case-sensitive, so the System must lead with an upper-case letter S.
The println method must be in “double quotes,” not ‘single quotes.’
Performance of the Code.
Time Complexity
- The program runs a single statement, so the time complexity is O(1) (constant time).
Space Complexity
- The program does not use additional memory, so the space complexity is O(1).
Memory Usage:
Very low
Execution Speed:
Fast (constant time execution)
Since it’s a simple I/O operation, its execution is nearly instantaneous.
Code Execution Guide
Step 1: Install Java
If you don’t have Java installed on your computer or laptop, you can download it from Oracle’s official website and install it.
Step 2: Write the Code
Open a text editor (e.g., Notepad, VS Code, IntelliJ, Eclipse).
Please copy and paste the Java program provided above.
Save the file as HelloWorld.java.
Step 3: Compile the Code
Open a terminal or command prompt.
Navigate to the folder where the HelloWorld.java file is saved.
Compile the Java file using the command:
javac HelloWorld.java
This generates a HelloWorld.class file (bytecode).
Step 4: Run the Program
Execute the program using:
java HelloWorld
Expected Output:
Hello, World!

Pic: Executing the Java Hello World program in Eclipse.