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!
-
55:07
LFA TV
1 day agoDefending the Indefensible | TRUMPET DAILY 2.25.25 7PM
65.9K21 -
6:09:26
Barry Cunningham
22 hours agoTRUMP DAILY BRIEFING - WATCH WHITE HOUSE PRESS CONFERENCE LIVE! EXECUTIVE ORDERS AND MORE!
202K77 -
1:46:37
Game On!
17 hours ago $7.46 earnedPUMP THE BRAKES! Checking Today's Sports Betting Lines!
109K4 -
1:27:21
Redacted News
16 hours agoBREAKING! SOMETHING BIG IS HAPPENING AT THE CIA AND FBI RIGHT NOW, AS KASH PATEL CLEANS HOUSE
251K330 -
1:08:28
In The Litter Box w/ Jewels & Catturd
1 day agoCrenshaw Threatens Tucker | In the Litter Box w/ Jewels & Catturd – Ep. 749 – 2/25/2025
149K64 -
44:57
Standpoint with Gabe Groisman
1 day agoWill Byron Donalds Run for Florida Governor? With Congressman Byron Donalds
79.8K11 -
1:06:25
Savanah Hernandez
16 hours agoEXPOSED: FBI destroys evidence as NSA’s LGBTQ sex chats get leaked?!
98.9K41 -
1:59:58
Revenge of the Cis
18 hours agoEpisode 1452: Hindsight
82.4K13 -
1:20:35
Awaken With JP
20 hours agoCrenshaw Threatens to Kill Tucker and Other Wild Happenings - LIES Ep 80
145K95 -
1:32:19
Russell Brand
18 hours agoBREAK BREAD EP. 15 - LECRAE
154K11