Friday, October 5, 2012

20 EJB 3.0 Interview Questions and Answers - Java J2EE

EJB interview questions are core part of any Java J2EE interview. As EJB forms business layer for modern J2EE enterprise application, Good knowledge of EJB is expected from J2EE programmer. Purpose of these EJB interview questions is to give an Idea about what kind of questions you can expect on J2EE and EJB interviews. EJB was always tough for Java programmer because of heavy weight architecture comprised with many interfaces e.g. home interface, remote interface, local interface, bean class etc. It take too much time and knowledge to implement and use EJB in your Java web and enterprise application forget about challenges posed by application servers like WebLogic or IBM WebSphere. All these problem persist till EJB 2.0 which makes EJB infamous along with J2EE and created path for Spring framework which is based on POJO. But with EJB 3.0, Enterprise Java Beans are back again and they are back with bang. In this article I will share some EJB Interview questions from my collection. These EJB questions are from EJB 2.0 and EJB 3.0 and also related to fundamental concept of using Enterprise Java beans. By the way I don't have answer of these Enterprise Java beans questions but I will update the post once I have answers of all these interview questions asked on EJB interviews. This article is divided in two category, in first category we will see some common EJB interview questions and in second category we will see EJB 3.0 interview question, which is more popular now days. I have seen EJB question on companies like Capegemini, TCS, CTS, Infosys and Wipro and mostly on finance domain projects

Common EJB Interview Questions in J2EE

1. What is Enterprise Java Beans (EJB) in J2EE ? What is advantage of using EJB ?
This is the first EJB question  asked to programmers on beginners and intermediate level. Enterprise Java beans are J2EE component which is managed by Container provided by Application server and encapsulate business logic and forms back end of Enterprise Java application. Main advantage of using EJB is to leverage core services provided by EJB container e.g. transaction management, persistence, security etc. Also business logic encapsulate in EJB is good multi-tier design and can be used with different clients e.g. Web, Desktop and mobile. Current version of EJB is EJB 3.0 which is based on annotation.

2. Can we run EJB in web server like Tomcat ?
One of the tricky interview question on EJB. No you can not run EJB in web server like Tomcat. You need application server like Glassfish, WebLogic or Websphere to run Enterprise Java beans. One of the followup question of this is What is difference between Application server and web server. See the link for answer of that question.

3. What was shortcomings of EJB 2.0 ?
If you have mentioned in your resume that you have worked on EJB 2.0, then better be prepared for this EJB interview question. It's not difficult to answer if you have indeed worked in EJB 2.0. There are several pain e.g. writing those local and remote interfaces, too many boiler plate coding etc.

4. What is advantage of putting business logic in EJB over stored procedure?
This is another tough Java question on EJB interview. Putting complex business logic in stored procedure is not a good idea but its been there for long time. Main advantage of using EJB over stored procedure is that you don't need to port your SQL Stored procedure code when you change database e.g. form Sybase to Oracle or Oracle to SQL Server.

5. What are the services provided by EJB container ?
Good EJB Interview Questions Answer asked in J2EE interviewContainer is one of the main reason why Programmer should use Enterprise Java beans. EJB container provide several useful services like :

1) life cycle management of Enterprise Java beans (EJB).
2) Container manged transaction
3) Container managed persistent
4) Security etc

6. What is two phase commit? How do you manage distributed transaction in EJB
This is one of the most tricky Java question I have seen in EJB interviews. Two phase commit involves one Transaction manager which controls whole commit process. If you have not used two phase commit or distributed transaction along with EJB then you need to explore this topic in detail to answer this EJB interview question.

Couple of more EJB interview questions whose answer will be updated later.
7) EJB invocation is based upon which design pattern ? What is Service locator design pattern ?
8) How do you call Enterprise Java beans from Servlet or JSP ?
9) What is difference between Session and Entity beans ?
10) What is Java persistence API or JPA.
11) What is difference between stateless and stateful Session beans ?
12) What is Session facade design pattern used in EJB and J2EE ?
13) What is difference between Session bean, Enttiry bean and Message driven bean (MDB)
14) Can you create Thread in EJB ?

If you know answer of these EJB practice question than please share as comment.

Top EJB 3.0 Interview Questions

In this section we will see some EJB 3.0 Interview question. EJB 3.0 is the most popular version of EJB which surprisingly ease development of EJB by using annotation based approach. EJB 3.0 is also most popular EJB version in use.

1) What is main difference between EJB 2.0 and EJB 3.0 ?
Simple answer is use of Java annotation, ease of development etc.

2) Can you name few annotation used in EJB 3.0 and what does the do ?
This is another simple EJB 3.0 interview question which can be easily answer if you have coded few EJB 3.0 beans. Some annotations used are @EJB, @PreDestory,  @PostConstruct etc.

3) Does EJB 3.0 supports dependency Injection ?

4) How to call a EJB 3.0 bean from Servlet or JSP ?
Use @EJB annotation.

5) What are the issues you face with EJB 3.0 ?

These were some of the EJB interview questions for practice if you are going to appear in any Java or J2EE interview which requires EJB skills. There are not many J2EE programmer who understand and use EJB very well. It was more difficult when EJB 2.0 was around but much better with EJB 3.0 and EJB 3.1. Please share if you have any other interesting EJB interview question or if you know answer of any EJB question shared here.

Other interview question to prepare for J2EE interviews:

No comments:

Post a Comment

Java67 Headline Animator