Hey,buddy:What's up?

Happy&Optimistic&Effective

BlogJava 首页 新随笔 联系 聚合 管理
  14 Posts :: 1 Stories :: 0 Comments :: 0 Trackbacks

#

Embedded HTML

Javadoc passes HTML commands through to the generated HTML document. This allows you full use of HTML; however, the primary motive is to let you format code, such as: Feedback

/**
* <pre>
* System.out.println(new Date());
* </pre>
*/


You can also use HTML just as you would in any other Web document to format the regular text in your descriptions: Feedback

/**
* You can <em>even</em> insert a list:
* <ol>
* <li> Item one
* <li> Item two
* <li> Item three
* </ol>
*/


Note that within the documentation comment, asterisks at the beginning of a line are thrown away by javadoc, along with leading spaces. Javadoc reformats everything so that it conforms to the standard documentation appearance. Don’t use headings such as <h1> or <hr> as embedded HTML, because javadoc inserts its own headings and yours will interfere with them. Feedback

All types of comment documentation—class, variable, and method—can support embedded HTML. Feedback

Some example tags

Here are some of the javadoc tags available for code documentation. Before trying to do anything serious using javadoc, you should consult the javadoc reference in the downloadable JDK documentation to get full coverage of the way to use javadoc. Feedback

@see: referring to other classes

The @see tag allows you to refer to the documentation in other classes. Javadoc will generate HTML with the @see tags hyperlinked to the other documentation. The forms are: Feedback

@see classname
@see fully-qualified-classname
@see fully-qualified-classname#method-name


Each one adds a hyperlinked “See Also” entry to the generated documentation. Javadoc will not check the hyperlinks you give it to make sure they are valid. Feedback

