Saturday, January 8, 2011

Q. What is the difference between a Buffered Writer and a Print Writer?


Ans. These classes were implemented for different aims. For example, Print Writer is just a convenient class to write some text information. It is convenient because it has methods to write strings, any primitives (double, float, ...) and so on, you should not convert primitive to string, some useful methods have been already implemented. 

Buffered Writer was implemented not for user convenience but for performance. The main aim of this class is to buffering characters that means if you call write(char[]) method it will flush characters to underlying outputstream only when some threshold will be reached.
Q. Why interface variables are final?


Ans. An Interface is a contract, so everything has to remain the same. If you declare a variable, it means that the variable is always available to the implementation. This is also true to the value. If someone was able to change the value, you can not depend on the value, thus breaking the contract. 


Q. Why there are two ways of implementing Thread in Java?


Please answer this question.

Q. Explain which bean is faster than other(Stateless/Statefull) and why?


Ans: State full bean has to be persisted while stateless is only used once. If cluster is used, State full Session Bean has to be replicated on all servers. State full Session Bean has to be tied to session and used for that session only, while State Less Session Bean is used for single request only. 
But, State less and State full have different usages. If you are building request response application State less is OK. If you have app that has to remember state between multiple requests, State full is the option.