日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java基本语文档_Java 文档注释

發布時間:2025/4/16 java 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java基本语文档_Java 文档注释 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Java 文檔注釋

Java 支持三種注釋方式。前兩種分別是 // 和 /* */,第三種被稱作說明注釋,它以 /** 開始,以 */結束。

說明注釋允許你在程序中嵌入關于程序的信息。你可以使用 javadoc 工具軟件來生成信息,并輸出到HTML文件中。

說明注釋,使你更加方便的記錄你的程序信息。

javadoc 標簽

javadoc 工具軟件識別以下標簽:

標簽

描述

示例

@author

標識一個類的作者

@author description

@deprecated

指名一個過期的類或成員

@deprecated description

{@docRoot}

指明當前文檔根目錄的路徑

Directory Path

@exception

標志一個類拋出的異常

@exception exception-name explanation

{@inheritDoc}

從直接父類繼承的注釋

Inherits a comment from the immediate surperclass.

{@link}

插入一個到另一個主題的鏈接

{@link name text}

{@linkplain}

插入一個到另一個主題的鏈接,但是該鏈接顯示純文本字體

Inserts an in-line link to another topic.

@param

說明一個方法的參數

@param parameter-name explanation

@return

說明返回值類型

@return explanation

@see

指定一個到另一個主題的鏈接

@see anchor

@serial

說明一個序列化屬性

@serial description

@serialData

說明通過writeObject( ) 和?writeExternal( )方法寫的數據

@serialData description

@serialField

說明一個ObjectStreamField組件

@serialField name type description

@since

標記當引入一個特定的變化時

@since release

@throws

和 @exception標簽一樣.

The @throws tag has the same meaning as the @exception tag.

{@value}

顯示常量的值,該常量必須是static屬性。

Displays the value of a constant, which must be a static field.

@version

指定類的版本

@version info

文檔注釋

在開始的 /** 之后,第一行或幾行是關于類、變量和方法的主要描述。

之后,你可以包含一個或多個各種各樣的 @ 標簽。每一個 @ 標簽必須在一個新行的開始或者在一行的開始緊跟星號(*).

多個相同類型的標簽應該放成一組。例如,如果你有三個 @see 標簽,可以將它們一個接一個的放在一起。

下面是一個類的說明注釋的實例:

/*** 這個類繪制一個條形圖

*@authorrunoob

*@version1.2*/

javadoc 輸出什么

javadoc 工具將你 Java 程序的源代碼作為輸入,輸出一些包含你程序注釋的HTML文件。

每一個類的信息將在獨自的HTML文件里。javadoc 也可以輸出繼承的樹形結構和索引。

由于 javadoc 的實現不同,工作也可能不同,你需要檢查你的 Java 開發系統的版本等細節,選擇合適的 Javadoc 版本。

實例

下面是一個使用說明注釋的簡單實例。注意每一個注釋都在它描述的項目的前面。

在經過 javadoc 處理之后,SquareNum 類的注釋將在 SquareNum.html 中找到。

SquareNum.java 文件代碼:

importjava.io.*;/**

* 這個類演示了文檔注釋

*@authorAyan Amhed

*@version1.2*/publicclassSquareNum{/**

* This method returns the square of num.

* This is a multiline description. You can use

* as many lines as you like.

*@paramnum The value to be squared.

*@returnnum squared.*/publicdoublesquare(doublenum){returnnum*num;}/**

* This method inputs a number from the user.

*@returnThe value input as a double.

*@exceptionIOException On input error.

*@seeIOException*/publicdoublegetNumber()throwsIOException{InputStreamReaderisr=newInputStreamReader(System.in);BufferedReaderinData=newBufferedReader(isr);Stringstr;str=inData.readLine();return(newDouble(str)).doubleValue();}/**

* This method demonstrates square().

*@paramargs Unused.

*@returnNothing.

*@exceptionIOException On input error.

*@seeIOException*/publicstaticvoidmain(Stringargs[])throwsIOException{SquareNumob=newSquareNum();doubleval;System.out.println("Enter value to be squared:");val=ob.getNumber();val=ob.square(val);System.out.println("Squared value is"+val);}}

如下,使用 javadoc 工具處理 SquareNum.java 文件:

$ javadoc SquareNum.java

Loading source file SquareNum.java...

Constructing Javadoc information...

Standard Doclet version 1.5.0_13

Building tree for all the packages and classes...

Generating SquareNum.html...

SquareNum.java:39: warning - @return tag cannot be used\

in method with void return type.

Generating package-frame.html...

Generating package-summary.html...

Generating package-tree.html...

Generating constant-values.html...

Building index for all the packages and classes...

Generating overview-tree.html...

Generating index-all.html...

Generating deprecated-list.html...

Building index for all classes...

Generating allclasses-frame.html...

Generating allclasses-noframe.html...

Generating index.html...

Generating help-doc.html...

Generating stylesheet.css...

1 warning

$

總結

以上是生活随笔為你收集整理的java基本语文档_Java 文档注释的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。