24 April 2010

Multiply Your Money - Systematic Investment Plans

Money is not biggest thing in life but it is reasonably close to oxygen. And there is nothing wrong in trying to maximize your corpus. With the rising inflation and real estate reaching unrealistic limits, I always feel that I m left behind. I m not so sure what will my lifestyle and what kind of lifestyle I can afford when I retire. With my little experience in investing, I feel that we have few options like NSC, PPF, Fixed Deposits, Stocks, Real Estate, Mutual Funds and life insurance.

I am very big fan of Systematic Investment Plans because of the idea of discipline. A portion of your salary goes to stock market every month. If you ask any successful investor, he will tell you that the key to investing is discipline and investing in small chucks periodically. The simple reason why "periodic small chuck investing" works is that we buy when market is low, we also buy when the market is high and we sell when the market is higher. I have strong belief that a periodic investment (every month) of few thousands for 15-20 years in stock market gives 5-10 times the returns from fixed deposit. But there is so risk but the risk can be diversified or reduced by investing in different types of mutual funds every month.

To give you a perspective, I started to invest 3-4 years back when the market was high. We all know that market crashed and even now I have a returns between 20-50%. The high return is possible simply because I bought during market crash. If you are serious about building a corpus, I would seriously suggest you to enter into mutual funds every month. The old saying, "little drops make ocean" hold very much for systematic investment plan.

Of course, you need a good financial consultant who does more than collecting money from you. He should be able to give you ideas on investments. Anyone who is having a good portfolio of services in MF and contacts in fund houses is the right candidate. Though, I don't do this as business, I can point you to my financial consultant Mr. Anand Srinivasan if you want. With his help, I am able to build a good corpus even now and I m on track with my targets :-)

Threads Execution - From my Imagination

Having posted general posts for long time, once in a while, a little poor programmer tries to creep out. This is an interview question and so far I haven't heard from anyone any different answer. The key to software development is imagination and trying to add more perspective. The multiple perspective helps us to clearly differentiate and appreciate the depth of the language. With no delay, let me jump into my question. Take a look at the following code and tell me what happens.
public class Threads extends Thread {
   
    public void run() {
        // do some serious thing
    }
   
    public static void main (String[] args) {
        Threads t = new Threads();
        t.start();
        t.start();   
    }
}
If you recognized that we create a thread, execute it twice and it will lead to IllegalThreadStateException, you are right. But have you ever imagined why threads cannot be executed twice. Here is my imagination.

Any thread is an independent execution path. You can have many execution paths that are similar in terms of execution and state changes. Let us take an example from real world. We do lot of things in a day like reading, writing, eating, speaking and so on. If we model or think that each activity as thread, though on a given week we may read many times, probably the same book at same speed, each read is different in the context of time. Similarly, in programming, two or many threads appear similar but they are not really similar. Any execution may it be a process or thread, it is illogical to go back in time however you can spawn off new process or thread that does the same thing. Execution cannot be taken back in time (if we take back execution, it is debugging).

Thread has two properties - object and an entity that can be scheduled. The points we discussed above is more on "an entity that can be scheduled". An entity that has completed its run, cannot brought back to execution as its purpose of its creation is over. But from object's perspective, it is data and hence can be accessed and kept for any duration as long as the process is alive.

When you think about thread, remember - "thread has life and object has space". Thread is an object and hence it is given a space in heap, it is available as object till it is garbage collected. But Thread as a entity of execution, it has life. Once its life is over it can be restored again.