Step 2 -: Java Comments

 The purpose of including comments in your code is to explain what the code is doing.

Type of Java Comments -:

  • Line Comment
  • Block Comment
  • Document Comment

Line Comment 
    A single-line comment starts with two forward slashes and continues until it reaches the end of the line.

ex -:



output -:



Block Comment  (Multi-Line Comment)

Java also supports comments that span multiple lines.
You start this type of comment with a forward slash followed by an asterisk, and end it with an asterisk followed by a forward slash.

ex-:


output -:





Java does not support nested multi-line comments.
However, you can nest single-line comments within multi-line comments.

ex-:
/* This is a single-line comment:

    // a single-line comment

 */


Document Comment
Documentation comments are special comments that have the appearance of multi-line comments, with the difference being that they generate external documentation of your source code. These begin with a forward slash followed by two asterisks, and end with an asterisk followed by a forward slash.

ex-:



/** This is a documentation comment */

/** This is also a
    documentation comment */


Javadoc is a tool which comes with JDK and it is used for generating Java code documentation in HTML format from Java source code which has required documentation in a predefined format.

When a documentation comment begins with more than two asterisks, Javadoc assumes that you want to create a "box" around the comment in the source code. It simply ignores the extra asterisks.


ex-: 

/**********************

This is the start of a method

***********************/
This will retain just the text "This is the start of a method" for the documentation.



Comments

Popular posts from this blog

Create your first Java program

Java Variables

Java OOP