Lesson 1 of 425 minModule progress 0%

Module 1: Start Coding in Java

How Java Turns Source into a Running Program

Build an accurate beginner mental model of Java, connect source code to visible output, and learn a repeatable way to practise without trying to memorize everything at once.

Author

Java Learner

Java version

Java 25 LTS

Learning goals

  • Distinguish the Java language, JDK, compiler, and JVM
  • Describe the path from a `.java` source file to a running program
  • Read a small program and predict its visible output
  • Use a predict, run, change, and check practice loop

Before you start

  • No programming experience is required
  • No local Java installation is required because the first examples run in the browser

Java is a programming language and a platform. You write Java instructions in source files whose names normally end in .java. Those files are readable text. Before the computer can run them, a Java compiler translates the source into another form called bytecode.

The JDK gives you the development tools. JDK means Java Development Kit. It includes the javac compiler used to compile source code, the java command used to start programs, and other tools you will meet later. Installing a full JDK is different from installing only an editor.

The JVM runs Java bytecode. JVM means Java Virtual Machine. A compatible JVM reads the compiled .class files and carries out their instructions. Keep this practical flow in mind:

1. Write source in Main.java 2. Compile it with javac 3. Receive compiled bytecode in Main.class 4. Start the class with java 5. Observe the program output

Java programs produce observable behavior. A program may read input, calculate values, make decisions, store information, or communicate with another service. The first examples use fixed text because printed output makes the relationship between code and behavior easy to see.

Do not try to memorize every keyword yet. The first program contains unfamiliar words such as public, static, void, and String. You only need to recognize the complete starting structure for now. Later lessons explain the parts when you have enough context to use them.

Treat predictions as part of programming. Before pressing Run, pause and state what you expect to happen. A correct prediction confirms your understanding. A wrong prediction is useful because it identifies exactly what needs another look.

Change one thing at a time. Begin with code that already works. Run it once, change one message, predict the new result, and run it again. If you change five things together, you will not know which change caused an error or an unexpected result.

Compiler messages are feedback, not failure. Everyone writes code that does not compile on the first attempt. The useful habit is to read the first message, inspect the named line and the line above it, make one correction, and try again.

The course builds in small steps. You will move from output to variables, input, calculations, decisions, loops, methods, objects, collections, files, testing, and projects. Each new lesson should depend only on ideas that have already been introduced.

Runnable examples

A complete program with visible behavior

public class Main {
    public static void main(String[] args) {
        System.out.println("Java source can become a running program.");
        System.out.println("The result is visible in the output.");
    }
}

Expected output

Java source can become a running program.
The result is visible in the output.

One small change creates one clear result

public class Main {
    public static void main(String[] args) {
        System.out.println("Current step: run the example.");
        System.out.println("Next step: change this message.");
    }
}

Expected output

Current step: run the example.
Next step: change this message.

Practice the lesson

Predict first, make a change, repair a real problem, then write a small program independently.

Predict the result

Read the program from top to bottom. Without running it, write the exact three output lines in order.

public class Main {
    public static void main(String[] args) {
        System.out.println("1. Read");
        System.out.println("2. Predict");
        System.out.println("3. Run");
    }
}
Show answer
1. Read
2. Predict
3. Run

The statements inside `main` execute from top to bottom. Each `println` call prints its text and then moves to a new line.

Change the program

Run the starter once. Then change only the second message so it describes the next Java topic you want to learn. Predict the two lines before running again.

public class Main {
    public static void main(String[] args) {
        System.out.println("Completed: first Java run");
        System.out.println("Next: choose a topic");
    }
}

Success criteria

  • The original program runs successfully before you edit it.
  • Only the text inside the second pair of quotation marks changes.
  • Your prediction matches the final two output lines.
  • The class and `main` method remain unchanged.

Close the string literal

The second message begins with a double quotation mark but never closes. Find the missing character before opening the solution.

public class Main {
    public static void main(String[] args) {
        System.out.println("The first line is valid.");
        System.out.println("The second line is unfinished.);
    }
}

What happens: The compiler reports an unclosed string literal because it reaches the end of the line without finding the closing double quotation mark.

Show the correction
public class Main {
    public static void main(String[] args) {
        System.out.println("The first line is valid.");
        System.out.println("The second line is finished.");
    }
}

Independent challenge

Create a three-line course checkpoint. Make a prediction, run the program, and compare the actual output with your prediction.

  • The first line must identify the current module.
  • The second line must describe one action you completed.
  • The third line must describe the next action you will take.
  • Use three separate `System.out.println` statements.
  • Do not change the `Main` class or `main` method declaration.
Show one complete solution
public class Main {
    public static void main(String[] args) {
        System.out.println("Module: Start Coding in Java");
        System.out.println("Completed: ran a Java program");
        System.out.println("Next: understand the program structure");
    }
}

Expected output

Module: Start Coding in Java
Completed: ran a Java program
Next: understand the program structure

Common mistakes

Thinking the `.java` source file runs directly

Use the practical model: source is compiled into bytecode, and the JVM runs the compiled class.

Trying to explain every word in the first program immediately

Recognize the complete working structure first. Learn each keyword when the course introduces a reason to use it.

Running code without making a prediction

Write or say the expected output before running. Comparing expectation with reality strengthens the mental model.

Changing many lines before obtaining a working baseline

Run the unchanged example first, then make one deliberate change and run it again.

Summary

  • Java source code is written in `.java` files.
  • The JDK provides the compiler and the tools needed to develop Java programs.
  • The compiler translates source into bytecode stored in `.class` files.
  • A JVM runs the compiled bytecode.
  • Predict, run, change one thing, and check the result.

Keep the reference close

Next step

Next, examine the minimum structure of a Java program and learn exactly where executable statements belong.

Sources used

Advertisement

Lesson check

Which sequence best describes how a basic local Java program runs?

Next lesson →