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!
-
31:21
The White House
3 hours agoVice President JD Vance Delivers Remarks at the 2026 National March for Life Rally
21611 -
1:22:12
Steven Crowder
4 hours agoThe 5-YO Minnesota Kid Hoax: Debunking The Left's Sinister Strategy
245K156 -
45:56
The Rubin Report
2 hours agoIs This the Beginning of the Downfall of Nick Fuentes, Andrew Tate & the Toxic Right?
40.9K62 -
LIVE
Framers View
17 hours agoFramersView
26 watching -
LIVE
LFA TV
16 hours agoLIVE & BREAKING NEWS! | FRIDAY 1/23/26
3,054 watching -
1:03:31
BonginoReport
4 hours agoPeople Keep Falling For These Hoaxes | Episode 210 - 01/23/26 VINCE
167K134 -
1:33:33
Benny Johnson
3 hours ago🚨BOMBSHELL: Whistleblower REVEALS Tim Walz Knew of Somali Fraud, Judge Protecting Don Lemon EXPOSED
56.6K98 -
LIVE
The Shannon Joy Show
4 hours ago🔥SJ LIVE Jan 23 - Friday Midday Matinee With SJ! Featuring Documentary “An Inconvenient Study”🔥
28 watching -
NXRStudios
2 hours ago $0.10 earnedAmerica: Nation or Empire?
8.63K -
12:09
Degenerate Jay
4 hours agoRockstar Actually Did Something Amazing With GTA 6
2.18K4