Wednesday, 2 July 2014

Birla Soft Interview Question & Answers for Java 2- 4 year experience.

The below questions asked by Birla Soft for Java/J2EE. I tried to give the best answer , hope it will help you out to crack the interview.



Q. Tell me about your self?
 Ans:  Give your brief introduction.

Q. Is Java Pass by Reference or Pass by Value?
Ans : Its always pass by value .

Q. What is the difference between an Interface and an Abstract class?
Ans : Both are looks similar. But, the basic difference is abstract class can contain abstract and non abstract methods, where interface only contains abstract method (without method body). You can declare fields that are not static and final, and define public, protected, and private concrete methods in abstract class. But, in Interface all members are public, static and final , all methods are public.

Q. What is the purpose of garbage collection in Java, and when is it used?
Ans : Garbage collection is a special feature in java language. It helps developer to save time and extra mental tension for handling object allocation in memory. It automatically clean the unused object from memory which helps to allocate space at runtime. When there is no reference to an object found, it will clean that object from memory . You can run the garbage collection explicitly by using System.gc() .

Q. What is Marker interface? How is it used in Java?
Ans : Marker interface is an interface which help us to notify few information to JVM/Compiler. The marker interface does not have any body, it’s a empty interface. Ex. Cloneable, Serialization, etc.            

Q. Can you give few examples of final classes defined in Java API?
Ans: String, Integer ,Float ,etc. Basically all wrapper classed are final.

Q. What is the importance of init() method in Servlet?
Ans:  init() method is one of the life cycle method of servlet. This method runs once in total life. After servlet instance created and before it handles request the init() method will work. Its basically used for initializing values at the time of application startup.

Q. How to improve Servlet Performance ?
Ans: You need to do few tuning for this achievement. Few points below :-
1.     Use init() method for all expensive operation during initialization (may be static data or cached data ).
2.     Always avoid auto loading of servlet.
3.     Avoid SingleThreadModel.
4.     Use and control HttpSession properly.

Q. How can a servlet refresh automatically if some new data has entered the database?
Ans :  Basically it depends on the scenario , how you can handle. You need  handle this in dao layer, when doing insert operation you can call an utility method which will load the context ServletContextListener. Because, servlets are basically used for handling request and give the response.

Q. How does JSP handle run-time exceptions?
Ans: You can use isErrorPage=”true” in page attribute.

Q. What is an EJB Context?
Ans: The EJBContext interface provides an instance with access to the container-provided runtime context of an enterprise bean instance.