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 Dana Show with Dana Loesch
2 hours agoTRUMP PLANS TO TAKE OVER GAZA | The Dana Show LIVE On Rumble!
774 watching -
59:36
The Dan Bongino Show
5 hours agoTrump Shocks The World With Major Announcement (Ep. 2416) - 02/05/2025
725K1.34K -
1:19:04
The Rubin Report
4 hours agoTrump & Netanyahu Shock with Truly Unexpected Plan for Gaza
83.6K97 -
1:59:23
Steven Crowder
6 hours ago🔴 Trump's Hitlist Grows: USAID, Dept. of Education, CIA, and... Gaza?
444K372 -
57:49
Grant Stinchfield
3 hours ago $3.43 earnedThe FBI Withholds 5000 Names of Agents & Employees Who Hunted Down J6'ers
18.9K8 -
2:02:40
LFA TV
18 hours agoMA-GAZA STRIP! | LIVE FROM AMERICA 2.5.25 11am
66.3K16 -
2:14:55
Matt Kohrs
12 hours agoBreaking Market News, Earnings Review & Live Trading $1M || The MK Show
88.9K1 -
1:27:18
Caleb Hammer
4 hours agoRadical Femcel Is Literal Garbage | Financial Audit
31.4K1 -
38:57
Rethinking the Dollar
4 hours agoEvery Signature Counts: How Trump's Policies Threaten the Dollar's Stability
49.4K5 -
15:36
Dr David Jockers
4 hours ago $1.50 earnedWhat's the Dark Side of Eggs That No One Talks About?
30.2K4