Monday, May 28, 2007

Tell Me Why (Java/J2ee Interview Questions)

Interview : The word itself would draw out different kind of emotions. Some may get excited. Some may get challenged. For first timers it may bring pressure in the form of expectation. And of course their are some who would get scared.
The very fact that I am writing about this should be an indication in itself that my feelings are different from the usual written above. There are few people who are actually left confused by the interviews and I am one of them. After every interview I have given (of course in the software industry) I am always left wondering why the questions which were asked were ever needed to be asked at all. It is not that I knew the answer to all of the questions asked rather they were asked left me baffled. I have never been able to understand and appreciate the psyche of an interviewer. It is because of the respect which I have never been able to give to this form of evaluation, I have managed to flunk every time. I have only managed to scrape through one interview and that was for the company in which I am in right now (My first Job). That was more so because the interviewer (who became my PL later on) was asking questions more so about my project rather than the clichéd general interview stuff. These interviews have always left me with the funny feeling. I will try and elaborate using an example.
Let us say you have been inside the industry for a year and then you start working on a job switch. The arrogance of the knowledge you displayed during the first time interview you gave comes back and you start thinking big of yourself. You never realize that a year in the industry hasn’t given you much experience in the eyes of the interviewer and you would rather be asked the same level of question as you were asked before. The only difference being the language on which you will get evaluated will change from c/c++ to java/j2ee. Hasn’t it happened with you if not then probably I am an exception. Even if I am it doesn’t matter, I would rather prefer thinking otherwise. Giving interview again after a year (rather a few months before) gave me the feeling of déjà vu’. The same frustration which I used to feel starting to come back but their was a difference this time. This time I was much more relaxed and was able to laugh at those frustration. I will try to explain the precarious scenario in which I was with a typical java/j2ee interview question and answers and the feeling which comes along with it.
A typical java/j2ee have a set of clichéd questions. And no matter how much one studies a normal human being will never be able to cover all of them. Java/J2ee is like an ocean and the candidate can easily be floored on the mat at any given point of time. It all depends on the person who is taking the interview. If the packages he like belongs to the set of one you like then probably you are safe. Otherwise you very well know that interviewers love to grind candidates and push them to a corner. I think every interviewer gets a kick out of demeaning the knowledge of the candidate. The knowledge neither the candidate nor the interviewer would have never used nor will ever used in the real world..

1) I have never been able to understand why does anyone ask about different packages and their implementation. How the hell is anyone suppose to know about the classes inside and their implementation. There are thousands of them and which one is your favourite Mr. Interviewer I never knew otherwise I would have studied and not make a fool of myself.

2) Now every class by default extends the object class. While writing the code did you ever care about it and moreover did one ever cared about the methods of the object class. Some of the favourite methods to be asked about are clone(), equals(Object obj), finalize(), hashcode() and a few other thread specific methods. Hashcode() Returns a hash code value for the object by converting the internal address of the object onto an integer. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable. Some of the properties of this method is that if two object is equal it returns the same hashcode. If not it returns different hashcode (Although not necessary it done to improve the performance of hashtable). The determination of object equality is done during the equal() method of the object class. Tell me one thing who uses object hashcode to create a table. Anyone creating an object will definitely have unique attributes which would form the key for storing them. finalize() another one of the crazy method called by garbage collector but did anyone ever override this method in their own class. If yes then you do tell me why. The purpose of other methods will get clearer later on in the rendition of my grievances.

3) Difference between == and equals another favourite of the interviewers. When two objects are compared using == it returns false whereas what happens if it is done via equals (obj1.equals(obj2)). Well if one hasn’t been using equals that extensively one might go back to strings and say Hey strings are objects , it works over there then it should work for any object. But hold on my friends this where the equals method of the object class needs to be overridden as an object can be made according to programmers whims and wishes so the equals need to be overridden for the method to work on our own customized classes. Well most of the time who cares about the equals method when the comparison needs to be done on a particular attribute only.

4) Collections: Probably one of the most favourite among the interviewer. The questions rather interrogation starts of lightly with interviewer expecting you tell him/her with the classes you are familiar with. Then question will go in the direction of the difference between a linked list and array list and when to use which. You say for that for faster access you will use the later but they have an answer already in their head which they want to hear. Yes they actually want you to say that for linked list you have exact memory allocation whereas an array list is growable array in which the array size increases dynamically by a factor of 1.5 + 1 with an initial size of 10. Tell me one programmer who took this into consideration. Its generally array list everywhere so you also start using the array list or any other storage structure which one is familiar with without thinking about the concept being discussed here . Then their may be other question on Set which cannot have duplicates SortedSet which is the sorted implementation of Set. Then they may ask some question on some legacy classes like vector which are synchronized.

5) Then there are good old legacy object oriented question but specific to java. Some of them are A) Difference between interface (which can have only abstract methods and static final variables) and abstract classes which may have self implementation of a method besides the usual abstract methods. B) Whether a protected method in base class can be declared as public derived class. The answer for which is no as we can only reduce the scope not increase it. Interviewers generally have the habit of tweaking a little here and a little there of the OOP concept and they feel glad to grill the candidates with them.

6) Of course then their are some basic key word question which interviewers definitely like to grill you with. Falter here then it would be hard to impress them. The key words can be static, final, transient, public, private, protected, default etc. 'static' is for declaring class variables i.e. only one reference is created for static variables for multiple objects. final variables are constants, final methods cannot be overridden and final class does not make any sense for extension. transient variables are not serialized (i.e. when a object copy is created it gets initialized by its default value). private is for class specific variables and methods, protected variables and methods can be used by derived classes, default variables and methods are accessible within a package only and public variable and methods is accessible across packages. Now just one question is on my mind does anyone uses 'default' and unless one come across a scenario while coding that their is a requiremnet of such declaration for the design why would anyone even bother to think about it.

