如何制作我的程序的JAVADOC?

时间:2017-12-17 23:52:15

标签: java javadoc dao

这是我的代码

public class Client
{
   protected int cod;
   protected String name;

   public void setCod(int cod) throws Exception
   {
      if(cod==null)
      throw new Exception("Invalid code!");

      this.cod = cod;
   }

   public int getCod()
   {
      return this.cod;
   }

   public void setName(String name) throws Exception
   {
      if(name==null || name.equals("")
      throw new Exception("Invalid name!");

      this.name = name;
   }

   public String getName()
   {
      return this.name;
   }

   public Client(int cod, String name) throws Exception
   {
      this.setCod(cod);
      this.setName(name);
   }

   public boolean equals(Object obj)
   {
      if(this==obj)
      return true;

      if(obj==null)
      return false;

      if(!(obj instanceof Client))
      return false;

      Client client = (Client)obj;

      if(this.cod!=client.cod)
      return false;

      if(this.name!=client.name)
      return false;

      return true;
   }

   public String toString()
   {
      return "Code: " + this.cod + "\n" +
             "Name: " + this.name;
   }

   public int hashCode()
   {
      int ret = 444;

      ret += ret*7 + new Integer (this.cod).hashCode();
      ret += ret*7 + (this.name).hashCode();

      return ret;
   }

   public Object clone()
   {
      Client ret = null;

      try
      {
         ret = new Client(this);
      }
      catch(Exception error)
      {
       // this is never null 
      }

      return ret;
   }

   public Client(Client model) throws Exception
   {
      if(model==null)
      throw new Exception("Inexistent model!");

      this.cod = model.cod;
      this.name = model.name;
   }

}


我知道,要发表评论,你必须加上“//”或“/ *”和“* /”。但是如何根据JAVADOC规则发表评论?
如果你知道怎么样,你能用JAVADOC复制我的代码并把它放在你的答案中吗?谢谢:)
请告诉我,什么是JAVADOC,它的用途是什么?有没有简单的方法来制作它?

1 个答案:

答案 0 :(得分:3)

Javadoc是您在程序中使用的一种注释,用于组织它,使程序更“友好”,并使用您评论的所有内容创建页面HTML,如下所示:https://memorynotfound.com/wp-content/uploads/generate-html-javadoc-maven-user.png

所以,要创建一个javadoc,你最好用“/ **”代替“/ *”。 在创建javadoc时,您需要了解各种类型的命令。

  

@author - 谁创建了该程序   
@throws - 例外   
@param - 方法参数   
@return - 方法返回的内容



所以,使用javadoc的代码将是这样的:

/**
  * @author IncredibleCoding
  */
public class Client
{
protected int cod;
protected String name;

/**
  * instance the code passed
  */
public void setCod(int cod) throws Exception
{
  if(cod==null)
  throw new Exception("Invalid code!");

  this.cod = cod;
}

/**
  * @returns the code
  */
public int getCod()
{
  return this.cod;
}

/**
  * instance the name passed
  * @param name, that is the name passed
  * @throws Exception, if the name is in invalid format
  */
public void setName(String name) throws Exception
{
  if(name==null || name.equals("")
  throw new Exception("Invalid name!");

  this.name = name;
}

/**
  * @returns the name 
  */
public String getName()
{
  return this.name;
}

/**
  * the constructor
  * @param cod, that is the code passed
  * @param name, that is the name passed
  */
public Client(int cod, String name) throws Exception
{
  this.setCod(cod);
  this.setName(name);
}

/**
  * @param obj, that is the object that will be compared
  * @returns true if the object is equal to this, false if the object isn't equal
  */
public boolean equals(Object obj)
{
  if(this==obj)
  return true;

  if(obj==null)
  return false;

  if(!(obj instanceof Client))
  return false;

  Client client = (Client)obj;

  if(this.cod!=client.cod)
  return false;

  if(this.name!=client.name)
  return false;

  return true;
}

/**
  * returns the formatted variable like String
  */
public String toString()
{
  return "Code: " + this.cod + "\n" +
         "Name: " + this.name;
}

/**
  * returns the hashCode of a variable
  */
public int hashCode()
{
  int ret = 444;

  ret += ret*7 + new Integer (this.cod).hashCode();
  ret += ret*7 + (this.name).hashCode();

  return ret;
}

/**
  * clone the object
  */
public Object clone()
{
  Client ret = null;

  try
  {
     ret = new Client(this);
  }
  catch(Exception error)
  {
   // this is never null 
  }

  return ret;
}

/**
  * "copy" the variables
  * @param model, that is the object that will be copied
  * @throws Exception, if the model is inexistent
  */
public Client(Client model) throws Exception
{
  if(model==null)
  throw new Exception("Inexistent model!");

  this.cod = model.cod;
  this.name = model.name;
}

}

你可以看一下这个页面,这对你也有帮助:
https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javadoc.html