Classes
A free lesson from Swipe Coding · Java, level 1 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
In Java, every piece of code you write lives inside a class. A class is like a container or blueprint that holds all your program code together. Without a class, there is no program in Java.
public class Main {
}The keyword "class" tells the Java compiler: "A new class starts here." Before it usually comes "public" — this means the class is visible and usable from anywhere, not just within its own file.
public class Car {
}In Java, every piece of code you write belongs inside a ____.
By convention, a class name should start with a capital letter, for example "Main", "Car", or "Calculator". This isn't a strict compiler rule, but practically every Java developer follows it so code looks consistent for everyone.
What best describes a class in Java?
A Java program can't exist without at least one class — all the code must be housed inside one. Next, we'll look at how a program inside such a class actually starts running: with the main() method.
A Java program can be written completely without a class.
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 →