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])));
    }
}

How to Spam one's personal mail id?

1. Somehow get hold of that person's mail id. You know your own ways of knowing that person's personal mail id.
2. Subscribe that person's mail id to the websites you would like most. Those websites obsivously irritate the victim.
3. If you think that person is blocking your marriage, then subscribe that mail-id to some matrimonial site. You have the privilege of choosing the RIGHT match for your victim. After doing this you will have full satisfaction and inside happiness forever.
4. Subscribe him for some adult jokes web site.
5. As always you can send some actress pictures since sending your pictures could be a waste of time.

Sigh.....

Tuesday, July 27, 2010

A mobile - A Car - A hardware

Can you draw a block diagram for a mobile application that communicates with a Car and a hardware which has legacy C, C++ module?

And here it is ...

Monday, July 26, 2010

Indexing - the Need

Objects are stored in discs just like they are stored in memory. Every object has a memory pointer at which it has been stored. Like wise for example a database row, has a location pointer at which is has been stored in the disc.

As for as the arrays are concerned, if the stored memory is contigeous, it is easy to randomly fetch that element. Let as assume we have an integer array with length 10. In java, integer occupies 4 bytes. We know the startIndex of this array while defining this array. Lets say its 1000. Now if we want to access 4th element, we shall directly go to 1000 + 3 * 4 = 1012 and read next 4 bytes. This is one kind of indexing.

This principle can be applied to database too but with many complexities involved. For example having multiple columns and variable string length etc. If we assume constant maximum length, then we might end up in wasting some space but with the performance benefits.

Normally rows are ordered based on primary key. Hence by default rows are indexed based on primary key. On accesssing the primary key value in the disc, user get to know the location of the complete row and if possible size of that row. If you want a specific column to be searched frequently, we shall index that column. By indexing means here, that values of that column are stored in a sorted manner in a separate place.

Now the users query might be little more complex, like checking whether value 5 exist or not or get the row values when my column value is 5. Here we need to scan through the values of the primary key/indexed column. So here sorting can help us to minimize the retrival time. It helps you find the element in log n time.

Sunday, July 25, 2010

How to improve performance of an application when you know nothing about that?

An application is given to you and now the question is how to improve the performance of that application?

Initially you know nothing about that application. So how do you execute the above task? Its through LEARNING. Learning could come through books, colleagues, google ..... and finally it could come from your own experience too.

Before answering the above question let us define the term performance. Bad performance means the system/application is delivering the output with some glitches. Performance of an application is measured in terms of efficient usage of resources. In other words improving the performance means finding and rectifying the inappropriate usage of resources. At the bottom level, it could end up in identifying and rectifying defects in the application either it could be in the application code or database or any other middle level layers.

Time is an important factor as for as the performance engineering is concerned. Less the time taken for a given task, better the usage of resources. Some times it could end up with using excessive usage of resources too. There should be a well balance between the usage of resources and the performance of the system.

Now what are all the resources used by that application?

1. I/0

File Access, database file access, other storage access, socket read/write and inter process communication etc.

2. CPU

CPU is used heavily for all computational intensive operations.

3. Memory

Memory helps you to reduce I/0 and hence you will get better performance by making
full use of memory.

1. Now identify the set of operations for which the performance is not upto the mark.
2. Prepare right tools to monitor the above resources while performing those operations. For example CPU, memory, IO can be monitored through commands like top in linux. Task Manager in Windows could give us wonderful inputs. Memory Analyzers like OptimizeIt, JProbe could give us wealth of input. Custom tools like sql query analyzer to find repetitive queries and queries that taking longer time will be very handy. In the case of web servers/application servers, tools that are analyzing http headers could help us to identify unncessary requests or repetetive requests.
3. Execute above operations and see the usage of resouces while doing the same.
4. Identify abnormal usages and try to rectify them. For example excessive IO could be rectified by proper caching, efficient usage of algorithms, indexing or even some times replacing default discs with high speed discs like RAID could do.
5. Excessive memory usage could be identified through OptimizeIt or JProbe. They have the capacity of identifying root cause of the excessive object creation. It could be because of the bugs in the application or we can go for object pooling to minimize temporary objects creation.
6. Like wise excessive CPU usage could be avoided by using efficient algorithms or sometimes through parallel processing etc.

At the end, if you get success, you will be a WELLKNOWN from UNKNOWN as for as the application is concerned.

Saturday, July 24, 2010

What does Tiles do?

Tiles helps us to create consistent layouts through out the product/website. For example, consider the scenerio of having one header.jsp/footer.jsp and multiple content.jsp.

