Use Javadoc to speculate Java development documentation

zhaozj2021-02-16  91

Usually we write Java programs that may rarely write annotations, but when you really develop projects in the company. There is usually a strict documentation requirement, I talk about it is not a design or test document, but javadoc. I have always thought that Javadoc seems to be convenient than MSDN, and it is equally uncomfortable.

Javadoc is a very important tool in J2SDK. If you write a comment in Java's source code, then it can generate the corresponding document. The developer will look very convenient. Many IDEs can generate Javadoc directly, here you introduce how to write Javadoc and how to generate Javadoc under Eclipse.

Javadoc usually extracts information from package, public or protected fields, disclosed or protected fields, disclosed or protected methods. Each annotation should be started with * / end in / **. For example / ** * * @param id the coreID of the person * @param userName the name of the person * you should use the constructor to create a person object * / public SecondClass (int id, String userName) {this.id = ID; this.username = username;} The annotation should be written in front of the section you want to explain, as shown above. And there is a mark of HTML, if it is not marked above, then you shop usr the ... will be tight with @Param UserName .... This is not what we hope. General notes can be divided into class annotations, method comments, field annotations, and more. The following is a simple introduction

Class annotation class comment should be in front of the class declaration behind the IMPORT statement, such as package com.north.java;

/ ** * @Author Ming * * this interface is to define a method print () * You Should Implements this interface is you want to print the username * @see com.north.ming.mainclass # main (string []) * / public interface dosomething {/ ** * @Param Name Which Will Be Printed * @return Nothing will be returned * * / public void print (String name);} where @Author and @see are commonly used annotation first representation The author, the second representation of the reference.

2. Method Note Method Note To follow the front of the method, you can use tags such as @param @return @throws. For example / ** * * @param i * @return true if ..... else false * @throws IOException when reading the file, if something wrong happened * then the method will throws a IOException * / public boolean doMethod (int i "throws oException {return"}

3. Field Note Only the field of public only needs to comment, usually Static German, such as / ** * the static filed hello * / public static int hello = 1; in Eclipse, we create new Java Project and prepare several interfaces and classes You can generate a document with Javadoc. From the menu Project, choose Generate Javadoc, there will be a wizard. You follow the setup requirements of his prompt step by step, it is best to ask you if you say a javadoc.xml, if you choose to generate He will generate a javadoc.xml under the DOC. When you update your document, you can run javadoc.xml directly with Ant. After the selection is complete, you can find a directory DOC in Project is your javadoc, you want to write a good Javadoc a very good way to refer to Java API DOC. It is very important to develop a good programming habit, let alone this is not difficult. Below is my writing blog code and comments / * * created on 2004-7-25 * * Todo to change the template for this generated file go to * window - preferences - java - code style - code templates * / package COM .north.ming;

/ ** * @Author p2800 * * Todo to change the template for this generated type comment go to * window - preferences - java - code style - code templates * / public class mainclass {

Public static void main (string [] args) {}} / * * Created on 2004-7-25 * * Todo to change the Template for this generated file go to * window - preferences - java - code style - code templates * / Package com.north.ming;

Import java.io.ioException;

/ ** * @author P2800 * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates * / public class SecondClass {/ ** * the static filed hello * / public static int hello = 1; private int id; private String userName; / ** * * @param id the coreID of the person * @param userName the name of the person * you should use the constructor to create a person object * / public SecondClass (int ID, string username) {this.id = ID; this.username = username;} / ** * @return returns the username. * / Public string getUsername () {Return Username;} / ** * @Param userName The userName to set * / public void setUserName (String userName). {this.userName = userName;} / ** * * @param i * @return true if ..... else false * @throws IOException when reading the File, if Something Wrong Happened * Then the method will throws a IOException * / public boolean doMethod (int i) throws IOException {return true;}} / * * Created on 2004-7-25 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates * / package com.north.java; / ** * @author ming * * this interface is to define a method print () * you should implements this interface is you want to print the username * @see com.north.ming.MainClass # main (String []) * / public interface DoSomething {/ ** * @param name which will be printed * @return nothing will be returned * * / public void print (String Name);

转载请注明原文地址:https://www.9cbs.com/read-13453.html

New Post(0)