CKTIS / Java
Comments and documentation in Java
Comments and documentation in Java: Java recognizes line //, block /* ... */, and documentation /** ... */ comments; javadoc interprets tags and generates API documentation from doc comments.
Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Syntax
commentsJava recognizes line //, block /* ... /, and documentation /* ... */ comments; javadoc interprets tags and generates API documentation from doc comments.
Use Javadoc for a public API contract with @param, @return, and @throws, and use {@code ...} to present identifiers and code fragments safely.
Block comments do not nest, so commenting out code containing */ closes the comment early; a stale comment is worse than a precise name.
Unicode escapes are processed before tokenization: a \u000a sequence inside // can become a line terminator and make the following text compile as code.
The // and /* ... */ comments do not change execution of int value = 7; the sole stdout line 7 confirms that they are treated as comments.
Examples
public class Main {
public static void main(String[] args) {
int value = 7; // this comment does not change the expression
/* A block comment can span lines. */
System.out.println(value);
}
}
Result
7
The // and /* ... */ comments do not change execution of int value = 7; the sole stdout line 7 confirms that they are treated as comments.