Here content.jsp could be changing for each and every request. In simple jsp implementation, we can achieve this by passing content jsp name as request attribute from the action class and dynamically we can include the jsp through jsp scriptlet (<%=request.getAttribute("contentName")%> or through some jstl core tags like c:get.

Now what we need to do if we have multiple header.jsp and footer.jsp. In other words what we will do if we need to show customer specific headers and footers but at the same time we need to maintain consistent L & F through out the product/website. Here comes the real usage of tiles, we will have only one layout.jsp and we will insert different header jsps (say header1.jsp header2.jsp etc) through tiles-def.xml combined with struts forwarding mechanism.

So basically tiles helps us to abstract and decouple layout and implementation jsps.

Thursday, June 3, 2010

Art of Spitting

In your short life span, surely you would come across people who are very good at nothing but for Spitting.

It starts from the bottom stomach with a low voice for 3 seconds and travels with the medium voice for 4 seconds and ends in high speed with 6 seconds.

It makes other people to run away from the apartments sometimes. The finest thing about the person who does is not ashamed of himself since he concludes with a note that he consumes ... regularly.

Amount of satisication they get is enormous after doing this but they dont even mind about the people who are getting affected because of this.

What a weapon they have?

Monday, May 17, 2010

Popular Design Patterns

When you do repeated code for authentication, authorization etc in each and every servlet, then you need to implement Front Controller to get rid of all those repeated code. Your front controller is also responsible for invoking the right component to perform your business need.

When your client needs complex business logic like getting data from multiple entities then you need to implement Session Facade where your session takes care of identifying unique requests and correlating multiple requests into one where by reducing the network overhead between client and presentation tire.

In most of the cases JNDI has either network overhead or io overhead. Its always beneficial to reduce number of JNDI lookups. ServiceLocater can be used to do that as it caches the resources obtained through JNDI lookups.


Business Delegate
is the right choice when you have your business components that are directly getting invoked from the presentation layer component. You can call this as a high level bridge pattern.

Monday, April 19, 2010

How to implement BeerPool through counting semaphore?

No. I am not going to write code here. Drawing class diagram is also tough here. So let me list down the requirements and solution through text as much as possible.

1. It should always have the minimum beer bottles in the initialized state. i.e filled state.
2. Beer bottles should not exceed the maximum count.
3. Beer bottles should be reused (irrespective of whether they are cleaned or not)

Now one way of doing the same is listed below

A skeleton of the code is given below

public class BeerPool
{
public BeerPool getInstance()
public BeerBottle getBeerBottle()
private BeerBottle createBeerBottle()
public BeerBottle freeBeerBottle()
}

Let me maintain an integer createdBeerCount that takes care of the number of created beer bottles. getBeerBottle and freeBeerBottle methods are synchronized where you will be incrementing and decrementing counting semaphore.

LinkedList is used to maintain the BeerBottles. In getBeerBottle() method, we will use pop method of the LinkedList and return that object.

IMPORTANT: point to note here is removeElementAt(0), is O(1) operation. If createdBeerBottleCount is >= maxBeerBottleCount, thread has to wait. On interruption throw timeout exception.

Now on freeBeerBottle() method, reduce the count, and push returned BeerBottle in the LinkedList as last object. This method also takes O(1) time.

Since you know the MAX_BEER_BOTTLES count, you could easily use LinkedList instead of any other collection. But the key point here is we need to add and remove elements in O(1) time.

Saturday, April 17, 2010

What is the difference between mutex, monitor, lock and semaphore?

Mutex is a lock. At any point of time only one thread can hold that lock and once its job is done, it has to acknowledge that through unlocking mechanism. Its used for mutual exclusion to avoid multiple threads corrupting global datasource. Java's synchronized keyword does this internally.

Semaphores are useful in sharing common resources efficiently through counters. For example object pooling and thread pooling can be implemented through counting semaphores. By functionality binary semaphore is equivalent to mutex except the fact that monitor ownership is provided in the mutex case. In java, semaphores can be implemented through wait and notify mechanism.

Lock shall be implemented using Monitor.  Monitor and Lock are giving same functionality. Across threads mutual exclusion can be implemented using Monitors. Across processes mutual exclusion can be implemented using mutex.

Have you ever wondered the difference between notify and notifyAll?

Have you ever wondered difference between notify and notifyAll methods in object?

Notify notifies only one thread that is waiting on the object. NotifyAll notifies all the threads that are waiting on the object.

Now what happens when more than one thread is waiting on the same object and notify is invoked?

Only one of these waiting thread will be entering into running state and all the other threads will be in waiting state. On the other hand, in you invoke notifyAll, all the threads will be entering into running state one by one.

Monday, April 12, 2010

Missing Number

In a table you have 99999 rows. But the max id is 100000. That means only one row is missing. How will you find that missing id in one simple query?

















select (max(id)*(max(id)+1))/2 - sum(id) from table;

Math: to find sum of n integers, you can use n*n+1/2.

Tuesday, April 6, 2010

Expectations Series 1 - From a Software Engineer

Year 0: Getting a job in MNC during campus interview
Year 1: What bike to choose?
Year 2: When is my next hike?
Year 3: When I will get Onsite? Which project should I choose to get onsite?
Year 4: Will SHE come for onsite?
Year 5: In which area should I buy plots?
Year 6: Is my domain safe from pay cut-off & recession?
Year 7: Boring work.....should I change the domain or company?
Year 8: Which girl to choose?

Coming more.....

Friday, April 2, 2010

Little things in Travel

1. A thank you with a smile for the bus driver after a long safe night journey.
2. Taking ticket for the co-passenger when conductor is angry with no-change. he he it happened to me.
3. Girl asking a guy/man to sit near her when there are no common seats are available. Especially in tamilnadu buses.
4. When a grandfather like man around 70 years of age inquires about today's sachin's score to an unknown young boy sitting next to him.
5. Taking care of a child from a standing mother. I happened to see that in all buses.
6. Conductor waking you up at the right place when you are asleep in between in your long travel.
7. Train ticket collector finishing his duties when your turn arrives.
8. Conductor giving exact change when you have no change in your wallet.
9. Seeing a known person when you have zero money in your wallet to get the ticket.
10. Stopping bus, seeing your hand signal.
add more...

Thursday, April 1, 2010

Title Reason - Where is devil?

Where is Devil?













Devil is in your mind. If you feel happy for simple cute things then you will make others happy for such things. Be it a knotty joke or past experience or a comedy scene in a movie, enjoy it and give the pleasure to others. Spread your positive attitude in professional and personal life. A simple cute action or word can change entire tensed situation as a simple pleasant one. For example saying "I Love you" to your wife after 10 years of tiring marriage life.


Now what are all the cute little things that make me happy and satisfied? Later ..