Java / Java 21 Coding Standards Interview Questions
What are the types of comments recommended in Java style guides?
Java style guides recognize three categories of comments, each with a distinct purpose:
| Type | Purpose |
Javadoc (/** ... */) | Documents the public contract of a class or method for external callers and generated API docs. |
Block comment (/* ... */) | Explains a non-obvious algorithm or a workaround, placed just above the code it describes. |
Line comment (//) | Adds a short clarifying note on or above a single statement. |
Standards discourage comments that restate what the code already says, such as // increment i above i++, and instead push authors toward naming the code clearly enough that a comment explaining "what" is rarely needed - comments are reserved for explaining "why".
More Related questions...