• Single-line comments begin with // and continue until the end of the line. They are used to add brief explanations or annotations to specific lines of code.
  • Single-line comments are ideal for providing short, concise explanations directly alongside the code they describe.

Example

// This is a comment
System.out.println("Hello World");
 

This example uses a single-line comment at the end of a line of code:

Example

System.out.println("Hello World"); // This is a comment



Practice Excercise Practice now