Java Tutorial

Basic Concepts

Object Oriented Concepts

Coming Tutorials

>Home>Java Tutorial>Comment Types in Java

Java Tutorial

Basic Concepts

Object Oriented Concepts

Coming Tutorials



Java Comments

The comments are the word phrases added into the program to provide additional information about the components or logics used in programming. The comments are completely ignored by the Java compiler therefore comments does not affect the flow of execution of the program.

Writing comments is always beneficial to provide extra information related to the programming components used in a program. Because a Java developer may or may not work on the same project longer, he/she may get replaced with another developer, and if the new developer is maintaining the project then added comments will help him to understand the programs.

The Java provides three types of comments

  1. Multiline Document comment

    If you're writing an API that will be published or reused within your organization, you should write comprehensive Javadoc comments for every public class, method, and field, as well as protected methods and fields of non-final classes. Using javadoc tool you can easily create the documentation for that API in html format.

    /**

    *@author Topper Skills

    */

  2. Multiline Text Comment

    This kind of comments are used to add normal text comments and these comments will not create any document. You can add multiple line of code within /* text */.

    /*

    *

    */

  3. .
  4. Single Line Comment

    This is text comment also, but for single line comment, means you want to add a short description which is not more than a line then use single line comment //

    //comment text

Example:


class CommentDemo
{
/**
*
* @author Topper Skills
*  
*/

/*
We are using the sample comment to tell you that the public static void main(String[] args) 
method is the starting point of the program execution
*/

// main() method
public static void main(String[] args)
{
// adding 2 numbers
int sum= 10+20;
System.out.println(sum);
}
}

Share the article to help your friends