single
Comments
Swipe to show menu
Comments are notes inside your code that are completely ignored by the program when it runs. They are meant for humans, not the computer — Java skips them during execution, so they do not affect how your program works in any way.
Despite that, comments are extremely useful. They help you explain what your code is doing, leave reminders for yourself, and make your programs easier to read and understand — especially when they become longer or more complex.
Single-line Comments
A single-line comment starts with //. Everything written after // on the same line is treated as a comment.
Main.java
12345678package com.example; public class Main { public static void main(String[] args) { // This prints a message to the screen System.out.println("Hello!"); } }
Multi-line Comments
When you need to write longer explanations, you can use multi-line comments. These start with /* and end with */. Everything between them is ignored by Java.
public class Main {
public static void main(String[] args) {
/*
This program prints a simple message.
The comment can span multiple lines.
Java will ignore everything inside it.
*/
System.out.println("Hello!");
}
}
Comments are especially useful in larger programs because they help you understand what different parts of the code are supposed to do without having to analyze everything from scratch.
Swipe to start coding
Your task is to identify the error and comment out the code fragment that contains it.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat