Tuesday, January 25, 2011

Communication Link Failure - Mysql

Recently I have been trying mysql with Hibernate. After setting the classpath with all related jars, I am puzzled to see communication link failure error while trying to connect from Hibernate.

Finally when I tried netstat -a, I found mysql was listening at port 3336 where as the default port is 3306. After changing connection url in the hibernate-cfg.xml with port entry, all are working fine. Bad thing is it took some 2 hours to find out that the port is the real curprit. Hummmmmm learning with time.


Wednesday, November 3, 2010

Wonderful PDF editor

Hi,

Here is the wonderful pdf editor that helped me to edit an important pdf document.

http://www.iceni.com/infixDownload.php?Edition=Standard&Platform=Win


regards,
Saravanakumar

Wednesday, September 1, 2010

What will you do?

1. What will you do when people are taking advantage of your normal friendly conversation into SPECIAL conversations?
2. What will you do when the above affects your work and life?
3. What will you do when you are troubled by the name of FEEDBACK?
4. What will you do when you come to know that people are taking obvious negative meaning when you are on the positive side?
5. What will you do when your normal actions are identified as mistakes?

Monday, August 30, 2010

Train ITems

Have you ever had a chance to taste Tea or Coffee served by the vendors in the train? During your travel especially during the day travelling, you will feel like munching or drinking something. If you have any ideas like drinking tea or coffee by the walking vendors, just drop that idea. Have seen pictures from one of the blog spot that tea/coffee can is filled with water coming from toilets. Recently had one tea because of headache but ended up in the same bitter taste.

Also there are lot of Items that are sold by those walking vendors are not good for health for example had some groundnuts and ended up with headache. But food items that are sold in authorized shops located at railway stations are OK type items. For example had a chance to have idlies as one of the food Item in Madurai railway station and they are good. In Madurai, normally temperature is on the higher side and you will end up with making yourself comfortable by removing some of your clothes etc. But there is no need to follow it everywhere say for example in a rainy season in chennai, while standing on the road side etc.

Wednesday, July 28, 2010

Second largest element in an unsorted array

How will you find out second largest element in an unsorted array?

If you would like to do it in one pass, then have two variables as max, secondMax. Do compare all values with thest values. Initially assign, firstValue as max and secondValue as secondMax do compare them.

Now the next question is, will it scale if you have large stream of numbers and if you would like to find Top N from that large stream of numbers?

Have array withe size N and repeat the above steps.

How to convert Version 1 requests into V2 requests?

Scenerio: If existing application is using lot of  Version 1 requests that need to be converted into version 2 requests.

Solution: Write a wrapper over the existing V1 class. For example if you import some class org.version.Version1 and calling various methods like addHeader(), addData() etc, write a wrapper org.wrapper.Version1Wrapper and define all  methods present in org.version.Version1. Inside org.version.Version1Wrapper  call org.version.Version2 methods. Now do a Search and Replace in all your existing code such that org.version.Version1 should be replaced by org.version.Version1Wrapper. Write a well defined unit test case for the newly written org.version.VersionV1Wrapper class.

Advantages: Very less implementation and testing effort.

Java code to convert base 10 value to a hex value

import org.junit.*;
import static org.junit.Assert.*;
public class HexValue
{
    private static final char[] hexArray = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
   
    private static String toHexValue(int baseValue) throws IllegalArgumentException
    {
        StringBuilder builder = new StringBuilder();
        if(baseValue < 0)
        {
            throw new IllegalArgumentException("Given base value "+baseValue+" is less than zero");
        }
        else if(baseValue == 0)
        {
            return String.valueOf(0);
        }       
        while(baseValue > 0)
        {
            int mod = baseValue%16;
            builder.insert(0,hexArray[mod]);
            baseValue = baseValue/16;
        }
        return builder.toString();
    }

    @Test public void  testZero()
    {
        assertEquals("0",HexValue.toHexValue(0));
    }
   
    @Test (expected=IllegalArgumentException.class)
    public void  testNegative()
    {
        HexValue.toHexValue(-8);
    }
   
    @Test
    public void  testValidInput()
    {
        assertEquals("A0",HexValue.toHexValue(160));
        assertEquals("100",HexValue.toHexValue(256));
        assertEquals("EA",HexValue.toHexValue(234));
    }
   
   
    public static void main(String a[])
    {
        if(a.length != 1)
        {
            System.out.println("Help:   java HexValue [baseValue]");
            return;
        }
       
        System.out.println("Hexa Decimal value of "+a[0]+" is "+HexValue.toHexValue(Integer.parseInt(a[0])));
    }
}