Thursday, December 31, 2009

How to Display Programming Code in Your blog

If you are giving some programming tips in your blogs means you will give sample programs related that article.but if copy and paste sample code from some another location or you will type that


              Most of the time your code won’t display in correct format.if you facing this problem this article will help you.















Select the programs and Click Quote button in the blogger toolbar.


Friday, December 25, 2009

Free Blog Templates

Choosing right blog template is important before start blogging,there are lot of blog templates available in number of we can find few best free blogger & wordpress templates sites.
Lot of free blog templates are available in above url. even you don’t want to do more customization.
We can download lot of free beautiful wordpress themes from the below url.
Simple and more powerful default blogger customized templates are available in the below location.
Most popular minima & rounder's templates are available here.

Thursday, December 24, 2009

Swing Invokelater Example

Here we can see How to write a responsive User interfaces using Swing.
Most post-initialization GUI work naturally occurs in the event-dispatching thread. Once the GUI is visible, most programs are driven by events such as button actions or mouse clicks, which are always handled in the event-dispatching thread. A program that uses separate worker threads to perform GUI-related processing can use invokelater and invokeandwait methods to cause a Runnable object to be run on the event-dispatching thread. 

Tuesday, December 22, 2009

Madras University Results

Some useful links for university results.
Madras University Results, Madras University DDE Results, Madurai Kamaraj University Results, Anna University,Annamalai University Results, Manonmaniam Sundaranar University Results.
IDE-ALL-PG and M.B.A Revaluation Results of June 2009.
check the below link.

How to Execute Shell Script From Java

Here is an example shows how to execute the shell scripts from java programs.

If you want to execute the below program set the java path in Unix environment.

export PATH=$PATH:/usr/jdk1.5.0/bin

export CLASSPATH=$CLASSPATH:/usr/jdk1.5.0/bin

create a shell script like

echo "Good morning, world."


then change the permission for this script.if you execute the shell script you need execute permission.

chmod 777



From java program


