Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Comments · Lesson 20 of 28

Why Comments Matter

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

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

🤖
Comments won't run, but they might just save future-you a headache. 📝

A comment is a note in the code that the Java compiler completely ignores. Comments never change what a program does — they exist purely for humans who read the code: yourself a few weeks from now, or colleagues who look at your code later.

public class Main {
    public static void main(String[] args) {
        // This line greets the user
        System.out.println("Hello, World!");
    }
}
The compiler skips the line with the comment entirely — it has no effect whatsoever on the program.
True or false

Comments are executed by the Java compiler like normal code.

🤖
A comment that just repeats the code isn't pulling its weight. 📝

Code you write today, you often don't read again until weeks or months later — and by then you've forgotten why you wrote certain lines the way you did. A good comment immediately explains to you (or someone else) what's going on, without you having to think through the entire code again.

// TODO: Add an evening greeting later
System.out.println("Good morning!");
A TODO comment is a reminder to yourself or your team about what still needs to be done later.
Fill in the blank

A comment that marks an open task for later often begins with the word ____.

🤖
This WHY vs WHAT distinction is the whole secret to good comments. 💡

Comments are especially valuable when they explain WHY something is done in the code — not just WHAT is done. The "what" can often be read directly from the code. The "why," on the other hand, exists only in the mind of the person who wrote the code.

// We print the text twice so the test can clearly recognize the output
System.out.println("Start");
System.out.println("Start");
This comment explains the intent behind the code — information you can't tell from the code alone.
Quick check

What are comments in Java mainly intended for?

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 →