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!
-
DVR
Stephen Gardner
1 hour ago🔥Democrat Jasmine Crocket REVEALS plan to RUIN TRUMP!
1.17K2 -
1:24:04
Roseanne Barr
3 hours agoTales From The Other Side w/ Darius J. Wright| The Roseanne Barr Podcast #101
25.5K10 -
2:15:45
The Quartering
3 hours agoNancy Pelosi Exposed, DOOM Bombs, Sydney Sweeny Bathwater For Sale & Bongino ABSURD Epstein Update
166K33 -
LIVE
Dr Disrespect
6 hours ago🔴LIVE - DR DISRESPECT - WARZONE - NEW SEASON 4!
2,231 watching -
LIVE
sophiesnazz
2 hours ago $0.09 earnedSEASON 4 UPDATE !socials
46 watching -
20:41
Benjamin Cowen
1 hour ago $2.30 earnedBitcoin Las Vegas with Aaron from Altcoin Daily
21.3K2 -
58:01
BEK TV
18 hours agoThe Unsexy Truth Behind 7-Figure Businesses - Clay Clark’s Blueprint to Nail It & Scale It
6.16K -
1:19:37
The Heidi St. John Podcast
1 day agoIVF, Ethics, and the Rights of the Child, with Katy Faust
6.74K1 -
LIVE
StoneMountain64
4 hours agoNew Downtown is HERE. MAX Battlepass Unlocked | Warzone Season 4
214 watching -
51:30
Badlands Media
2 hours agoRugpull Radio Special Episode - GMoney Live at Bitcoin Conference
28.5K3