Multi-Line Comments
A free lesson from Swipe Coding · Java, level 2 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
Sometimes a single line isn't enough to explain something. For longer comments, Java has a second notation: the multi-line comment. It begins with /* and ends with */ — everything in between is ignored, no matter how many lines it spans.
/* This is a
multi-line comment
that spans three lines. */
System.out.println("Hello!");Multi-line comments are especially well-suited for longer explanations — for example, to describe at the beginning of a file what a program actually does.
/*
* This program greets the user.
* It is for practice purposes only.
*/
public class Main {
public static void main(String[] args) {
System.out.println("Hello!");
}
}A multi-line comment in Java begins with /* and ends with ____.
Another practical use: with /* */ you can "turn off" multiple lines of code at once, without having to write // in front of every single line.
public class Main {
public static void main(String[] args) {
System.out.println("Start");
/*
System.out.println("Middle 1");
System.out.println("Middle 2");
*/
System.out.println("End");
}
}What does this program print?
public class Main {
public static void main(String[] args) {
System.out.println("Start");
/*
System.out.println("Middle 1");
System.out.println("Middle 2");
*/
System.out.println("End");
}
}An important difference from //: a multi-line comment always has to be closed with */. If you forget the */, the compiler treats all the remaining code up to the next */ as a comment — which can lead to confusing errors.
A multi-line comment /* ... */ can span multiple lines.
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 →