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
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-sensitiveThis 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!");
}
}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!");
}
}Which statement about indentation in Java is correct?
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.
A file containing the class "public class Main" must be named ____.
Java Program Structure
10 questions · pass with 60% — just like in the app.
What best describes a class in Java?
A Java program can be written completely without a class.
A Java program begins its execution in the ____ method.
Which keyword in the main() signature means the method doesn't return a value?
A statement in Java must always end with a semicolon.
Java executes a program's statements ____ (from top to bottom).
Curly braces { } group statements into a ____.
Every opening curly brace { needs a matching closing brace }.
What must the file containing a class "public class Main" be named?
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 →