JAVA Hello World Program Step by steps

JAVA Hello World Program Step by steps. Hello! I’d be happy to guide you through creating a simple Java program step by step. Let’s create a program that prints “Hello, World!” to the console.

Step 1: Prepare Your Development Environment

Ensure that you have the Java Development Kit (JDK) properly installed on your computer.. You can download it from Oracle’s website or use OpenJDK.

Step 2: Write the Java Code

Open a text editor or an Integrated Development Environment (IDE) like IntelliJ IDEA, Eclipse, or Visual Studio Code.

Create a new file named HelloWorld.java. Java files must have the same name as the public class they contain.

Step 3: Write the Java Code

Inside HelloWorld.java, write the following Java code:

//Simple Java Program HelloWorld..
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Step 4: Save the File

Save HelloWorld.java.

Step 5: Compile the Java Program

Open your command prompt or terminal and navigate to the directory where HelloWorld.java is saved.

Compile the program by typing:

javac HelloWorld.java

This will compile HelloWorld.java into bytecode, producing a HelloWorld.class file.

Step 6: Run the Java Program

After successfully compiling, run the program by typing:

java HelloWorld

Step 7: Output

Output in your terminal:

Hello, World!

Explanation

  • final keyword is added, indicating that the class cannot be subclassed.
  • The class is still declared as public, allowing it to be accessed from other classes.

Adding final ensures that the class HelloWorld cannot have any subclasses, making it effectively a terminal class in terms of inheritance.

  • Main Method: public static void main(String[] args) is the entry point of any Java program. It’s where the program starts executing.
  • Printing to Console: System.out.println("Hello, World!"); prints theĀ  output “Hello, World!” followed by a new-line to the console.

Additional Tips

  • Make sure your JDK is properly installed and configured.
  • Always use javac to compile and java to run Java programs.
  • Understand the basic syntax rules of Java, such as using semicolons at the end of statements, curly braces for defining blocks of code, etc.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *