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!
-
53:56
ZeeeMedia
21 hours agoSilicon Valley, Transhumanists & the Book of Revelation ft. Jay Dyer | Daily Pulse Ep 144
15.8K13 -
1:02:02
A Cigar Hustlers Podcast Every Day
1 day agoEpisode 4 Hustler Every Day Target 10/4, No More Pennies and Gronk Is The Man
15K1 -
3:07
GreenMan Studio
1 day agoHOW TO NOT SELL OUT IN 2025 W/Greeman Reports
13.8K6 -
0:43
WildCreatures
2 days ago $5.69 earnedDiver is swallowed up by a passing bait ball at Darwin Island
15.7K4 -
1:54
Damon Imani
3 days agoDamon Left The View SPEECHLESS on Marriage And Government Overreach
17.6K10 -
4:09
Memology 101
16 hours ago $3.65 earned"Journalist" REPEATEDLY tries and FAILS to bait John Fetterman into calling Trump an "AUTOCRAT"
17.4K26 -
58:02
Dialogue works
2 days ago $9.11 earnedMatthew Hoh: Ukraine’s Army Is COLLAPSING Everywhere!
40.2K20 -
17:24
Nate The Lawyer
2 days ago $3.87 earnedBREAKING: NEW Scientific Evidence Shows Men Are Better in Sports Than Women
21K18 -
29:43
Code Blue Cam
2 days agoHow Missing Dipping Sauce Turned into a Felony Arrest
20.9K17 -
16:19
BlaireWhite
2 days agoWoman Confronts "Trans Woman" In Locker Room: Gold's Gym Scandal
19.3K16