Lesson 2 of 612 minModule progress 0%

Module 1: Start Coding in Java

Run and Change Your First Java Program

Open the built-in compiler, run a working program, personalize it, and use the output to confirm exactly what your change did.

Author

Java Learner Editorial Team

Reviewer

Technical review by Java Learner

Last reviewed

2026-07-13

Java version

Java 25 LTS

Learning goals

  • Open a lesson example in the Java compiler
  • Run, edit, and rerun a complete Java program
  • Connect each `println` statement to one line of output

Before you start

  • You only need a browser; Java does not need to be installed yet

Step 1: Open the example. Use the compiler button beside the code. The complete program is placed in the editor for you, so there is nothing to configure.

Step 2: Run it once before editing. Select Run code and find the program output. It should match the expected output shown below the example. This confirms that you are starting from working code.

Step 3: Make one deliberate change. Replace the text inside the quotation marks, predict what the new output will say, and run the program again. If the output changes as expected, you have already completed the basic programming loop.

Keep the surrounding structure for now. Your message belongs inside System.out.println("...");. Leave the Main class, braces, and main line in place until the next lesson explains them.

Runnable examples

Run this program exactly as written

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, Java!");
        System.out.println("I ran my first program.");
    }
}

Expected output

Hello, Java!
I ran my first program.

Personalize the result

public class Main {
    public static void main(String[] args) {
        System.out.println("My name is Samira.");
        System.out.println("I want to build useful Java programs.");
        System.out.println("Day 1: complete.");
    }
}

Expected output

My name is Samira.
I want to build useful Java programs.
Day 1: complete.

Common mistakes

Changing code before the first successful run

Run the original example first. Then you will know whether a later error came from your change.

Removing a quote, parenthesis, or semicolon

Edit only the words between the double quotes at first. Keep `");` at the end of the line.

Mini exercise

Create a three-line introduction: your name, how many minutes you plan to practice today, and the program you eventually want to build. Predict the output before selecting **Run code**.

Summary

  • Run working code once before changing it.
  • Text inside double quotes appears in the output.
  • One `println` statement produces one output line.

Next step

You can now control the program output. Next, learn what the class, `main` method, braces, and print statement each do.

Sources used

Advertisement

Lesson check

After opening a working example, what should you do before changing it?

Next lesson →