Thursday, October 31, 2013

Documentation in Java

In this tutorial, you will learn to do documentation of your Java programs. Java comes with a powerful tool called javadoc. This tool allows Java developer easily to create documentation of their programs. The javadoc tool extracts your comments embedded in the source code, constant fields, class name, methods and outputs these information in html files.
The comments that can be recognized by the javadoc tool must be placed between /** and */. Besides normal text, in the block of /** and */, there are some special tags that can be recognized by the javadoc tool. The table below summarizes these tags.

Tag Description Example
@author The author tag allows you to specify the information about the author. @author Dara Yuk
@deprecated This tag specifies that a class or method is deprecated in the current version. @deprecated Deprecated
@exception This tag is used to specify the type of exception to be thrown. @exception IOException
{@link} This tag is used to specify the in-line link to other page. See the {@link <a href="JCalc.htm">JCalc</a>}
@param This tag specifies the parameter of a method. @param a
@return This tag allows you to specify the return value of a method. @return sum
@see You can use this tag to provide a link to other topic or page. This link will shown at the "See Also" section of the page. @see <a href="Jtutorial.html">Java Tutorial</a>
@serial This tag specifies the default serial field. You can describe the field and its possible values. The information about this tag will be shown in the Serial Form page. @serial The PI field
@since You will use this tag to spcify the version of your software when a specific change was introduced. @since 1.6
{@value} You will use this tag to display the value of a constant field. The value of this field is {@value}.
@version This tag will be used to specify the current version of your software. @version 1.0

For example, you have the JCalc class that is a simple calculator class. It contains twelve methods that can be used to add, subtract, multiply, and divide integer and floating-pointer numbers.

/**
 * This is the JCalc class. It has twelve methods that can be called to add, subtract, multiply,
 * and divide floating-point numbers. See the {@link <a href="index.html">JCalc</a>}.
 * @author Dara Yuk 
 * @version 1.0
 * 
 */
public class JCalc{

/**
* The value of the constant is {@value}.
*/
public static final double PI=Math.PI;
public static void main(String[] args){

}
/**
* This method adds two integer values a and b.
* @param a
* @param b
* @return a+b
* @see <a href="JavaTutorial.html">Java Tutorial</a>
*/
public int sum(int a,int b){
return(a+b);
}
/**
* This method adds two float values a and b.
* @param a
* @param b
* @return a+b
*/
public float sum(float a,float b){
return(a+b);
}
/**
* This method adds double values a and b.
* @param a
* @param b
* @return a+b
*/
public double sum(double a,double b){
return(a+b);
}

/**
* This method subtracts b from a. The parameters a and b are integer. 
* @param a
* @param b
* @return a-b
*/
public int subtract(int a,int b){
return(a-b);
}
/**
* This method subtracts b from a. The parameters a and b are float. 
* @param a
* @param b
* @return a-b
*/
public float subtract(float a,float b){
return(a-b);
}
/**
* This method subtracts b from a. The parameters a and b are double. 
* @param a
* @param b
* @return a-b
*/
public double subtract(double a,double b){
return(a-b);
}

/**
* This method multiplies a and b. The parameters a and b are integer.
* @param a
* @param b
* @return a*b
*/
public int multiply(int a,int b){
return(a*b);
}
/**
* This method multiplies a and b. The parameters a and b are float.
* @param a
* @param b
* @return a*b
*/
public float multiply(float a,float b){
return(a*b);
}
/**
* This method multiplies a and b. The parameters a and b are double.
* @param a
* @param b
* @return a*b
*/
public double multiply(double a,double b){
return(a*b);
}
/**
* This method divides a by b. The parameters a and b are integer.
* @param a
* @param b
* @return a/b
*/
public double divide(int a,int b){
return(a/b);
}
/**
* This method divides a by b. The parameters a and b are float.
* @param a
* @param b
* @return a/b
*/
public float divide(float a,float b){
return(a/b);
}
/**
* This method divides a by b. The parameters a and b are double.
* @param a
* @param b
* @return a/b
*/
public double divide(double a,double b){
return(a/b);
}
}


To create the document of the JCalc class, from the command prompt, enter the directory that contains the JCalc.java file and type the following command:


D:\eclipse\charts\Calculator\src>javadoc -d docs JCalc.java

While javadoc is processing the file, the messages below are displayed on the screen.

Loading source file JCalc.java...
Constructing Javadoc information...
Standard Doclet version 1.7.0_21
Building tree for all the packages and classes...
Generating docs\JCalc.html...
Generating docs\package-frame.html...
Generating docs\package-summary.html...
Generating docs\package-tree.html...
Generating docs\constant-values.html...
Generating docs\serialized-form.html...
Building index for all the packages and classes...
Generating docs\overview-tree.html...
Generating docs\index-all.html...
Generating docs\deprecated-list.html...
Building index for all classes...
Generating docs\allclasses-frame.html...
Generating docs\allclasses-noframe.html...
Generating docs\index.html...
Generating docs\help-doc.html...

The document pages will be generated in the src/docs folder.


9 comments:

  1. This is very interesting, You are a very skilled postger. I've joined your feed and look forward to seeking more of your magnificent post. Also, I've shared your website in my social networks! I do agree with all the ideas you've presented in your post. They're very convincing and will certainly work. Still, the posts are very short for novices. Could you please extend them a bit from next time? Thanks for the post. web page design singapore

    ReplyDelete
  2. Nice read, I just passed this onto a friend who was doing some research on that. And he actually bought me lunch because I found it for him smile So let me rephrase that: Thanks for lunch! marketing strategies

    ReplyDelete
  3. Thank you for another informative site. Where else may just I am getting that type of info written in such a perfect way? I have a mission that I'm just now operating on, and I have been on the glance out for such information.digital marketing campaign

    ReplyDelete
  4. Great blog! Is your theme custom made or did you download it from somewhere? A design like yours with a few simple tweeks would really make my blog stand out. Please let me know where you got your design. Cheersecommerce website development singapore

    ReplyDelete
  5. Wow! This blog looks exactly like my old one! It's on a entirely different subject but it has pretty much the same layout and design. Excellent choice of colors!komodo liveaboard

    ReplyDelete
  6. I do not even know how I ended up here, but I thought this post was great. I don't know who you are but certainly you are going to a famous blogger if you are not already ;) Cheers! productivity solutions grant (psg)

    ReplyDelete
  7. Wonderful work! This is the type of info that should be shared around the web. Shame on Google for not positioning this post higher! Come on over and visit my site . Thanks =)
    b2b marketing

    ReplyDelete
  8. It's a shame you don't have a donate button! I'd certainly donate to this excellent blog! I suppose for now i'll settle for bookmarking and adding your RSS feed to my Google account. I look forward to new updates and will share this site with my Facebook group. Talk soon!
    blogger singapore

    ReplyDelete
  9. Thank you for another informative blog. The place else could I am getting that type of information written in such a perfect method? I have a challenge that I'm simply now working on, and I have been at the glance out for such info. buy landscape paintings

    ReplyDelete