Java is a widely-used programming language known for its portability, performance, and extensive libraries. It is an object-oriented language that allows developers to create robust applications. The “Hello, World!” program is traditionally used as a beginner’s first program to demonstrate the basic syntax of a programming language and how to output text to the console.
Objective
The objective of this program is to write a simple Java application that prints “Hello, World!” to the console. This will help in understanding the structure of a Java program and how to execute it.
Java Code
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Explanation of the Program Structure
- public class HelloWorld: This line declares a public class named HelloWorld. In Java, every application must have at least one class.
- public static void main(String[] args): This is the main method, the entry point of any Java application. The Java Virtual Machine (JVM) looks for this method when running the program.
- System.out.println(“Hello, World!”); This line prints the string “Hello, World!” to the console. The
System.out
is a built-in output stream, andprintln
is a method that outputs a line of text.
How to Run the Program
- Install Java Development Kit (JDK): Make sure you have JDK installed on your computer. You can download it from the official Oracle website.
- Create a Java File: Open a text editor or an Integrated Development Environment (IDE) and create a new file named
HelloWorld.java
. - Write the Code: Copy and paste the provided Java code into the file and save it.
- Open Command Line: Open your terminal or command prompt.
- Navigate to the File Location: Use the
cd
command to change the directory to where you saved theHelloWorld.java
file. - Compile the Program: Run the command
javac HelloWorld.java
to compile the program. This will create a file namedHelloWorld.class
. - Run the Program: Finally, execute the command
java HelloWorld
. You should see the outputHello, World!
in the console.