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
HomieQuest
4 hours agoLive Streaming!
93 watching -
26:47
Degenerate Jay
5 hours ago $2.51 earnedPlaying Fallout 3 For The First Time Ever - Here's My Thoughts
12.6K4 -
LIVE
ItsMossy
2 hours ago🍃DEVS ARE CRACKING DOWN🍃maybe a video?🍃shrooms aren't real dude🍃ARC RAIDERS RAIDERING SO HARD🍃
38 watching -
59:25
Jeff Ahern
4 hours ago $9.74 earnedThe Saturday Show with Jeff Ahern
75.7K17 -
29:53
Afshin Rattansi's Going Underground
2 days agoBRICS MUST Replace the US’ Authoritarian International Financial System! (Prof. Steve Keen)
10.3K17 -
31:27
Robbi On The Record
3 days ago $11.40 earnedWhat the Bible say about Astrology.. The Conversation Culture Has Been Avoiding | ft. JT Follows JC
44.9K12 -
17:38
Professor Nez
4 hours ago🚨THIS IS A NATIONAL SECURITY EMERGENCY: Stephen Miller with CHILLING WARNING for AMERICA
44.2K122 -
LIVE
tminnzy
3 hours agoBLACK OPS 7 MULTIPLAYER ROAD TO MASTER PRESTIGE
81 watching -
47:10
The Rubin Report
9 hours agoWhat Really Happened on ‘The View’ & ‘Curb Your Enthusiasm’ | Cheryl Hines
191K50 -
3:08:37
LumpyPotatoX2
7 hours agoWhere Winds Meet: New Level Cap + Rumble Wallet - #RumbleGaming
43.2K1