Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Your first Java program

โญ beginnerโณ 12 min read๐Ÿ“ Lesson 1 of 256

The class, the main method, println vs print, and what compiling means.

Every Java program starts the same way: a class, and inside it a main method โ€” the entry point the JVM calls first.

public class Solution {
    public static void main(String[] args) {
        System.out.println("Hello, AP CSA!");
    }
}

Read it piece by piece:

  • public class Solution โ€” Java code lives in classes; the file name must match the class name (Solution.java).
  • public static void main(String[] args) โ€” the exact signature Java looks for. Change any word and the program will not start.
  • System.out.println(...) โ€” prints a line, then moves to the next line. System.out.print(...) prints without moving to a new line.
  • Every statement ends with a semicolon ;.

Compile and run:

javac Solution.java    # compile to bytecode
java Solution          # run it

Errors happen in two places. A compile-time error (missing ;, unknown word) stops javac before anything runs. A runtime error (like dividing by zero) appears while the program runs. Fixing compiler errors is a skill you will practice from day one.