7) Coming to exceptions. Who the hell likes exception in the program. Every programmer would like to exhaustively handle all kind of exception scenarios. So much effort gets spend in identifying and handling those scenarios but any programmer would be able to leave a few. Thankfully we have certain classes to catch them. The Checked (which can be catched,subclass of Exception class)and Unchecked(which only gets caught at runtime, subclass of Runtimeexception class) exceptions are the two kind of exception in java. Now the most generic question to be asked under this category is the usage of finally block along with try and catch. Its basically for calling this block(generally to free resources) irrespective of try block is called or catch block. But this is not enough interviewers have a cruel way of confusing you by asking whether this block gets called if in a try block their is a return statement. The answer is yes but they ask in a way that you will definitely get confused and will struggle to get a reason why and then you try your luck. Their is another thing they ask that is the way to create ones own checked and unchecked exception. One can throw checked exception using throw new Exception() and unchecked exception using throw new RuntimeException(). Yes simple but to that person who generally uses unchecked exception but my guess and experience tell me if I want to throw my own exception I would throw a checked exception why should I require to throw an unchecked exception may be someone can explain. Something which I wont be able to catch within the program is a scenario I haven't come across.

8) Object clone(): Here is another one of the crazy concept if one doesn't not know one is bound to flounder. If one doen't know this concept one generally takes String as a reference and derive conclusion out of it. Here lies the inherant danger of the concepts getting totally screwed up because of the implementations provided in string. When obj1=obj2 is done obj2 reference gets passed to obj1. To create a new copy clone() method of the object class has to be used. Then again clone() can only give shallow copy that is a copy of the object but the references inside the object is not created. To get a complete copy of an object i.e. to do deep copy one has to make the object serializable and write it to (Byte)OutputStream and read it back from there. This is probably the only way to create a total copy of an object including its references. My Oh My ....Somebody save the candidates if they did not know about cloning.

My friends I have a long list following. I was able to write this much only. I will come back and update with a few more as I start recalling the typical clichéd questions.

Saturday, May 19, 2007

Dance

The Bible
Ecclesiastes
To every thing there is a season,
and a time to every purpose under the heaven:
A time to be born, and a time to die; a time to plant,
and a time to pluck up that which is planted;
A time to kill, and a time to heal; a time to break down,
and a time to build up;
A time to weep, and a time to laugh; a time to mourn,
and a time to dance;

The question is Is their anything in your life which has given you pleasure which is unexplainable. The pleasure which gets you into trance. The pleasure which is in its purest of form. The pleasure untouched by the ways of the world. The pleasure which made you happy beyond your expectation. The pleasure which cannot be shared. The pleasure which can only be experienced. The pleasure which makes you feel closer to a higher entity. The pleasure which makes a believer out of an atheist. The pleasure which is actually not a pleasure but a state of your mind in which you have no boundaries. The pleasure which releases you from all the bonds. The pleasure which made you feel free in the actual sense. The pleasure which drove you to ecstasy and the ecstacy is what you have lost. The pleasure which you are always in the lookout for. The pleasure which has become a part of you. The pleasure which you had experienced years before. The pleasure which has now been lost in the world you are living. The pleasure which never fails to bring a smile when you think about it. The pleasure which made you calm and serene. Yes my friends such are the properties of the pleasure I am trying to define.

Actually their is no particular definition so I have tried to list out various properties of the thing which I am talking about. I hope that you are able to relate with the thing which I am trying to point towards. Looking at the things said above one (especially people like me who has just started into professional life)might find it difficult to relate it to any of the thing which one might be doing now . Probably if one will look hard enough into the past then a thing or two might come up. Dancing could be one of those thing as it is for me.
Dance is one of the purest form of expression of ones feeling. It can bring one joy which one is always in the look out for. Oh no Sir I am not talking about dancing just like that in party. I believe the state which I am trying to define is not achievable in those parties. It cannot be achieved by an hour or two of fun. It is not achievable in a party where you are dancing more so because of others than yourself. Rather I am talking about the dance which one enjoys for oneself. It is not driven to impress others nor it is driven to please others. The dance which I am referring to is an expression of freedom. This form of art lets one forget all the troubles in the world and gets one to a place which is unmatched by any in beauty . Have you ever tried dancing for 13-14 hours at a stretch. This state and form of dance was what I was able to achieve after 4-5 hours of continuous dance. This leads one to a state where ones body and the music becomes one in unision. The rhythm and beats is what drives ones movement. Then the music does not remain something which is played on a speaker rather it becomes a way to communicate to an unknown entity. The undercurrent of music then starts flowing through ones body and gets embedded in ones soul. Then even when the music stops one keeps on shaking oneself with the beat which is being emanated from one body. Now one might question that after such long hours of shaking ones body doesn't one gets tired. I say this is what is one of the effects of achieving this state of ecstasy. Instead of getting tired one feels doubly energised. Each beat of music then becomes a source of abundant energy. Such can be the power of the bodily movement called the dance. It has been rightly said by Martha Graham that "Dance is the hidden language of the soul". The artform which can be so passionate, intense and meaningful that it engulfs one with its beauty.

As I said before that their can be other things which actually effect you to get into a state of complete joy. Be whatever it may be, never be hesitant to enjoy it over an over again. Cause then may come the times when one has to regret of not doing that enough. So if it is dancing then let your hair down jive a little and enjoy it to the fullest