33 - Java - Documentation Comments - The Javadoc Tags
33 - Java - Documentation Comments - The Javadoc Tags
com
Advertisements
Java supports three types of comments. The first two are the // and the /* */. The third type is called a documentation comment. It begins with the character sequence /** and it ends with */. Documentation comments allow you to embed information about your program into the program itself. You can then use the javadoc utility program to extract the information and put it into an HTML file. Documentation comments make it convenient to document your programs.
@serialField
@since
@since release The @throws tag has the same meaning as the @exception tag. Displays the value of a constant, which must be a static field. @version info
Same as @exception. Displays the value of a constant, which must be a static field. Specifies the version of a class.
Documentation Comment:
After the beginning /**, the first line or lines become the main description of your class, variable, or method. After that, you can include one or more of the various @ tags. Each @ tag must start at the beginning of a new line or follow an asterisk (*) that is at the start of a line. Multiple tags of the same type should be grouped together. For example, if you have three @see tags, put them one after the other. Here is an example of a documentation comment for a class:
Example:
Following is a sample program that uses documentation comments. Notice the way each comment immediately precedes the item that it describes. After being processed by javadoc, the documentation about the SquareNum class will be found in SquareNum.html.
ipr jv.o* mot aai.; /* * *Ti casdmntae dcmnaincmet. hs ls eosrts ouetto omns *@uhrAa Ahd ato yn me *@eso 12 vrin . * / pbi casSurNm{ ulc ls qaeu /* * *Ti mto rtrstesur o nm hs ehd eun h qae f u.
*Ti i amliiedsrpin Yucnue hs s utln ecito. o a s *a mn lnsa yulk. s ay ie s o ie *@aa nmTevlet b surd prm u h au o e qae. *@eunnmsurd rtr u qae. * / pbi dul sur(obenm { ulc obe qaedul u) rtr nm*nm eun u u; } /* * *Ti mto ipt anme fo teue. hs ehd nus ubr rm h sr *@eunTevleipta adul. rtr h au nu s obe *@xeto IEcpinO ipterr ecpin Oxeto n nu ro. *@e IEcpin se Oxeto * / pbi dul gtubr)trw IEcpin{ ulc obe eNme( hos Oxeto Ipttemedrir=nwIpttemedrSse.n; nuSraRae s e nuSraRae(ytmi) BfeeRae iDt =nwBfeeRae(s) ufrdedr naa e ufrdedrir; Srn sr tig t; sr=iDt.edie) t naaraLn(; rtr (e Dul(t).obeau(; eun nw obesr)dulVle) } /* * *Ti mto dmntae sur(. hs ehd eosrts qae) *@aa ag Uue. prm rs nsd *@eunNtig rtr ohn. *@xeto IEcpinO ipterr ecpin Oxeto n nu ro. *@e IEcpin se Oxeto * / pbi sai vi mi(tigag[)trw IEcpin ulc ttc od anSrn rs] hos Oxeto { SurNmo =nwSurNm) qaeu b e qaeu(; dul vl obe a; Sse.u.rnl(Etrvlet b surd "; ytmotpitn"ne au o e qae: ) vl=o.eNme(; a bgtubr) vl=o.qaevl; a bsur(a) Sse.u.rnl(Surdvlei "+vl; ytmotpitn"qae au s a) } }
Now process above SquareNum.java file using javadoc utility as follows:
$jvdcSurNmjv aao qaeu.aa Laigsuc fl SurNmjv.. odn ore ie qaeu.aa. Cntutn Jvdcifrain. osrcig aao nomto.. Sadr Dce vrin1501 tnad olt eso .._3 Bidn te fraltepcae adcass. ulig re o l h akgs n lse.. Gnrtn SurNmhm.. eeaig qaeu.tl. SurNmjv:9 wrig-@euntgcno b ue\ qaeu.aa3: ann rtr a ant e sd i mto wt vi rtr tp. n ehd ih od eun ye Gnrtn pcaefaehm.. eeaig akg-rm.tl. Gnrtn pcaesmayhm.. eeaig akg-umr.tl. Gnrtn pcaete.tl. eeaig akg-rehm.. Gnrtn cntn-aushm.. eeaig osatvle.tl. Bidn idxfraltepcae adcass. ulig ne o l h akgs n lse.. Gnrtn oeve-rehm.. eeaig vriwte.tl. Gnrtn idxalhm.. eeaig ne-l.tl.
Gnrtn dpeae-ithm.. eeaig erctdls.tl. Bidn idxfralcass. ulig ne o l lse.. Gnrtn allse-rm.tl. eeaig lcassfaehm.. Gnrtn allse-orm.tl. eeaig lcassnfaehm.. Gnrtn idxhm.. eeaig ne.tl. Gnrtn hl-o.tl. eeaig epdchm.. Gnrtn syehe.s.. eeaig tlsetcs. 1wrig ann $
You can check all the generated documentation here: SquareNum.
Copyright tutorialspoint.com