{@link package.class#member label}

Very similar to @see, except that it can be used inline and uses the label as the hyperlink text rather than “See Also.”

{@docRoot}

Produces the relative path to the documentation root directory. Useful for explicit hyperlinking to pages in the documentation tree.

{@inheritDoc} 

Inherits the documentation from the nearest base class of this class into the current doc comment.

@version

This is of the form:

@version version-information


in which version-information is any significant information you see fit to include. When the -version flag is placed on the javadoc command line, the version information will be called out specially in the generated HTML documentation. Feedback

@author

This is of the form:

@author author-information


in which author-information is, presumably, your name, but it could also include your email address or any other appropriate information. When the -author flag is placed on the javadoc command line, the author information will be called out specially in the generated HTML documentation. Feedback

You can have multiple author tags for a list of authors, but they must be placed consecutively. All the author information will be lumped together into a single paragraph in the generated HTML. Feedback

@since

This tag allows you to indicate the version of this code that began using a particular feature. You’ll see it appearing in the HTML Java documentation to indicate what version of the JDK is used. Feedback

@param

This is used for method documentation, and is of the form:

@param parameter-name description


in which parameter-name is the identifier in the method parameter list, and description is text that can continue on subsequent lines. The description is considered finished when a new documentation tag is encountered. You can have any number of these, presumably one for each parameter. Feedback

@return

This is used for method documentation, and looks like this:

@return description


in which description gives you the meaning of the return value. It can continue on subsequent lines. Feedback

@throws

Exceptions will be demonstrated in Chapter 9. Briefly, they are objects that can be “thrown” out of a method if that method fails. Although only one exception object can emerge when you call a method, a particular method might produce any number of different types of exceptions, all of which need descriptions. So the form for the exception tag is:

@throws fully-qualified-class-name description


in which fully-qualified-class-name gives an unambiguous name of an exception class that’s defined somewhere, and description (which can continue on subsequent lines) tells you why this particular type of exception can emerge from the method call. Feedback

@deprecated

This is used to indicate features that were superseded by an improved feature. The deprecated tag is a suggestion that you no longer use this particular feature, since sometime in the future it is likely to be removed. A method that is marked @deprecated causes the compiler to issue a warning if it is used. Feedback

Documentation example

Here is the first Java program again, this time with documentation comments added:

//: c02:HelloDate.java
import java.util.*;

/** The first Thinking in Java example program.
 * Displays a string and today's date.
 * @author Bruce Eckel
 * @author www.BruceEckel.com
 * @version 2.0
*/
public class HelloDate {
  /** Sole entry point to class & application
   * @param args array of string arguments
   * @return No return value
   * @exception exceptions No exceptions thrown
  */
  public static void main(String[] args) {
    System.out.println("Hello, it's: ");
    System.out.println(new Date());
  }
} ///:~
posted @ 2005-07-07 10:01 Kun Tao's Blog 阅读(222) | 评论 (0)编辑 收藏

 //author: Tao Sun
要对一格字符串分割,本来可以用split,但是要指定多个分割字符的话就要用StringTokenizer了.下面是个简单的程序测试,分别用汉字逗号和英文逗号分割字符串.

String abc = new String("因子1,因子2,因子3");
       try {
      StringTokenizer tokenizer = new StringTokenizer(abc, ",,");//can add more in the delim
      while (tokenizer.hasMoreTokens()) {
        String yz= tokenizer.nextToken();
        System.out.println("result: " + yz);
      }
    }
    catch (Exception ee) {
      System.out.println(ee.toString());
    }
posted @ 2005-06-04 10:58 Kun Tao's Blog 阅读(232) | 评论 (0)编辑 收藏

最近一直在做java数据库操作的applicaitons,今天抽时间整理了一下,有些比较粗糙,实在是太忙了,所以整理的有点仓促,一些注释也没有来的及加上,有问题请和我联系,我会不断改进。愿与各位交流,共同提高。转载请注明作者信息以及出处。谢谢。mail:suntao2000st@ustc.edu

//DbOperation Source Code:
/**
 * Title:Database basic Operation
 * Description:This program intends to deal with basic database operation includes
 * querying,updating,inserting and creating table,also user can get table
 * column names and existed tables in specific database.
 * Copyright:Copyright (c) 2005
 * @author:Tao Sun (<a href="mailto:suntao2000st@ustc.edu">Tao Sun</a>)
 * @version:1.0
 */

import java.sql.*;

public class DbOperation {
  private String databaseName;
  private String operationException;
  private String password;
  private String userName;
  private int columnCount;

  /**
      @roseuid 429FF7C10280
   */
  public DbOperation() {
    databaseName = new String();
    operationException = new String();
    password = new String();
    userName = new String();
  }

  /**
      @param password
      @roseuid 429FAC3002CE
   */
  public void setPassword(String password) {
    this.password = password;
  }

  /**
      @param userName
      @roseuid 429FAC3C00EA
   */
  public void setUserName(String userName) {
    this.userName = userName;
  }

  /**
      @param databaseName
      @roseuid 429FF3BC0138
   */
  public void setDatabaseName(String databaseName) {
    this.databaseName = databaseName;
  }

  /**
      @return java.lang.String
      @roseuid 429FF3D901F4
   */
  public String getOperationException() {
    return operationException;
  }

  /**
        @return int
   */
  public int getTableColumnCount() {
    return columnCount;
  }

  /**
      @return java.lang.String[]
      @roseuid 429FAB1503B9
   */
  public String[] queryDbExistedTableNames() {
    String[] dbExistedTableNames = null;
    try {
      Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
      String url =
          "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=" +
          databaseName;
      Connection con = DriverManager.getConnection(url, userName, password);
      Statement passt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                                            ResultSet.CONCUR_UPDATABLE);
      DatabaseMetaData databaseMetaData = con.getMetaData();
      String[] types = new String[1];
      types[0] = "TABLE";
      //return tables that are available for users
      ResultSet tableResult = databaseMetaData.getTables(null, null, "%",
          types);
      int numCols = 0;
      while (tableResult.next()) {
        ++numCols;
      }
      dbExistedTableNames = new String[numCols];
      tableResult.first();
      int ii = 0;
      do {
        dbExistedTableNames[ii] = tableResult.getString("TABLE_NAME");
        ++ii;
      }
      while (tableResult.next());
      tableResult.close();
      con.close();
      operationException = new String("Get db existed tablename successfully!");
    }
    catch (SQLException ex) {
      operationException = new String(ex.toString());
    }
    catch (Exception ex) {
      operationException = new String(ex.toString());
    }
    return dbExistedTableNames;
  }

  /**
      @param tableName
      @return java.lang.String[][]
      @roseuid 429FAB460167
   */
  public String[][] queryTableData(String tableName) {
    String[][] tableData = null;
    try {
      Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
      String url =
          "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=" +
          databaseName;
      String pas = "select * from " + tableName;
      Connection conn = DriverManager.getConnection(url, userName, password);
      Statement passt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                                             ResultSet.CONCUR_UPDATABLE);
      ResultSet resultset = passt.executeQuery(pas); //return result set
      ResultSetMetaData rsmd = resultset.getMetaData();
      columnCount = rsmd.getColumnCount();
      int row = 0;
      while (resultset.next()) {
        row++;
      }
      tableData = new String[row][columnCount];
      resultset.first();
      int j = 0;
      do {
        for (int i = 1; i <= columnCount; i++) {
          tableData[j][i - 1] = resultset.getString(i);
        }
        j++;
      }
      while (resultset.next());
      passt.close();
      conn.close();
      operationException = new String("get data success!");
    }
    catch (SQLException ex) {
      operationException = new String(ex.toString());
    }
    catch (Exception e) {
      operationException = new String(e.toString());
    }
    return tableData;
  }

  /**
      @param tableName
      @return java.lang.String[]
      @roseuid 429FAB5301E4
   */
  public String[] queryTableColumnNames(String tableName) {
    String[] tableColumnNames = null;
    try {
      Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
      String url =
          "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=" +
          databaseName;
      String pas = "select * from " + tableName;
      Connection conn = DriverManager.getConnection(url, userName, password);
      //execute the sql statement
      Statement passt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                                             ResultSet.CONCUR_UPDATABLE);
      ResultSet resultset = passt.executeQuery(pas); //return result set
      ResultSetMetaData rsmd = resultset.getMetaData();
      int columnCount = rsmd.getColumnCount();
      tableColumnNames = new String[columnCount];
      for (int i = 1; i <= columnCount; i++) {
        tableColumnNames[i - 1] = rsmd.getColumnName(i);
      }
      passt.close();
      conn.close();
      operationException = new String(
          "Get " + tableName + "column name successfully!");
    }
    catch (SQLException ex) {
      operationException = new String(ex.toString());
    }
    catch (Exception e) {
      operationException = new String(e.toString());
    }
    return tableColumnNames;
  }

  /**
      @param tableName
      @param columnNames using default types char(100)
      @throws java.sql.SQLException
      @roseuid 429FAB930186
   */
  public void createTable(String tableName, String[] columnNames) {
    String columnNameString = new String();
    for (int i = 0; i < columnNames.length; i++) {
      if (i == columnNames.length - 1) {
        columnNameString += columnNames[i] + " char(100)";
      }
      else {
        columnNameString += columnNames[i] + " char(100),";
      }
    }
    try {
      Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
      String url =
          "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=" +
          databaseName;
      String pas = "CREATE TABLE " + tableName + "(" + columnNameString + ");";
      Connection conn = DriverManager.getConnection(url, userName, password);
      //execute the sql statement
      Statement passt = conn.createStatement();
      passt.execute(pas); //
      //close the connection and data workspace
      passt.close();
      conn.close();
      operationException = new String("Create table:" + tableName +
                                      "successfully!");
    }
    catch (SQLException ex) {
      operationException = new String(ex.toString());
    }
    catch (Exception e) {
      operationException = new String(e.toString());
    }
  }

