Hello World Program


Steps to Write Your First Java Program:

  1. Open your IDE (IntelliJ IDEA, Eclipse, or VSCode).
  2. Create a New Java Project:
    • If you're using IntelliJ IDEA or Eclipse, select "Create New Project" and choose Java.
    • If you're using VSCode, create a new Java project by selecting Java: Create Java Project from the command palette.
  3. Create a New Java Class:
    • In your new Java project, create a new class file named HelloWorld.java.
  4. Write the Code: In the HelloWorld.java file, write the following Java code:

Code for HelloWorld.java:

    
    // This is a simple Java program that prints "Hello, World!" to the console

    public class HelloWorld {
        public static void main(String[] args) {
            // Print "Hello, World!" to the console
            System.out.println("Hello, World!");
        }
    }
    
    

Explanation of the Code:

public class HelloWorld
This defines the class HelloWorld. In Java, every application must have at least one class with a main method.
public static void main(String[] args)
This is the entry point of the program. The main method is where the program starts execution. The String[] args allows you to pass command-line arguments if needed, though we're not using them here.
System.out.println("Hello, World!");
This line prints the text "Hello, World!" to the console. The println method outputs text followed by a newline.

Step-by-Step Instructions to Run the Program:

  1. Save the File:
    • Ensure that the class name is the same as the filename (HelloWorld.java).
  2. Run the Program:
    • In IntelliJ IDEA or Eclipse: Right-click on the file and select Run.
    • In VSCode: Press F5 or click on the Run button to execute the program.
Expected Output:

Once you run the program, the output in the console will be:

    
        Hello, World!