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!
-
10:23
TheSaltyCracker
17 hours agoMuslims Immediately Threaten New Yorkers After Zohran Win
34.5K441 -
18:40
Actual Justice Warrior
17 hours agoMamdani Pledges To DESTROY New York
21.3K57 -
28:53
iCkEdMeL
16 hours ago $0.03 earnedBREAKING: 9 DEAD After UPS Plane BURSTS Into Fireball at Louisville Airport
28.5K7 -
20:52
Professor Nez
19 hours agoThe TRUTH is Actually WORSE than we Thought...
19.5K22 -
8:59
MattMorseTV
18 hours ago $0.06 earnedTrump’s DIRE WARNING to the Senate GOP.
79.2K84 -
2:13:33
Side Scrollers Podcast
21 hours agoAsmongold SUED for Emotional Distress + Hasan REJECTED+ INSANE Plane Crash + More | Side Scrollers
93.6K27 -
21:39
Nikko Ortiz
4 days agoI Take A North Korean Shooting
84.7K11 -
23:01
GritsGG
19 hours agoWarzone Solo Dubular! Last Night Time Solo???
19.5K2 -
22:47
The Pascal Show
16 hours ago $0.05 earnedTHEY’RE HIDING EVIDENCE?! Candace Owens EXPOSES Foreign Connection In Charlie Kirk Shooting
26.9K27 -
LIVE
Lofi Girl
3 years agolofi hip hop radio 📚 - beats to relax/study to
286 watching