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!
-
14:47
World2Briggs
17 hours ago $1.45 earnedShocking but True: The 10 States Leading in Murder
25.2K16 -
8:30
Faith Frontline
14 hours agoPriest Reveals TERRIFYING Emily Rose Exorcism Details Nobody Talks About
23.2K11 -
10:54
NAG Daily
15 hours agoMike on a Bike #5 - Charlie
21.6K11 -
11:07
Ken LaCorte: Elephants in Rooms
16 hours ago $0.97 earnedWhy Do Black Athletes Dominate?
20.6K21 -
2:01:45
BEK TV
1 day agoTrent Loos in the Morning - 9/24/2025
20.8K1 -
LIVE
The Bubba Army
23 hours agoCrying Kimmel Returns | Bubba the Love Sponge® Show | 9/24/2025
1,411 watching -
46:08
ZeeeMedia
18 hours agoAutism: Vaccines vs. Tylenol, Parents Suing Open AI Speak Out | Daily Pulse Ep 113
34.4K34 -
22:54
DeVory Darkins
1 day ago $16.80 earnedABC suffers fatal mistake brings Kimmel back on air as Trump makes shocking announcement
47K167 -
19:04
putther
2 days ago $1.20 earnedTrolling a Level 7981 With My CHERNOBOG on GTA Online!
38.9K6 -
26:17
Coin Stories with Natalie Brunell
22 hours agoInside Strive’s Bold Bitcoin Acquisition of Semler Scientific
43.7K2