Loading Posts...

How To Write Comments In Java Example Tutorial

How To Write Comments In Java Example Tutorial

How To Write Comments In Java Example Tutorial is today’s topic. Java comments are the statements that are not executed by a compiler and interpreter. The comments can be used to provide the information or explanation about a variable, method, class, or any statement. It can also be used to hide program code for a specific time.

How To Write Comments In Java

In the program, comments take part in making the program more human-readable by placing a detail of code involved, and proper use of the comments makes maintenance easier and finding bugs quickly. Comments are ignored by a compiler while compiling the code.

There are mainly three types of comments in Java.

  1. Single-Line Comment
  2. Multi-Line Comment
  3. Documentation Comment

#Java Single-line Comments

The single-line comment is used to comment only one line. See the following syntax.

// This is single-line comment

See the following example.

public class Conditionals {
  public static void main(String[] args) {
    // Single line comment here 
    System.out.println("Stranger Things Season 3 is best TV Show in 2019"); 
  }
}

In the above code, we have written the single line comment here.

#Java Multi Line Comment

Java multi-line comment is used to comment on multiple lines of code. See the following syntax.

/* 
This  
is  
multi line  
comment 
*/

See the following code.

public class Conditionals {
  public static void main(String[] args) {
   /* Let's write a
    multi-line comment. */  
    System.out.println("Stranger Things Season 3 is best TV Show in 2019"); 
  }
}

In the above code, I have written multi-line comment like Let’s write a multi-line comment.

#Java Documentation Comment

The documentation comment is used to create the documentation API. If we want to create documentation API, you need to use the Javadoc tool.

See the following syntax.

/** 
Write 
the java
documentation comment
*/

See the following code example.

public class Conditionals {
  public static void main(String[] args) {
    /**
     * Write the java documentation comment
     */
    System.out.println("Stranger Things Season 3 is best TV Show in 2019");
  }
}

In the above code, we have written the comment like we are providing documentation for that particular function.

We can use the Available tags to use while creating the documentation. See the following table.

TAG DESCRIPTION SYNTAX
@author It adds the author of the class. @author name-text
{@code} It displays text in code font without interpreting the text as HTML markup or nested Javadoc tags. {@code text}
{@docRoot} It represents the relative path to the generated document’s root directory from any generated page. {@docRoot}
@deprecated It adds a comment indicating that this API should no longer be used. @deprecated deprecatedtext
@exception It adds a Throws subheading to the generated documentation, with the classname and description text. @exception class-name description
{@inheritDoc} It inherits a comment from the nearest inheritable class or implementable interface. Inherits a comment from the immediate superclass.
{@link} It inserts an in-line link with the visible text label that points to a documentation for a specified package, class, or member name of a referenced class. {@link package.class#member label}
{@linkplain} Identical to {@link}, except that link’s label is displayed in plain text than code font. {@linkplain package.class#member label}
@param It adds a parameter with the specified parameter-name followed by the specified description to the “Parameters” section. @param parameter-name description
@return It adds a “Returns” section with the description text. @return description
@see It adds a “See Also” heading with a link or text entry that points to reference. @see reference
@serial It is used in that doc comment for a default serializable field. @serial field-description | include | exclude
@serialData It documents the data written by the writeObject( ) or writeExternal( ) methods. @serialData data-description
@serialField It documents an ObjectStreamField component. @serialField field-name field-type field-description
@since It adds a “Since” heading with the specified since-text to the generated documentation. @since release
@throws It @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 It adds a “Version” subheading with the specified version-text to the generated docs when the -version option is used. @version version-text

 

Finally, How To Write Comments In Java Example Tutorial is over.

The post How To Write Comments In Java Example Tutorial appeared first on AppDividend.

Get Free Email Updates!

Signup now and receive an email once I publish new content.

I agree to have my personal information transfered to MailChimp ( more information )

I will never give away, trade or sell your email address. You can unsubscribe at any time.

user

The author didnt add any Information to his profile yet

Loading Posts...