Ad space (banner)
โ˜•Java Lessons
Lesson 17 / 68

Writing Comments

This lesson covers writing comments in Java, so your code's intent comes across clearly to others and to your future self. It's for anyone searching "Java comment syntax."

A comment is a note for humans with no effect on execution. // starts a single-line comment, and /* */ wraps a multi-line one.

The example shows three patterns: a whole-line comment like // This is a single-line comment, an inline comment at the end of a line of code like int price = 100; // product price (yen), and a multi-line comment wrapped in /* */.

A common early mistake is over-commenting until it becomes harder to read, not easier. Writing down "why this logic is needed" is genuinely useful, but there's no need to explain what's already obvious from the code.

In real projects, a special comment style called Javadoc can be used to auto-generate method documentation with a tool.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Java directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)