Thursday, September 25, 2008

My second interview with I

So I went for my second interview with I
And this time -dressed up :)

It was a good conversation
I think I did well.
It was weird hearing myself speak at times.
The first meeting was with V- An architect of sorts
I think I was able to carry the conversation well
He has some interesting questions- which i think I answered well.

Meeting with A and D also went fine

Lets see... what happens next
All this economy meltdown has me worried...but then should I worry ?

I already have my 'insurance policy' :)

Technology Tracker

So these are the technologies I need to catch up on

GWT
Php
Webservice
AJAX
Grails
Groovy
Flex
Ruby
RoR
Apache
Tomcat
mySQL
Linux
JUnit
Cactus

Saturday, September 20, 2008

What is Factory Design Pattern

Factory design pattern is a creational pattern- which gives you more control on how you create objects.

The main objective is to encapsulate object creation.





Factory pattern basically comes in three flavours

A) Simple factory

There are three entities. Client- who needs to create objects. Factory- who does the actual creation. Product- the objects that are finally created.

The client has a reference to a the Factory (or this method createObject may be static as well)

The client then asks the factory to create the object it wants



B) Factory Method

It has two sets of classes- Creators and Products.These are implemented as parallel hierarchies

So we have Product A, B, C - (all implementing the same interface Product I)

And in parallel- we will have multiple creators- Creator A,B,C extending Creator Abs.

The Creator Abs defines how Product will be created

Creator A , B and C have specific knowledge about how their counterpart Products will be created

No one except Creator A should know about Product A



An abstract creationMethod is provided in the Abstract Creator

This will be implemented by the Creators A ,B,C



C) Abstract Factory Pattern

This is used to create a family of related objects rather than a single object.

We start with an abstract interface which defines the suite of objects to be created

like createValidator, createPreProcesor, createPostPorocssor.

We will then create a Factory which implements all these methods

The objects that this class will create will all be related or dependent

We can accordingly have another Factory which also implements the same interface- but this one creates another set of objects - also related to each other though



The second thing we need to do is define the family of objects

e.g. you have a POValidator and a DO Validator

POPreprocessor and a DOPreprocessor

PO Validator and DO validator belong to the same family and POPreProcessor and DOPreProcessor belong to another family

Whats the difference between Hashmap and Hashtable

Hastable is always synchronized.
Hashmap is by default - not synchronized- though it can be constructed as such

Hashtable doesn't allow null values. Hashmap does allow null values(Neither allows null keys)

These headhunters...

Oh boy
Some of these are worse than car salesmen
Specially this lady -SG.

Every time I bring up the name of a company I am talking to - without her help
All she has to say is- Oh that company sucks

Well, S:
I am not as naive as I seem to be
I appreciate that you have a living to make and in a way is related to how and where I make the selection. But puh-lease - don't be so naive yourself to think that I would be so naive to shut down my grey cells and look for your advice at all

Meeting K was quite refreshing.
She was awesome !!!
Helpful. Genuine. She earned my respect for her- in the first call.

How do you write threead safe programs

Thread safe program is one which will work well in an environment where there are multiple threads working in tandem.

Look out for global variables. These can be easily in the centre of a conflict between multiple threads
Its a common practise to declare static constants. Such constants should be declared as final whenever possible.
This will gaurantee that these do not get changed
If you have an intention of changingthese- then they shouldnt have been Static Variables probably

Thread safe program is achieved by taking care of the following
1) Write re-entrant code
This involves using variables created on stack (private variables) rather than variables created on heap (global)

2) Mutual Exclusion
Access to shared data is serialized- typically by using programming constructs like synchronized in Java.

3) Atomic operation
Using machine language instructions

4)Thread local storage
Not sure if Java provides this.

Saturday, September 13, 2008

What is a Singleton Pattern

Singleton pattern is used to ensure there is one and only one instance of a class.

There are three parts to it

A. Ensure that we cant have more than one instance of the class
This is done by marking the constructor as private or protected
B. Provide a mechanism to access the singleton object. This is typically done by providing a static method to access the object. Something like getInstance ()method
C. Creation of the object.
This is by far the most tricky part.There are many ways to do so
1) Create the object using the static initializer or Construct the object at the time of declaration
This uses the classloader to create the object. You can run into issues in a J2EE environment where there can be multiple classloader
2) Use an inner static class. The singleton object is held in a static inner class. This will ensure that the object is not created until its really needed
3) Use double-checking mechanism. This means that we create the object in the getInsatnce() method- we check for NULL before creating the object. And the call to the creation of the object is enclosed withing synchronized block