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


Tuesday, 3 January 2012

Flex basics


-> we can use two languages to write Flex applications: MXML and ActionScript.

-> MXML is an XML markup language that you use to lay out user interface components.

-> Like HTML, MXML provides tags that define user interfaces. MXML will seem very familiar if you have worked with HTML.

-> MXML is more structured than HTML, and it provides a much richer tag set.

-> One of the biggest differences between MXML and HTML is that MXML-defined applications are compiled into SWF files and rendered by Adobe® Flash® Player or Adobe® AIR™, which provides a richer and more dynamic user interface than page-based HTML applications.


Simple Flex Application :

<?xml version="1.0"?>
<!-- mxml\HellowWorld.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Panel title="My Application" 
        paddingTop="10" 
        paddingBottom="10"
        paddingLeft="10" 
        paddingRight="10"
    >
        <mx:Label text="Hello World!" fontWeight="bold" fontSize="24"/>
    </mx:Panel>
</mx:Application>


Why using UTF-8 in encoding format :

-> UTF-8 provides a unique number for every character in a file, and it is platform-, program-, and language-independent.


<mx:Application> tag :

-> It  represents a Application container.

-> A container is a user-interface component that contains other components and has built-in layout rules for positioning its child components.

-> By default, an Application container lays out its children vertically from top to bottom


The MXML properties :

-> We can configure initial state of an component using mxml properties. And We can change this properties using Actionscript at run time.


Relationship of MXML tags to Actionscript classes :

-> Adobe implemented Flex as an ActionScript class library. That class library contains components (containers and controls), manager classes, data-service classes, and classes for all other features.

-> MXML tags correspond to ActionScript classes or properties of classes. Flex parses MXML tags and compiles a SWF file that contains the corresponding ActionScript objects.

For example,

<mx:Button label="Submit"/>

-> When you declare a control using an MXML tag, you create an instance object of that class. This MXML statement creates a Button object, and initializes the label property of the Button object to the string "Submit".

Monday, 28 November 2011

Java with mysql


1. To connect java into database, we need some driver to connect. I have used jdbc driver.

2. In java.sql package contain DriverManager class, it handles driver.

3. After this driver successfully connected to data base, it returns connection object.

   DriverManager.getConnection(String databaseUrl, String username, String password);

   datbaseUrl  -   Url which represents database connection

                   Example, jdbc:mysql://localhost:3306/Uma

                   Uma - Data base name

   username   -    username of the mysql

   password   -    Password of the mysql


4.  Use this connection object, we can create a statement for executing mysql queries.

    Statement st = Conn_object.createStatement()  -   create a statement with out any specification

    [ We can create statement with some specification like resultset scrollable, etc ]


5. statement class contains methods to run queries. We can get the query result using ResultSet.

  
   ResultSet rs = st.exceuteQuery(String query)  -   Simply returns the result, not update in datbase

                  st.updateQuery(String query)   -   Update the query result into database



Some methods in ResultSet :

    We can get values from ResultSet using some methods in ResultSet.


1. To get the column value using getXXX()

   Here XXX is the column data type like getInt(), getString()

2. To check wheather or not a column is null, using wasNull()

      if (rs.wasNull()) {
          // resultset contains null value
      }

3.  Use JDBC operation inside try block and catch the exception which is thrown. TO get more details about exception,

JDBC provides some methods,  e.getMessage(), e.getErrorCode()

    catch (Exception e) {
        // print error message using  e.getMessage()
        // print error number using e.getErrorCode()   
    }


More Info :

http://www.kitebird.com/articles/jdbc.html

Difference between JDK, JRE and JVM

JDK:

1. Java development kit contains tools for developing java programs such as compiler (javac.exe) whihc converts source code inro byte code,
Interpreter, Java Application launcher (java.exe) which converts byte coe into mechine code.


JRE :

1. Java Runtime Environment contains JVM, class libraries and other supported files. It does not contain any developer tools such as compiler, interpreter. Actually JVM runs the program using library files and other supported files that are provided by JRE.

JVM :

1. JVM is in both JRE and JDK.

2. JVM runs the java program using library files in jre.

3. JVM interpretes the byte code into machine code.

4. JVM is called "virtual" because it creates machine interface which does not depend on underlying operatiog system and machine hardware architecture.

[ JVM interpretes byte code into machine code which does not depend on underlying operating system ]



-

Wednesday, 16 November 2011

Enhanced for loop

Enhanced for loop:

1. This new feature added in Java1.5

2. Also callied as "for each loop".

3. It allows as to iterate through collection without having to create a iterator or without having to calculate beginning and end conditions for counter variable.

For example, 

In normal for loop,

class sample {
    public static void main(String args) {
        int[] var = {1, 9, 18, 27 };
        for( int i = 0; i < var.length; i++) {
            System.out.println("values :" +var[i]);
        }
    }
}
       
For each loop,

class sample {
    public static void main(String args) {
        int[] var = {1, 9, 18, 27 };
        for( int i : var) {
            System.out.println("values :" +var[i]);
        }
    }
}

Here, no need to check var length. Its easy to adapt for loop to for each loop.


But, It contains some disadvantages, follows

1. for each loop iterate only sequencialy. cant get first and third value using for each. [ Step value can not be incremented ]

2. Backward traversal is not possible.



Reference :

http://www.javabeat.net/articles/32-new-features-in-java-50-1.html

Wednesday, 9 November 2011

Flex Basics

Flex basics:

Use of Name space in mxml :

1. To specify language version

2. To provide scope for mapping XML tag name to ActionScipt class name or CSS style tag to ActionScript class name

3. And provide details to compiler, where local sources located for custom component.


Name space :

1. Flex 2 and 3 -> MXML 2006  which contains language version and mapping for flex framework component

2. In Gumbo, new language features are added and updated to MXML 2009 [ xmlns:fx="http://ns.adobe.com/mxml/2009" ]

3. Components are described in their own namespaces,

    -> Flex 3 or MX components are in mxml library namespace. [ xmlns:mx="library://ns.adobe.com/flex/mx" ]

    -> New Gumbo spark components are in spark component name space. [ xmlns:s="library://ns.adobe.com/flex/spark" ]


For flex 3,

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://ns.adobe.com/mxml/2006">


For flex 4, Gumbo spark component,

<?xml verison="1.0" encoding="utf-8"?>

<s:Applicaiton xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx">


                                                                                - will continue in next post..