Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Java Program Structure · Lesson 11 of 28

Classes

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

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

🤖
Every Java program needs a home for its code — that's exactly what a class gives it. 🏠

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" followed by the name of the class — here the class is called "Main".
🤖
Notice how 'public' opens the door for other code to use this class. 🚪

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 {

}
This is also a valid (still empty) class — it's simply called "Car" instead of "Main".
Fill in the blank

In Java, every piece of code you write belongs inside a ____.

🤖
Capital letters for class names — small rule, big consistency win. 🔤

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.

Quick check

What best describes a class in Java?

🤖
Every Java program needs at least one of these to even exist. 🏗️

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.

True or false

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 →