Java Reference
In-Depth Information
/∗∗
∗ @param s
∗ @param n
∗/
As you can see, JavaDoc is a way to document your code using a special automatically
generated template. On the second line, we need to specify the description of the method.
On the next lines, we will describe the meaning of each of the method's parameters. Here
is a possible version of the JavaDoc documentation.
/∗∗
∗ Prints a string multiple times on the same line .
@param s The s t r i n g to be p r i n t ed .
@param n The frequency .
/
Fill in the JavaDoc for the rest of the methods. Now we are ready to compile our JavaDoc.
Note that the JavaDoc compiler does not work if you have used the default package for your
class. Go to the menu Run and select Generate JavaDoc . A new Web page with the JavaDoc
of your program should automatically open. Moreover, the JavaDoc will be automatically
displayed by NetBeans when you need it. For example, type “ printStrings( ”inthe main
method and press Ctrl+Space. Now you will see a description of the method and each of
the parameters.
Creating and using JavaDoc is an important part of writing a program. It helps
us prevent errors that are caused by using methods incorrectly, passing the wrong
arguments to methods, or passing the arguments in the wrong order.
As a general rule, add JavaDoc before every method and before every class. Use addi-
tional comments sparingly. For example, only code that performs a non-trivial task needs
to be explicitly documented. Remember to always give appropriate names to both methods
and variables. Just because a method is documented, it does not mean that its name can
be counterintuitive.
4.5 Sending Data between Methods
By now, we have a basic understanding of how methods work. They are like friends. We
send them some information and we ask them to do something. They perform the task and
present us with the result. Look at the following simple program and see if you can figure
outwhatitprints.
import java . util .
;
public class Example
{
public static void inc( int i) {
i ++;
} public static void main(String [] args)
{
int i=3;
 
Search WWH ::




Custom Search