Last Updated: 25 March, 2023
Comments are non-executable statements in Java, the purpose of a comment is to provide information about a set of statements or a single line of statement. It can be also used to comment on Java code if we don't want to execute that piece of code.
Comments are written inside the Java source code file but It is completely ignored by the Java compiler while compiling the code.
Java provides three different types of comments
Single-line Comment is one line of the statement, It starts and ends in the same line.
To write a single-line comment, we can use the // (two forward slashes) symbol. For example,
Multi-line comments mean commenting on more than one consecutive line of statements.
We use the /*....*/ symbol for writing multi-line comments. Any statements between /* and */ will be ignored by the Java compiler. For example,
Documentation comments are generally used when writing code for a project or software application, since they help generate a documentation page for reference, which can be used to get information about methods present, their parameters, etc.
Tag | Description | Syntax |
---|---|---|
@author | Adds the author name of a class. | @author name-text |
{@code} | Displays text in code font without interpreting the text as HTML markup or nested javadoc tags. | {@code text} |
{@docRoot} | Represents the relative path to the generated document’s root directory from any generated page. | {@docRoot} |
@deprecated | Adds a comment indicating that this API should no longer be used. | @deprecated deprecated text |
@exception | Adds a Throws subheading to the generated documentation, with the classname and description text. | @exception class-name description |
{@inheritDoc} | Inherits a comment from the nearest inheritable class or implementable interface. | Inherits a comment from the immediate surperclass. |
{@link} | Inserts an in-line link with the visible text label that points to the documentation for the specified package, class, or member name of a referenced class. | {@link package.class#member label} |
{@linkplain} | Identical to {@link}, except the link’s label is displayed in plain text than code font. | {@linkplain package.class#member label} |
@param | Adds a parameter with the specified parameter-name followed by the specified description to the “Parameters” section. | @param parameter-name description |
@return | Adds a “Returns” section with the description text. | @return description |
@see | Adds a “See Also” heading with a link or text entry that points to reference. | @see reference |
@serial | Used in the doc comment for a default serializable field. | @serial field-description | include | exclude |
@serialData | Documents the data written by the writeObject( ) or writeExternal( ) methods. | @serialData data-description |
@serialField | Documents an ObjectStreamField component. | @serialField field-name field-type field-description |
@since | Adds a “Since” heading with the specified since-text to the generated documentation. | @since release |
@throws | The @throws and @exception tags are synonyms. | @throws class-name description |
{@value} | When {@value} is used in the doc comment of a static field, it displays the value of that constant. | {@value package.class#field} |
@version | Adds a “Version” subheading with the specified version-text to the generated docs when the -version option is used. | @version version-text |
That's all guys, hope this Java article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com