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
GamersErr0r
3 hours ago $0.68 earnedMooning My Community
323 watching -
2:22:59
Banks Atkin Live
5 hours agoChilling playing Games & Vibin
47.6K1 -
LIVE
Dragoon_B
7 hours agoNothing crazy - just Counter Strike + Valorant
82 watching -
18:03
Stephen Gardner
6 hours ago🔥YES!! Trump GETS HUGE win in 4th district court!!
65.1K376 -
4:40:54
G3T
5 hours ago🔴GET | not saying it
17K -
15:35
DeVory Darkins
11 hours ago $3.92 earnedGavin Newsom drops CRUSHING BLOW on Democrats
22K65 -
LIVE
Etheraeon
8 hours agoPUBG: Battlegrounds | Total Bot Domination
127 watching -
3:18:33
House of Jacobs
4 hours agoElden Drinks - Drunk Souls Series
14.1K1 -
3:12:13
BubbaSZN
7 hours ago🔴 LIVE - SPIDER-MAN 2 - PART 3
14.9K1 -
1:43:06
Roseanne Barr
2 days ago $48.02 earnedBit*h Better Have My Money W/ Michael Malice | The Roseanne Barr Podcast #92
131K150