Documenting Your Code - Java Language Basics

Java examples for Language Basics:Java Doc

Introduction

Use Javadoc to place comments before any class, method, or field that you want to document.

To begin such a comment, write the characters /**.

Then begin each subsequent line with an asterisk (*).

Lastly, close the comment with the characters */ on a line by themselves at the end.

Demo Code

import java.math.BigInteger; 

public class Main { 
    /** /*w  w  w .ja v a 2 s .  c  o  m*/
     * Accepts an unlimited number of values and 
     * returns the sum. 
     * 
     * @param nums Must be an array of BigInteger values. 
     * @return Sum of all numbers in the array. 
     */ 
     public static BigInteger addNumbers(BigInteger[] nums) { 
         BigInteger result = new BigInteger("0"); 
         for (BigInteger num:nums){ 
             result = result.add(num); 
         } 

         return result; 
     } 
    /** 
     * Test the addNumbers method. 
     * @param args not used 
     */ 
     public static void main (String[] args) { 
         BigInteger[] someValues = {BigInteger.TEN, BigInteger.ONE}; 
         System.out.println(addNumbers(someValues)); 
     } 
}

Result


Related Tutorials