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
Side Scrollers Podcast
2 hours agoSide Scrollers VTuber TAKE OVER with Kirsche, Rev Says Desu & DarlingStrawb | Side Scrollers
673 watching -
The White House
2 hours agoPresident Trump Makes an Announcement, Nov. 6, 2025
10K7 -
1:02:55
VINCE
3 hours agoThey're Coming For You Next | Episode 163 - VINCE 11/06/25
152K256 -
1:42:05
Graham Allen
4 hours agoTrump And Vance Show The Path For Winning!!! WE MUST FIGHT! + Erika Kirk Reveals All!
117K40 -
LIVE
LadyDesireeMusic
2 hours ago $0.02 earnedLive Piano & Convo - Rumble Rants and Sub Request
155 watching -
1:10:27
Chad Prather
19 hours agoThe Secret To Pleasing The Lord Over Man!
82.5K53 -
LIVE
LFA TV
14 hours agoLIVE & BREAKING NEWS! | THURSDAY 11/6/25
4,059 watching -
52:16
American Thought Leaders
21 hours agoIs There a Link Between Mass Shootings and SSRIs?
63.3K59 -
17:12
World2Briggs
21 hours ago $0.09 earnedTop 10 Towns You Can Retire or Live on $1900 a month in the Midwest #1
51.5K26 -
17:25
BlackDiamondGunsandGear
1 day agoCustom Building the Cheapest MP5
57.4K2