Object Oriented Programming: Unit I: Introduction to OOP and Java

JavaDoc Comments

Syntax with Example Java Programs

Javadoc is a convenient, standard way to document your Java code. Javadoc is actually a special format of comments. There are some utilities that read the comments, and then generate HTML document based on the comments.

JavaDoc Comments

Javadoc is a convenient, standard way to document your Java code. Javadoc is actually a special format of comments. There are some utilities that read the comments, and then generate HTML document based on the comments. HTML files give us the convenience of hyperlinks from one document to another.

There are two types of Javadoc comments -

• Class level comments

• Member level comments

The class level comments describe the purpose of classes and member level comments describe the purpose of members.

The Javadoc comments start with /** and end with */ For example

/** This is a Javadoc comment statement*/

Class Level Comments

The class level comments provide the description and purpose of the classes. For example - /**

*@author XYZ

* The Employee class contains salary of each employee the organization

*/

public class Employee

{

//Employee class code

}

Member Level Comments

The member level comments describe the data members, methods and constructors used in particular class. In this type of comments special tags are used to describe the things. The most commonly used tags are -

The example of member level comments for the Employee class is as shown below /**

* @author XYZ

* The Employee class contains salary of each employee the organisation

*/

public class Employee

{

/**

*Employee information for knowing the salary

*/

private int amtSalary;

/**

*The constructor defined to initialise the salary amount

*/

public Employee()

{

this.salary=0;

}

/**

* This method returns the salary amount of particular employee

*@return int

*/

public int getAmtSalary()

{

return salary;

}

/**

*@param int No_of_Days_Worked is for total number of working days

* @param int Payscale is for payment scale as per the designation of the employee

*/

public void setAmtSalary(int No_of_Days_Worked, int Payscale)

{

this.salary=No_of_Days_Worked* Payscale;

}

Along with the above mentioned tags some HTML tags can also be included in Javadoc comments. For example we can use<table><img> tags in Javadoc. Also we can include special tags like &lt in the Javadoc. Some words like true, false and null can also be included in Javadoc.

Object Oriented Programming: Unit I: Introduction to OOP and Java : Tag: : Syntax with Example Java Programs - JavaDoc Comments