View RSS Feed

My Java Tips

Creating JavaDocs An Example

Rate this Entry
by , 11-09-2011 at 05:33 PM (1291 Views)
You are developing a software in a team and you are assigned to work on a particular package. You worked on it and submitted it after completion. The development team has to use the classes and methods written by you. To use them, they have to know a lot of things.


For a class, they should know:
- Constructors of class
- Is class a static?
Etc

For a method, they should know:
- Is method static?
- Return type of method.
- Parameter list of method.
Etc

To know these, they have to dig deep into your code. They have to check themselves constructors, methods and lot of other stuff which is hectic.

If the development team has JavaDocs for your package, life will become easier for them. So always use JavaDocs.

Now lets take an example:

We have a package called lecturers having two classes called WhereAbouts and Lecturer.

Class lecturers.WhereAbouts is as follows. We have used JavaDoc comments in it.


package lecturers;
Java Code:
import java.util.Date;

/**
 * WhereAbouts class contains general information about the lecturers of the University
 * @author Pollack
 * @version 1.1
 *
 */
public class WhereAbouts {
private String name;
private String idNo;
private String location;
private Date dob;
/**
 * @return the name
 */
public String getName() {
	return name;
}
/**
 * @param name the name to set
 */
public void setName(String name) {
	this.name = name;
}
/**
 * @return the idNo
 */
public String getIdNo() {
	return idNo;
}
/**
 * @param idNo the idNo to set
 */
public void setIdNo(String idNo) {
	this.idNo = idNo;
}
/**
 * @return the location
 */
public String getLocation() {
	return location;
}
/**
 * @param location the location to set
 */
public void setLocation(String location) {
	this.location = location;
}
/**
 * @return the dob
 */
public Date getDob() {
	return dob;
}
/**
 * @param dob the dob to set
 */
public void setDob(Date dob) {
	this.dob = dob;
}
}
Class lecturers.Lecturer is as follows. We have used JavaDoc comments in it.


Java Code:
package lecturers;

import java.util.ArrayList;
import java.util.Date;

/**
 * Lecturer class contains methods specific to the lecturers
 * @author Pollack
 * @version 1.0
 *
 */
public class Lecturer extends WhereAbouts {
private Date yearOfJoining;
private String education;
/**
 * @return the yearOfJoining
 */
public Date getYearOfJoining() {
	return yearOfJoining;
}
/**
 * @param yearOfJoining the yearOfJoining to set
 */
public void setYearOfJoining(Date yearOfJoining) {
	this.yearOfJoining = yearOfJoining;
}
/**
 * @return the education
 */
public String getEducation() {
	return education;
}
/**
 * @param education the education to set
 */
public void setEducation(String education) {
	this.education = education;
}

/** Used to add new Lecturer
 * @param empCode Employee code of the new employee.
 */
public void addNewLecturer(int empCode){

}

/** Used to get Lecturer data.
 * @param empCode Employee code employee for which the data is required.
 * @return Returns an ArrayList with all the employee data.
 */
public ArrayList getLecturerData(int empCode){
	return new ArrayList();
}

}
We have to generate JavaDocs for the package lecturers. Click Project from the Eclipse menu bar and select JavaDoc.
Now select the project containing lecturer package and then select the basic options and proceed. JavaDocs will be generated.

Following are few screen shots of the docs generated:

Whereabouts

Lecturer

Submit "Creating JavaDocs  An Example" to Facebook Submit "Creating JavaDocs  An Example" to Digg Submit "Creating JavaDocs  An Example" to del.icio.us Submit "Creating JavaDocs  An Example" to StumbleUpon Submit "Creating JavaDocs  An Example" to Google

Tags: None Add / Edit Tags
Categories
Eclipse

Comments