Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Industrial programming >> Java

Java Hello World: Step‑by‑Step Guide to Writing Your First Java Program

Java Hello World: Step‑by‑Step Guide to Writing Your First Java Program

Ready to dive into Java? This tutorial walks you through every step of creating, compiling, and running your first Java program, from installing the Java Development Kit (JDK) to executing a simple Hello World application.

What You’ll Need

  1. Java SE Development Kit (JDK) – The JDK provides the compiler, runtime, and essential tools. Download and install the JDK here (refer to our previous tutorial for detailed instructions).
  2. A Text Editor – For this example we’ll use Windows Notepad, a lightweight editor that comes pre‑installed. You can also choose Notepad++ or an online compiler like Repl.it if you prefer a browser‑based workflow.

Watch the Introduction Video

For a visual walkthrough, check out our Java Hello World video below. If the video doesn’t load, click here to view an alternative version.

Step‑by‑Step: Compile and Run Your First Program

Follow these steps to write, compile, and execute a simple Java program that prints Hello World to the console.

  1. Open Notepad – Start Menu > Accessories > Notepad.

    Java Hello World: Step‑by‑Step Guide to Writing Your First Java Program

  2. Write the Source Code – Create a file named FirstProgram.java with the following content:
    class A {
        public static void main(String[] args) {
            System.out.println("Hello World");
        }
    }

    Java Hello World: Step‑by‑Step Guide to Writing Your First Java Program

  3. Save the File – Save as FirstProgram.java in your working directory (e.g., C:\workspace) and choose "All Files" in the file type dropdown.

    Java Hello World: Step‑by‑Step Guide to Writing Your First Java Program

  4. Open Command Prompt – Navigate to C:\workspace.

    Compile the program with:

    javac FirstProgram.java

    Java Hello World: Step‑by‑Step Guide to Writing Your First Java Program

  5. Check the Output – After compilation, an A.class file appears in the folder.

    Java Hello World: Step‑by‑Step Guide to Writing Your First Java Program

  6. Run the Program – Execute with:
    java A

    The console should display:

    Hello World

    Java Hello World: Step‑by‑Step Guide to Writing Your First Java Program

  7. Key Reminder – Java is case‑sensitive. FirstProgram and firstprogram are distinct identifiers.
  8. Next Steps – Once comfortable, try an Integrated Development Environment (IDE) like Eclipse or IntelliJ IDEA. IDEs streamline compiling and running but stick to a simple editor for foundational learning.

Congratulations! You’ve just written, compiled, and run your first Java program. From here, explore more complex constructs like variables, loops, and object‑oriented concepts to deepen your Java expertise.

Java

  1. C# Hello World – Building Your First C# Application
  2. Java Hello World: Your First Program
  3. Your First VHDL Program: A Step‑by‑Step Hello World Tutorial
  4. C# Hello World: Building Your First Console Application
  5. C Hello World: Your First Program – A Step‑by‑Step Guide
  6. Java String length() Method: How to Get a String’s Size (Example)
  7. Mastering Java's split() Method: A Practical Guide with Code Examples
  8. Reading Files in Java with BufferedReader – A Practical Guide with Examples
  9. Insertion Sort Algorithm in Java: A Clear Example & Step‑by‑Step Guide
  10. Hello World: Building Your First Python Application