Monday 23 April 2012

How to create javadoc for Java Application?



To create java documentation, we need to write documentation command while writting code itself.

Documentation command look like this,
/**
 *
 * Description of Packagae / Class / Method / Variables
 */

If we wrote like this, then we can easily generate Java Api for our Application.

Example:

package javaexamples;


/**
 *
 * @author uma
 */
/**
 *
 * This class implements usage of toString in java.
 * If we override this toString(), then when ever we print this class's object,
 * It will display all information about that object
 * what ever we defined in this toString() method
 */
public class Student {


    /**
     * id is an unique key to identify Student
     */
    private int id;
    /**
     * name of the Student
     */
    private String name;


    /**
     * Student constructor initialize id and name of the Student
     */
    public Student(int id, String name) {
        this.id = id;
        this.name = name;
    }


    /**
     * The toString() will display Student class 's object information
     */
    public String toString() {
        return "Id :" + id + " Name :" + name;
    }
}



To create Javadoc, need to run this commmand or use 'Generate javadoc' option in netbeans.

javadoc [ option ] package_name 

[ To know about all options, use javadoc command. It will list all options ]

From above example,

javadoc -private javaexamples

This will give complete javadoc in html file. Once, we open this index.html in browser, It will show all details.



Where we can use NULL in mysql?


Where we can use NULL in mysql?

Normally, In java, null means nothing. Like that, In mysql, We can use NULL.

While try to insert null in mysql table, then we should not use single quotes while insert null in table. If we use single quote for null, then I will take that as a String.

If we add null, then it automatically added NULL in table.


Example,

create table sample(id integer(20) default NULL, name varchar(60) default NULL);

+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(20)     | YES  |     | NULL    |       |
| name  | varchar(60) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+

insert into sample values(1, null);
1 row in set (0.02 sec)

select * from sample;

+------+------+
| id   | name |
+------+------+
|    1 | NULL |
+------+------+

insert into sample values(NULL, 'Uma');
1 row in set (0.02 sec)

select * from sample;

+------+------+
| id   | name |
+------+------+
|    1 | NULL |
| NULL | Uma  |
+------+------+

insert into sample values(3, 'Vidhya');
1 row in set (0.02 sec)

select * from sample;

+------+--------+
| id   | name   |
+------+--------+
|    1 | NULL   |
| NULL | Uma    |
|    3 | Vidhya |
+------+--------+


-> We can check NULL as follows,

select * from sample where name is Not NULL;

+------+--------+
| id   | name   |
+------+--------+
| NULL | Uma    |
|    3 | Vidhya |
+------+--------+


select * from sample where name is NULL;
+------+------+
| id   | name |
+------+------+
|    1 | NULL |
+------+------+



More Info :

http://dev.mysql.com/doc/refman/5.0/en/problems-with-null.html

http://stackoverflow.com/questions/3059805/difference-between-mysql-is-not-null-and