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!
-
54:43
Glenn Greenwald
4 hours agoGlenn Reacts to Netanyahu's UN Speech; PLUS: Q&A on Trump's Russia/Ukraine Policy, the Tom Homan Investigation, and More | SYSTEM UPDATE #522
34.7K37 -
LIVE
MissesMaam
1 hour ago*Spicy* Friend Friday with Mally_Mouse and Friends!! 💚✨
39 watching -
43:54
Donald Trump Jr.
3 hours agoJames and the Giant Breach, Plus Explosive J6 Revelations | TRIGGERED Ep.277
132K158 -
LIVE
MadHouse_
3 hours agoFRIEND FRIDAY! - Garys Mod ? im pretty sure im gonna lose at this game
77 watching -
2:26:51
blackfox87
2 hours agoBorderlands Grind Continues | PREMIUM CREATOR | #DisabledVeteran
8.04K1 -
LIVE
Mally_Mouse
5 days agoFriend Friday!! 🎉 - Let's Play! - Gary's Mod!
39 watching -
LIVE
ZWOGs
9 hours ago🔴LIVE IN 1440p! - Resident Evil 3 First Playthrough, GMod w/ Mally_Mouse & Friends - Come Hang Out!
45 watching -
1:00:55
BonginoReport
7 hours agoJames Comey Indicted! - Nightly Scroll w/ Hayley Caronia (Ep.143)
138K103 -
1:20:26
Kim Iversen
6 hours agoThis Intel Analyst Has Accurately Predicted Putin's Every Move... Is War With NATO Next?
124K53 -
LIVE
GritsGG
13 hours agoQuad Win Streaks!🫡 Most Wins in WORLD! 3600+
58 watching