//delete data from specific table
public void delData(String tableName)
{
 try {
      Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
      String url =
          "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName="+databaseName;
      String pas = "delete from "+tableName+"where x=45 and z=45";
      Connection conn = DriverManager.getConnection(url, user, password);
      //execute the sql statement
     Statement passt = conn.createStatement();
      passt.executeUpdate(pas); //return result set
      passt.close();
      conn.close();
      System.out.println("delete data success!") ;
    }
    catch (SQLException ex) {
      System.out.println(ex.toString());
    }
    catch (Exception e) {
      System.out.println(e.toString());
    }
}
  /**
      @param tableName
      @param insertColumnNames
      @param insertValues
      @throws java.sql.SQLException
      @roseuid 429FF45402EE
   */
  public void insertTableValues(String tableName, String[] insertColumnNames,
                                String[] insertValues) {
    if (insertColumnNames.length > insertValues.length) {
      System.out.println("Not enough values for columns!");
    }
    else if (insertColumnNames.length < insertValues.length) {
      System.out.println("Not enough columns to receive values!");
    }
    else {
      String columnString = new String();
      String valueString = new String();
      for (int i = 0; i < insertColumnNames.length; i++) {
        if (i == insertColumnNames.length - 1) {
          columnString += insertColumnNames[i];
          valueString += "'" + insertValues[i] + "'";
        }
        columnString += insertColumnNames[i] + ",";
        valueString += "'" + insertValues[i] + "',";
      }
      try {
        Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").
            newInstance();
        String url =
            "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=" +
            databaseName;
        String pas = "insert into userselect(" + columnString + ")values(" +
            valueString + ");";
        Connection conn = DriverManager.getConnection(url, userName, password);
        //execute the sql statement
        Statement passt = conn.createStatement();
        passt.executeUpdate(pas); //
        //close the connection and data workspace
        passt.close();
        conn.close();
        operationException = new String("Insert table values successfully!");
      }
      catch (SQLException ex) {
        operationException = new String(ex.toString());
      }
      catch (Exception e) {
        operationException = new String(e.toString());
      }

    }
  }

}

