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
XDDX_HiTower
1 hour agoBATTLEFIELD 6 REDSEC! [RGMT CONTENT Mgr.
39 watching -
LIVE
Joker Effect
42 minutes agoSTREAMER NEWS: What actually occurred at Dreamhack ATL. Frontier Airlines. Kick Staff Trolled me?!
470 watching -
LIVE
VapinGamers
52 minutes agoBF6 RedSpec - Nothing but Wins and New Rum Bot Testing - !rumbot !music
15 watching -
1:01:50
MattMorseTV
3 hours ago $0.01 earned🔴Now he’s literally BEGGING for a DEAL. 🔴
23K37 -
LIVE
Cewpins
38 minutes agoWEED PORN *unboxing*🔥World Wide !weed Review🍃420💨!MJ
42 watching -
1:00:02
BonginoReport
4 hours agoBlue Wave Crashes Over The Nation On Election Night - Nightly Scroll w/ Hayley Caronia (Ep.171)
117K63 -
5:49
Buddy Brown
8 hours agoTake a Look at the Outdoor MOSQUES in TIMES SQUARE after MAMDANI Win | Buddy Brown
22K19 -
18:15
ArynneWexler
5 hours agoThe Fall of New York - How Zohran Mamdani Won | NN8
16.3K11 -
1:30:53
Kim Iversen
5 hours agoAmerica Under INVASION - Sharia Law Wins In New York City?
110K291 -
50:45
Redacted News
4 hours agoNick Fuentes & Tucker Carlson DESTROY Ben Shapiro, Cuomo collapses to a socialist | Redacted
61.3K143