• Multi-line comments begin with /* and end with */. They can span multiple lines and are often used for longer explanations, documentation, or temporarily disabling code blocks.
  • Multi-line comments are suitable for providing detailed descriptions of methods, classes, or sections of code.

 

This example uses a multi-line comment (a comment block) to explain the code:

Example

/* The code below will print the words Hello World
to the screen, and it is amazing */
System.out.println("Hello World");
 

Single or multi-line comments?

It is up to you which you want to use. Normally, we use // for short comments, and /* */ for longer.



Practice Excercise Practice now