//The Test Code:

public class Application {
  DbOperation dbo = new DbOperation();
  String[] bdExistedTabelNames = null;
  String[] createColumnNames;
  String[] tableColumnNames = null;
  String[][] tableData = null;

  public Application() {
    createColumnNames = new String[] {
        "a", "b", "c", "d"};
    test();
  }

  public void test() {
    dbo.setDatabaseName("pestforecast");
    dbo.setUserName("crop");
    dbo.setPassword("crop");

    /**
     * Test to create table
     */
    //   dbo.createTable("test",createColumnNames);
    //   System.out.println(dbo.getOperationException());

    /**
     * Test to get database existed table names
     */
    bdExistedTabelNames = dbo.queryDbExistedTableNames();
    System.out.println(dbo.getOperationException());
    for (int i = 0; i < bdExistedTabelNames.length; i++) {
      System.out.println(bdExistedTabelNames[i]);
    }

    /**
     * Test to get specific table column names
     */
    tableColumnNames = dbo.queryTableColumnNames("historydata");
    System.out.println(dbo.getOperationException());
    for (int i = 0; i < tableColumnNames.length; i++) {
      System.out.println(tableColumnNames[i]);
    }

    /**
     * Test to get specific table data
     */

    tableData = dbo.queryTableData("historydata");
    System.out.println(dbo.getOperationException());
    for (int i = 0; i < tableData.length; i++) {
      for (int j = 0; j < dbo.getTableColumnCount(); j++) {
        System.out.print(tableData[i][j] + " ");
      }
      System.out.println();
    }

    /**
     * Test to insert table values
     */
    int n = tableColumnNames.length;
    String[] inputValue = new String[n];
    for (int i = 0; i < n; i++) {
      inputValue[i] = "test" + i;
    }
    dbo.insertTableValues("historydata", tableColumnNames, inputValue);
    System.out.println(dbo.getOperationException());
  }

  public static void main(String[] args) {
    new Application();
  }

}

posted @ 2005-06-03 17:41 Kun Tao's Blog 阅读(542) | 评论 (0)编辑 收藏

These days, the boss asks me to have a look at the GP programming. Though busy now, I try to write something about the plans, the structures, the program flow and UML,etc. In my mind, a good plan is worth codes of several days.

The problem discription: Function set F={+,-,*,/,sin,cos}

Terminal set T=(x,y,z...)where the numbers are not set but can get from other place eg. database tables(such as column names)
The parameters set below:
Population size of 5000 individuals, number of generation is 1000, ramped half-and-half initialization, tournament selection of size 10, crossover rate equal to 95%, mutation rate equal to 0.1%,maximum tree depth for the initialization phase equal to 4, maximum depth for the crossover and mutation phases equal to 50.

Goal of function:
Automatically find the model from existed data sets and give the fitness curve.

So, my organization is divided into several steps:
First: understand fully the process of GP(especially the characters that will be used,eg.Adjucted Fitness, Encoding...)
Second:Java coding(effective and reusable with better UML figrues)
Third: later will be added...Let me have a rest, It is a long time since I last saw the web news....
Have a good time,every one.


 

posted @ 2005-05-26 15:38 Kun Tao's Blog 阅读(138) | 评论 (0)编辑 收藏

仅列出标题
共2页: 上一页 1 2