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!
-
5:06:15
AirCondaTv Gaming
22 hours ago $39.02 earnedOnce Human - New Year. New Meta. Happy New Year!
149K15 -
1:00:37
Bright Insight
10 days agoOlmec Heads are Evidence of Lost Ancient Advanced Civilization
144K230 -
13:43
Cooking with Gruel
2 days agoCreamy Saffron Risotto
126K24 -
18:38
DeVory Darkins
1 day ago $44.20 earnedTrump Makes HUGE Announcement that may spark GOP Battle
150K90 -
2:13:05
The Nerd Realm
21 hours ago $13.09 earnedNew Years Eve! Fortnite Hunters w/ YOU! Creator Code: NERDREALM
105K6 -
11:04:44
FusedAegisTV
1 day agoNYE Eve! - 2025 Incoming 🎉 - 12hr Variety Stream!
158K7 -
1:18:52
Awaken With JP
1 day agoSomehow The World DIDN’T End This Year! - LIES Ep 72
190K169 -
1:19:34
Michael Franzese
22 hours agoWhat 2024 Taught Us About the Future?
148K37 -
1:48:09
The Quartering
22 hours agoBird Flu PANIC, Sam Hyde DESTROYS Elon Musk & Patrick Bet David & Woke Witcher?
152K112 -
4:47
SLS - Street League Skateboarding
3 days agoLiz Akama’s 2nd Place Finish at SLS Tokyo 2024 | Best Tricks
70.4K6