What is a program? Your first Java file

Programs, classes, and main. Print your first line.

1. What is this?

A program is instructions the computer executes. In Java, code lives inside a class — a named container for behaviour. Every runnable program needs a main method: the entry point where execution starts. System.out.println(...) prints a line to the output. A String (capital S) is Java's text type.

2. Why do we use it?

Java runs banks, Android apps, and large backends. Its strictness catches mistakes early, which matters at scale.

3. Syntax breakdown

  • public class Main {

    Declares a container called Main. File must be Main.java. Braces group its contents.

  •   public static void main(String[] args) {

    The entry point. Execution starts here. void means it returns nothing.

  •     System.out.println("Hello");

    Prints Hello plus a newline. Statements end with a semicolon.

5. Common mistakes

  • File/class name mismatch: public class Main must be in Main.java.
  • Forgetting the semicolon at the end of the println statement.
  • Lowercase string: the type is String, not string.

Practice task

Print two lines: your name, then "Learning Java step by step."

Hint

Add a second System.out.println(...) line below the first.

Try it below — tests run automatically when you press Run.

java

Output

Press Run to see output.

Mini quiz

3 questions. Answer, then check.

  1. 1. Where does a Java program start?

  2. 2. What is a class?

  3. 3. How does a statement end?

4. Example — edit and run

java

Output

Press Run to see output.

Expected output: Hello, I am learning Java