public class JavaScript {

public static void main(String[] args) {

         try {


                System.out.println("Working Fine");

              } catch (IOException e) {





Sunday, December 20, 2009

Blog Templates

Blog templates are important for blog to become more popular.For new blogger, they usually start blogging from existing templates available in the blogger or wordpress.

Before you start blogging choose the right template for your blog topic and blog intention.if you like to earn something from blog(using adsense or other ads) means choosing right template is more important,otherwise if you chose a template and started writing about something and later you planning to change means you may lose some widgets or scripts.

There are lot of customized templates are available for BlogSpot and wordpress.

3 column templates are most popular design templates,especially minima series and 3 column rounder series are commonly used blog templates.





above templates are well suits for adsense also.

After template selection add some featured widgets for your blog it will useful for you.

wowzio live activity feed widgets and more widgets are available in


related post

or you can use feedjit live widjet.

and add some more suitable widgets for your blog and customize your template as you wish.

Saturday, December 19, 2009

Java Date Format

Below examples explains how to do date format using SimpleDateFormat and how to convert string to date in java.
SimpleDateFormat Example
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateFormatExample {
    public static void main(String args[]) {
        Date date = new Date();
        String DATE_FORMAT = "MM:dd:yyyy";
        // or
        // String DATE_FORMAT = "MM/dd/yyyy";
        SimpleDateFormat simDateFormat = new SimpleDateFormat(DATE_FORMAT);
        System.out.println("Today is " + simDateFormat.format(date));
        // or If you want display time with AM/PM
        String TIME_FORMAT = "HH:mm:ss a";
        SimpleDateFormat timeFormat = new SimpleDateFormat(TIME_FORMAT);
        System.out.println("Now time is " + timeFormat.format(date));
        // Today date and Time
        System.out.println("Date and time is " + simDateFormat.format(date)
                + " " + timeFormat.format(date));
Convert String to Date

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class StrToDate {
    public static void main(String[] args) {
        String stri = "18/12/2009";
        DateFormat simDateForm = new SimpleDateFormat("dd/MM/yyyy");
        Date dstr;
        try {
            dstr = (Date) simDateForm.parse(stri);
            System.out.println("Date is" + dstr);
        } catch (ParseException e) {
            // TODO Auto-generated catch block

Thursday, December 17, 2009

Google Chrome Extensions

Google Chrome Extensions

Add new features to google chrome by adding extensions (beta). But these features are useful for some people, but not for all.

Extensions currently available for Windows and Linux.

Most Popular Features

1.Google Mail Checker

It is displays the number of unread messages in your Google Mail inbox.

2. AdThwart

we can blocks ads on websites using this feature.


Dotspots is an annotation service.It is also useful for blogger.

You can connect blog posts, links, photos, videos and docs to any text on the web or into your social stream for all to see.

You can add these extensions by clicking bottom right corner of your google chrome browser.

4.Google Translate

5.Google Wave Notifier

Add the above the extensions and make your google chrome browser as more powerful.

Java Usb Communication

Like a serial port we can communicate with USB from java application
Each USB port on a computer is assigned a unique identification number (port ID) by the USB controller. When a USB device is attached to a USB port, this unique port ID is assigned to the device.
Communication on the USB network can use any one of four different data transfer types:

  • Control transfers: These are short data packets for device control and configuration, particularly at attach time.
  • Bulk transfers: These are data packets in relatively large quantities. Devices like scanners or SCSI adapters use this transfer type.
  • Interrupt transfers: These are data packets that are polled periodically. The host controller will automatically post an interrupt at a specified interval.
  • Isochronous transfers: These are data streams in real time with higher requirements for bandwidth than for reliability. Audio and video devices generally use this transfer type. 
JUSB is a Java API for java and USB communication.
JSR80 API for java USB communication
Download the above api from the following location.
LibusbJava is a Java wrapper for the libusb 0.1 and libusb-win32 USB library.
Download the library from the following location

Monday, December 14, 2009

Java Look and Feel

We can modify the look and feel of java GUI components,Here is an example used to implement the look and feel concepts in java programs.

Using below code we can set the operating systems look and feel.


import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class LookAndFeel {
    public static void main(String[] args) {
        try {
            // UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (Exception ex) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {

            private void createTheGUIComponents() {
                // Your implementation here…

We can also set the lot of GUI skins using substance.jar.

Download the latest substance.jar using below link

Add the above jar file in java classpath.

Wednesday, December 9, 2009

Java GUI Hanging Issue

The problem shall be because of the following reasons.

  • Not using of Event Dispatching Thread (EDT) properly for the events triggered from the operator.
  • Usually event dispatching thread should not contain the long running operations.
  • And unwanted usage of threads which leads to high CPU usage some times might leads to hang USM.
  • Unused objects are not set for garbage collection.Which leads to high heap usage and throws OutofMemory exception.
  • Unnecessary usage of Collection classes leads to heap memory occupation.
  • Critical operations if not synchronized may lead to deadlock and resulting the Java UI to hang.
  • And costly operation like Cell Renderer used for the JTables, which will be triggered to paint the GUI very frequently which takes the EDT thread. So that Java UI will hang most very often.
  • And also when the NEs are dragged and dropped to the working view the getValueAt() method will be called for each cell of the JTable. So this again takes significant amount of time in painting the value at each cell of the JTable. So this leads to block the Java GUI.


The problem can be solved by removing unwanted usage of Collection classes (Vector, Hashtable etc…) and avoiding usage of loops in the run method of threads which leads to high CPU usage.

Monday, December 7, 2009

Database Front End Applications

1. HeidiSQL

HeidiSQL is an user friendly and open source tool for popular MYSQL Database. It is used to handle and browse your databases and tables from an Windows interface.

You can get this tool in the following location.

Download Location



 HeidiSQL Features

  • It is used to generate SQL -Exports
  • It also synchronize tables between two databases
  • It will export table data as CSV,XML,
  • We can create and edit stored procedures also.


Toad is a another very good tool available for all the databases like Oracle,SQL server,DB2,My SQL.

Toad is a fast and easier tool and it has lot of features.


3.Oracle SQL Developer

Oracle SQL Developer is a free and graphical tool for database development.

  • Using SQL Developer we can run SQL statements and SQL scripts, and
  • We can edit and debug PL/SQL statements using this tool.
  • We can also run any number of reports, as well as create and save your own.

Friday, December 4, 2009

How To Set Environment Variable In Java

Environment variables are used to run the java programs from any location.
For Windows Vista
Right Click Computer -------> Properties -------->Advanced system settings ----------> Click Environmental variables
Goto System variables section --------> Click New

  variable name -----> PATH
  variable value ---------> C:\Program Files\Java\jdk1.6.0_12\bin(Your java path)
then goto command prompt
Type javac
Method 2:
  If you don’t want to set environmental variable
You can also set  java path for current location using following commands
got to DOS Prompt
   set PATH=%PATH%;C:\Program Files\Java\jdk1.6.0_12\bin
   set CLASSPATH=%CLASSPATH%;C:\Program Files\Java\jdk1.6.0_12\bin
( . indicates current path )

Wednesday, December 2, 2009

Java Native Interface

Here is an example for Java Native Interface
Java application that calls a C function and executes the operation.
Ping program
           Write a java program for ping operation.
import java.util.StringTokenizer;

public class PINGMain {

String ipaddress = null;

boolean defragment = false;

int num = 2;

String str = "";

String success ="success";

String[] ipaddr = { "", "20", "2000", "5000", "500" };

private String destination;

private String packetSize;

private String bytes;

private String time;

        private String ttl;

protected native String ping(String[] ipaddress);

public PINGMain() {


try {


} catch (UnsatisfiedLinkError e) {





private void singlePing() {

int a = 10;

int b = 20;

String string=null;

while(true) {

string = ping(ipaddr);


StringTokenizer strToken = new StringTokenizer(string);

int numToken = strToken.countTokens();

            destination =   strToken.nextToken();

            bytes = strToken.nextToken();

            time=       strToken.nextToken();

            ttl = strToken.nextToken();

System.out.println("\n Reply from"+" "+destination+" "+"bytes"+" "+bytes+" "+"Time"+" "+time+" "+"TTL"+" "+ttl);



private String continuousPing() {

return null;


private String disconnect() {


//System.out.println("Unloaded SuccessFully");

return success;


private void unLoadPing() {

// unLoad();



* @return


private String getStatistics() {

return null;


public static void main(String ar[]) {

new PINGMain();




Step 2:

   Using javac to compile the PINGMain source file

After you have defined the PINGMain class, save the source code in a file called PINGMain .java. Then compile the source file using the javac compiler as follows:

This command will generate a PINGMain.class file in the current directory.

Step 3:

Using javah -jni to generate a C header file (PINGMain.h) containing the function prototype for the native method implementation

Next we will use the javah tool to generate a JNI-style header file that is useful when implementing the native method in C. You can run javah on the PINGMain class as follows:

  • javah -jni PINGMain

    The command shown above generates a file named PINGMain.h.

  • Step 4:

    Writing the C implementation (PINGMain.c) of the native method

    The JNI-style header file generated by javah helps you to write C or C++ implementations for the native method. The function that you write must follow the -prototype specified in the generated header file.

    #pragma comment(lib, "wsock32.lib")

    #include "jni.h"

    #include "com_dtt_traffic_ping_PINGMain.h"

    #include "stdlib.h"

    #include "StdAfx.h"

    #include <windows.h>

    #include <winsock.h>

    #include <stdio.h>

    #include <string.h>

    int packetsize;

    int count;

    char *data;//Ping info

    typedef struct tagIPINFO


            u_char Ttl;                             // Time To Live

            u_char Tos;                             // Type Of Service

            u_char IPFlags;                 // IP flags

            u_char OptSize;                 // Size of options data

            u_char FAR *Options;    // Options data buffer


    typedef struct tagICMPECHO


            u_long Source;                  // Source address

            u_long Status;                  // IP status

            u_long RTTime;                  // Round trip time in milliseconds

            u_short DataSize;               // Reply data size

            u_short Reserved;               // Unknown

            void FAR *pData;                // Reply data buffer

            IPINFO  ipInfo;                 // Reply options


    // ICMP.DLL Export Function Pointers

    HANDLE (WINAPI *pIcmpCreateFile)(VOID);

    BOOL (WINAPI *pIcmpCloseHandle)(HANDLE);

    DWORD (WINAPI *pIcmpSendEcho)




    char *pingFun(char *dest[])


        int timeout;

        char ping_Resp[2048];

            WSADATA wsaData;                        // WSADATA

            ICMPECHO icmpEcho;                      // ICMP Echo reply buffer

            HANDLE hndlIcmp;                        // LoadLibrary() handle to ICMP.DLL

            HANDLE hndlFile;                        // Handle for IcmpCreateFile()

            LPHOSTENT pHost;                    // Pointer to host entry structure

            struct in_addr iaDest;              // Internet address structure

            DWORD *dwAddress;                       // IP Address

            IPINFO ipInfo;                          // IP Options structure

            int nRet;                                       // General use return code

            DWORD dwRet;                            // DWORD return code

            int x;

           packetsize = atoi(dest[2]);

            count = atoi(dest[5]);

            timeout = atoi(dest[4]);

            // Dynamically load the ICMP.DLL

            hndlIcmp = LoadLibrary("ICMP.DLL");

            if (hndlIcmp == NULL)


                    fprintf(stderr,"nCould not load ICMP.DLLn");



            // Retrieve ICMP function pointers

            pIcmpCreateFile = (HANDLE (WINAPI *)(void))


            pIcmpCloseHandle = (BOOL (WINAPI *)(HANDLE))


            pIcmpSendEcho = (DWORD (WINAPI *)



            // Check all the function pointers

            if (pIcmpCreateFile == NULL             ||

                    pIcmpCloseHandle == NULL        ||

                    pIcmpSendEcho == NULL)


                    fprintf(stderr,"nError getting ICMP proc addressn");




            // Init WinSock

            nRet = WSAStartup(0x0101, &wsaData );

        if (nRet)


            fprintf(stderr,"nWSAStartup() error: %dn", nRet);





        // Check WinSock version

        if (0x0101 != wsaData.wVersion)


            fprintf(stderr,"nWinSock version 1.1 not supportedn");





            // Lookup destination

        // Use inet_addr() to determine if we're dealing with a name

        // or an address

        iaDest.s_addr = inet_addr(dest[1]);

        if (iaDest.s_addr == INADDR_NONE)

            pHost = gethostbyname(dest[1]);


            pHost = gethostbyaddr((const char *)&iaDest,

                            sizeof(struct in_addr), AF_INET);

            if (pHost == NULL)


                    fprintf(stderr, "n%s not foundn", dest[1]);





            // Tell the user what we're doing

            /*printf("nPinging %s [%s]", pHost->h_name,


            // Copy the IP address

            dwAddress = (DWORD *)(*pHost->h_addr_list);

            // Get an ICMP echo request handle

            hndlFile = pIcmpCreateFile();

           // for (x = 0; x < 4; x++)

                    // Set some reasonable default values

                    ipInfo.Ttl =dest[3];

                    ipInfo.Tos = 0;

                    ipInfo.IPFlags = 0;

                    ipInfo.OptSize = 0;

                    ipInfo.Options = NULL;

                    //icmpEcho.ipInfo.Ttl = 256;

                    // Reqest an ICMP echo

                    dwRet = pIcmpSendEcho(

                            hndlFile,               // Handle from IcmpCreateFile()

                            *dwAddress,             // Destination IP address

                            packetsize,                   // Pointer to buffer to send

                            0,                              // Size of buffer in bytes

                            &ipInfo,                // Request options

                            &icmpEcho,              // Reply buffer

                            sizeof(struct tagICMPECHO),

                            timeout);                  // Time to wait in milliseconds

                    // Print the results

                    iaDest.s_addr = icmpEcho.Source;

                   /* printf("\n Reply from %s  Time=%ldms  TTL=%d",




                    sprintf(ping_Resp,"%s %d %ld %d",    




                    if (icmpEcho.Status)


                           // printf("nError: icmpEcho.Status=%ld",

                            //        icmpEcho.Status);

                            printf("\n Request timed out");




            // Close the echo request file handle




            return ping_Resp;


    JNIEXPORT jstring JNICALL Java_com_dtt_traffic_ping_PINGMain_ping

       (JNIEnv *env, jclass job, jobjectArray oarr)


       jsize argc = (*env)->GetArrayLength(env, oarr);

       /* Declare a char array for argv */

       int i;

       char const* argv[128];

       for (i = 1; i < 6; i++)


          /* obtain the current object from the object array */

          jobject myObject = (*env)->GetObjectArrayElement(env, oarr, i-1);

          /* Convert the object just obtained into a String */

          const char *str = (*env)->GetStringUTFChars(env,myObject,0);

          /* Build the argv array */

          argv[i] = str;


         data=(char *)malloc(sizeof(char) * 2048);


        // printf("Data %s ",data);

          return ((*env)->NewStringUTF(env,data));



            Compiling the C implementation into a native library, creating ping.dll or

    On Solaris or Linux, the following command builds a shared library called

    cc -G -I/java/include -I/java/include/solaris

    PINGMain.c -o

    On Win32, the following command builds a dynamic link library (DLL) ping.dll using the Microsoft Visual C++ compiler:

  • cl -Ic:\java\include -Ic:\java\include\win32

    -MD -LD PINGMain.c -ping.dll

    Step 6: Running the

    java PINGMain

        If you get the following error put the dll file in the java path

    java.lang.UnsatisfiedLinkError: no PINGMain in library path

    at java.lang.Runtime.loadLibrary(

    at java.lang.System.loadLibrary(

    at PINGMain .main(

    Tuesday, December 1, 2009

    Java Oracle Connection

    Step1 : First download the classes12.jar file.
    Step2:  Add the jar file to java library path
    For eclipse –  
    goto Projectmenu--->properties--->Click Java Build Path ---> Libraries Tab—> Add External JARs

    Example Program for JavaWithOracleConnection
    Replace the bold values with your settings.
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    public class TestOracleConnection {
    public static void main(String[] args) {
    try {
    Connection con = null;
    con = DriverManager.getConnection(
    "jdbc:oracle:thin:@ipaddressoforacleinstalledmachine:1521:databasename", "username",
    Statement s = con.createStatement();
    ResultSet rs = s.executeQuery("SELECT * from tablename");
    while ( {
    System.out.println("Values------>" + rs.getString("columnname"));
    } catch (Exception e) {

    The Link Exchange - Your ultimate resource for link exchange!

    About This Blog

      © Blogger template Webnolia by 2009

    Back to TOP