Java comment examples

Question: How do I create a comment in Java?

Answer: There are two ways to create Java comments, and both are shown in the example code below:

// this is a one-line comment

/**
 * this is also
 * a comment, but it can span multiple
 * lines.
 */

The // syntax makes everything after it on the current line a Java comment, and the /** ... */ syntax lets you create multi-line Java comments.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.