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
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!");
}
}Comments are executed by the Java compiler like normal code.
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 comment that marks an open task for later often begins with the word ____.
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");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 →