Here is a list of commonly asked interview questions about EJB.

What is EJB ?

EJB stands for Enterprise JavaBean and is a widely-adopted server side component architecture for J2EE. It enables rapid development of mission-critical application
that are versatile, reusable and portable across middleware while protecting IT investment and preventing vendor lock-in.

What is session Facade?

Session Facade is a design pattern to access the Entity bean through local interface than accessing directly. It increases the performance over the network. In this
case we call session bean which on turn call entity bean.

What is EJB role in J2EE?

EJB technology is the core of J2EE. It enables developers to write reusable and portable server-side business logic for the J2EE platform.

What is the difference between EJB and Java beans?

EJB is a specification for J2EE server, not a product; Java beans may be a graphical component in IDE

What are the key features of the EJB technology?

1. EJB components are server-side components written entirely in the Java programming language
2. EJB components contain business logic only – no system-level programming & services, such as transactions, security, life-cycle, threading, persistence, etc. are
automatically managed for the EJB component by the EJB server.
3. EJB architecture is inherently transactional, distributed, portable multi-tier, scalable and secure.
4. EJB components are fully portable across any EJB server and any OS.
5. EJB architecture is wire-protocol neutral–any protocol can be utilized like IIOP,JRMP, HTTP, DCOM,etc

Are enterprise beans allowed to use Thread.sleep()?

Enterprise beans make use of the services provided by the EJB container, such as life-cycle management. To avoid
conflicts with these services, enterprise beans are restricted from performing certain operations: Managing or synchronizing threads

Is it possible to write two EJB’s that share the same Remote and Home interfaces, and have different bean classes? if so, what are the advantages/disadvantages?

It’s certainly possible. In fact, there is  an example that ships with the Inprise Application Server of an Account interface with separate implementations for
CheckingAccount and SavingsAccount, one of which was CMP and one of which was BMP.

Is it possible to specify multiple JNDI names when deploying an EJB?

No. To achieve this you have to deploy your EJB multiple times each specifying a different JNDI

Is there any way to force an Entity Bean to store itself to the db? We can’t  wait for the container to update the db, we need to do it NOW! Is it possible?

Specify the transaction attribute of the bean as RequiresNew. Then as per section of the EJB v 1.1 spec EJB container automatically starts a new transaction before the method call. The container also performs the commit protocol before the method result is sent to the client.

READ  Deploying and testing Stateless Session Bean