In programming, comments are lines of text in code meant for humans to read. The computer ignores these lines when running the program. Comments help explain what your code does, making it easier to understand and maintain.
// This is a single-line comment
// Anything after the double slashes is ignored by the computer
/*
This is a multi-line comment.
You can use it for longer explanations or to temporarily disable code.
*/
// Example of both types of comments in action
public class Main {
public static void main(String[] args) {
// Print a message to the console
System.out.println("Hello, World!"); // This prints text
}
}Output
Hello, World!
In this example, the comments are ignored by the compiler, and only the System.out.println statements are executed.