Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Java Program Structure · Lesson 15 of 28

Java Syntax Basics

A free lesson from Swipe Coding · Java, level 1 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
Time to pull together everything you have learned about the rules. 📋

You now know about classes, the main() method, statements, and code blocks. Now let's summarize a few basic syntax rules that apply to every Java program.

System.out.println("Hello!"); // correct
system.out.println("Hello!"); // Error! Java is case-sensitive
Java is "case-sensitive" — capitalization makes a difference. "System" and "system" are two completely different words as far as Java is concerned.
🤖
Case matters everywhere in Java — no exceptions. 🔠

This applies to everything in Java: class names, method names, keywords like "class" or "public". A single letter with the wrong capitalization leads to a compiler error.

Another fixed rule: the name of the Java file must exactly match the name of the public class inside it, including capitalization, plus the ".java" extension.

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, Java!");
    }
}
This class is called "Main", so the file must be named exactly "Main.java" — not "main.java" and not "MainClass.java".
True or false

Java is case-sensitive (for example, "Main" and "main" are different).

Indentation — meaning spaces at the start of a line that visually shift nested blocks inward — is, on the other hand, not necessary for the compiler. Java compiles code without any indentation just fine. Still, you should always indent cleanly, because it makes your code much easier for people to read.

public class Main {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
This code compiles just fine — it's simply much harder to read without indentation than the indented version above.
Quick check

Which statement about indentation in Java is correct?

🤖
You now have the complete rulebook for any Java program. 📖

In summary, every Java program follows these rules: the code lives in a class, execution starts in the main() method, every statement ends with a semicolon, related statements sit in a block of curly braces, Java is case-sensitive, and the file name must match the public class.

Fill in the blank

A file containing the class "public class Main" must be named ____.

Chapter quiz

Java Program Structure

10 questions · pass with 60% — just like in the app.

Quick check

What best describes a class in Java?

True or false

A Java program can be written completely without a class.

Fill in the blank

A Java program begins its execution in the ____ method.

Quick check

Which keyword in the main() signature means the method doesn't return a value?

True or false

A statement in Java must always end with a semicolon.

Fill in the blank

Java executes a program's statements ____ (from top to bottom).

Fill in the blank

Curly braces { } group statements into a ____.

True or false

Every opening curly brace { needs a matching closing brace }.

Quick check

What must the file containing a class "public class Main" be named?

True or false

Java is case-sensitive.

Keep your streak going in Swipe Coding

Swipe through every level of Java on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →