Thursday, June 24, 2010

XML to HashMap in JAVA

Hi Guys,

This program will convert any XML document to a HashMap in Java.
Download - Please download it from here-

1) Program 1:
This is the main java program. It has public static void main method.
2) Program 2:
This is the program which will actually do the conversion.
3) Prgram 3:
This is just a small util which will convert String to InputStream.

How to use?
1) Please unzip the zip file.
2) Copy all the 3 files in same folder
3) Run

The program will run on Java 1.5 and higher.

Thursday, June 10, 2010

com port communication using java

NOTE: For step by step tutorial please click on this link -


public class ComPortTest

 * This program will connect to COM PORT Device and send TEST MESSAGE to it.
 * After sleeping for 500ms , It will read the response from SAME DEVICE.
 * copyright (c) 2011
 * For detailed Tutorial please check it out - 
public boolean testComPort(String comPort, String testMessage){
    CommPortIdentifier portIdentifier = null;
        portIdentifier = CommPortIdentifier.getPortIdentifier(comPort);
        if (portIdentifier.isCurrentlyOwned())
            System.out.println("Port in already in use, owner ["+ portIdentifier.getCurrentOwner()+"]");
            return false;
            SerialPort serialPort = (SerialPort)"ListPortClass", 300);
            System.out.println("COM PORT NAME -["+portIdentifier.getName()+"] BAUD RATE ["+serialPort.getBaudRate()+"]" );
            serialPort.setSerialPortParams(300, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
            OutputStream mOutputToPort = serialPort.getOutputStream();
            InputStream mInputFromPort = serialPort.getInputStream();
            System.out.println("Byte Sent");
            System.out.println("Waiting for response");
            byte mBytesIn [] = new byte[20];
            String value = new String(mBytesIn);
            System.out.println("Response from Serial Device: "+value);
            System.out.println("!!! ======================== COM PORT TEST - PASS =============================!!!");
            return true;
    }catch(NoSuchPortException nspe){
            System.out.println("No such port ["+comPort+"] found on system "+ nspe.getMessage());
    }catch(PortInUseException piue){
            System.out.println("port ["+comPort+"] is already in use, owner["+ portIdentifier.getCurrentOwner()+"] "+piue.getMessage());
    }catch(UnsupportedCommOperationException ucoe){
            System.out.println("Setting Communciation Operations - 300, DataBits -"+ SerialPort.DATABITS_8+", StopBits "+ SerialPort.STOPBITS_1+", Parity "+ SerialPort.PARITY_NONE);
            System.out.println("Communication Operations are not supported on port ["+comPort+"] "+ ucoe.getMessage());            
    }catch(IOException ioe){
            System.out.println("IOExceptin while trying to communicate with COM PORT device "+ ioe.getMessage());
    }catch(InterruptedException ie){
            System.out.println("Interruption while waiting for response from COM Device "+ ie.getMessage());
    return false;

    public static void main(String... args){
            new ComPortTest().testComPort("COM1", "JOVIAL JAVA");