Premium Only Content
Java "Hello World"
Java Tutorial 1: Printing "Hello, World!"
This tutorial covers the very first step in Java programming: printing "Hello, World!" on the screen. This simple program introduces the structure of a Java program and demonstrates how to display text in the console.
Writing the Code:
In your HelloWorld.java file, type the following code:
java
Copy code
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Understanding the Code:
public class HelloWorld: Defines a class named HelloWorld. In Java, every program must have at least one class, and the file name must match the class name.
public static void main(String[] args): This is the main method, the entry point of every Java application. When you run the program, this method is executed.
System.out.println("Hello, World!");: This line prints "Hello, World!" to the console. The System.out.println method outputs text to the screen, followed by a new line.
Compiling and Running the Program:
Compile the code by opening a terminal, navigating to the folder where HelloWorld.java is saved, and running:
bash
Copy code
javac HelloWorld.java
This command compiles the code and creates a file named HelloWorld.class.
Run the program with:
bash
Copy code
java HelloWorld
You should see the output:
Copy code
Hello, World!Writing the Code:
In your HelloWorld.java file, type the following code:
java
Copy code
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Understanding the Code:
public class HelloWorld: Defines a class named HelloWorld. In Java, every program must have at least one class, and the file name must match the class name.
public static void main(String[] args): This is the main method, the entry point of every Java application. When you run the program, this method is executed.
System.out.println("Hello, World!");: This line prints "Hello, World!" to the console. The System.out.println method outputs text to the screen, followed by a new line.
Compiling and Running the Program:
Compile the code by opening a terminal, navigating to the folder where HelloWorld.java is saved, and running:
bash
Copy code
javac HelloWorld.java
This command compiles the code and creates a file named HelloWorld.class.
Run the program with:
bash
Copy code
java HelloWorld
You should see the output:
Copy code
Hello, World!
-
LIVE
The Shannon Joy Show
1 hour agoMarjorie Taylor Greene DUMPS Trump, Defects To ‘America First’ Setting Up NEW Paradigm For 2028 Presidential Election
313 watching -
LIVE
Grant Stinchfield
18 hours agoABC SETUP: Michael McCaul Falls for Martha Raddatz Trap on Live TV!
173 watching -
2:00:33
Nikko Ortiz
2 hours agoWorst Military Events And War Crimes... | Rumble LIVE
15.3K1 -
17:27
We Got Receipts
3 hours agoAntifa Getting Arrested In The Funniest Ways!
19.8K8 -
1:34:14
Caleb Hammer
11 hours agoHe Treats His Wife Like A Dog | Financial Audit
24.6K1 -
1:55:16
Badlands Media
5 hours agoBadlands Daily Nov. 24, 2025
38.9K10 -
2:12:17
Matt Kohrs
13 hours agoStock Market Open, Breaking News & The Week Ahead || Live Trading $1M
31.1K1 -
2:59:14
Wendy Bell Radio
7 hours agoWhy Do Democrats Put America Last?
72.9K97 -
1:36:29
Graham Allen
4 hours agoIs The MAGA Divorce Real Or Did Elon Just Expose It’s FAKE?!
134K605 -
1:13:15
The Big Migâ„¢
4 hours agoTrump, We Must Focus All Our Energy & Might On Election Fraud
6.2K11