FreeCode

Donate HTML/CSS JavaFX Java Home
Array Data Structures Array List Data Structures Linked List Data Structures Stack Data Structures Queue Data Structures While Loops Do-While Loops For Loops For-each Loops If, Else, and Multi-Way If Statements Switch Statements Try-Catch Blocks Comment Types and Javadoc Java Classes Java Methods

Comment Types and Javadoc

Code Description:

Comments can be used to write internal descriptions and notes in your code and are sometimes used to help with the debugging process. Comments are ignored as the program progresses through the code. There are three types of comments that are used by Java which are single-line, multi-line, and Javadoc. Single-line comments are typically used for 1 or 2 consecutive lines while multi-line comments are used for 3 or more lines. Javadoc helps document methods and is able to generate HTML formatted documentation.

Single-line Comment Syntax:

// Comments

Multi-line Comment Syntax:

/*



*/

Javadoc Syntax:

/**



*/

Comments Example Code:

public class Demo {

    /**
    * @author FreeCode.net
    * @param args
    * This is the main method and we are using Javadoc.
    */
    public static void main(String[] args) {
		
        // This is a single line comment
		
        /*
        * This is a multi-line comment.
	* These are super handy when writing a description for your code.
	* We recommend using this when you have 3 or more lines of text.
	*/
		
    }
	
}

How to Run This Code:

Make sure that your Class name is the same as ours. In this case, we are using the Class name of "Demo". Alternatively, you can change the Class name in the provided code to match yours. As these are comments, you will get no output.

Javadoc Tags

  • The @author tag states who wrote the code. Ex: @author John Smith
  • The @version tag states the version number and date created. Ex: @version 1.12, 04/21/2017
  • The @param tag is used with methods and constructors and is used to describe each parameter. The standard format consists of the parameter name followed by it's description. Ex: @param radius The radius in inches for the circle.
  • The @return tag is used to describe what a method with a non-void return type returns. Ex: @return apples The amount of apples bought.
  • The @throws tag is used to state which checked exceptions a method can throw. The exception name and a description of when it is thrown is included. Ex: @throws IOException Thrown when an input or output exception occurs.

Related Links: