Online Tutorials & Training Materials | STechies.com
Register Login
Advertisement

EJB Interview Questions and Answers

|| 0

EJB Interview Questions and Answers
Stechies

What is EJB and what does EJB stand for?

EJB stands for Enterprise Java Beans that is a Java application-programming interface. It is a server-side API and is used for developing enterprise applications which are large, high performing and scalable. Any EJB application can be executed in a server that complies with the J2EE 1.3 standards.

What are some of the important features of EJB?

The important features of EJB are as follows:

  • The EJB architecture is scalable, portable, distributed and transactional.
  • EJB components do not contain any system level programming and have only business logic.
  • EJB components are platform independent and are coded in Java.
  • The life cycle of EJB instances is managed by the EJB container.

What is EJB container?

An EJB container is also called the application server that is an environment used for executing applications. It handles the security authorization and transactional management of an application so that the developer can focus on the important business logic.

The container also handles object pooling and life cycle management. Commonly used EJB containers are Glassfish, JBoss and Weblogic.

What are session beans in EJB?

A session bean is a bean component developed by the client for storing the session data for a specific session. It performs different operations for the client. In the case of system failure, the session bean cannot be recovered. The bean is transactional but can be stateless or stateful. They get destroyed as soon as the session gets over.

How many types of session beans are available in EJB?

The different types of session beans are available in EJB are:

  • Stateful session beans
  • Stateless session beans
  • Singleton session beans

What is stateless and stateful session bean in EJB?

A stateless session bean does not maintain the state across client conversations and method invocations. A client can use any instance of a stateless bean. The client state is not retained when the method is finished.

A stateful bean holds the state of a session between a client and a bean. Each session is associated with a specific client.

What is the use of EJB in a web application?

EJB is used for creating the business logic of web applications. They provide assistance while implementing such logic. They are used for pooling if the beans, injecting the entity manager and developing transactional logic.

How to call EJB from Java class?    

EJB can be called from a Java class by performing a lookup. A Lookup with a JNDI name can be used to obtain the EJBObject instance.

How is EJB different from Java beans?

EJB

Java beans

EJB is a business component that can be remotely executed on a server.  

 

It is a local process that is executed on the client side.

It is a remote object and is nonvisual.

It can be visible or nonvisible during execution time.

It has a deployment descriptor that states its functions to an IDE.

It has a properties interface that describes the functionality to an IDE.

Why don’t we use static in Java EE EJB?

Static class fields that are not final are not allowed in EJB because they make it very difficult to distribute. These static class can behave differently when they run in a single JVM (Java Virtual Machine) which can create problems.

How to get the primary key value after insert in EJB?

The primary key can be obtained by inserting some code in jbosscmp-jdbc.xml file when using JBoss. The code is as follows:

<create-table>false</create-table>

<remove-table>false</remove-table>

This code has to be added to the entity’s function.

What are the six transaction attributes that can be assigned to EJB methods?

The six transaction attributes that can be assigned to EJB methods are:

  • Required
  • RequiresNew
  • NotSupported
  • Mandatory
  • Never
  • Supports

Which EJB protocol is used for communication?

EJB uses the RMI-IIOP protocol that stands for Internet Inter-ORB Protocol is used for communication that uses a Common Object Request Broker Architecture (CORBA). The IIOP protocol is used for distributed communication and can be executed on all platforms. Here RMI stands for Remote Method Invocation that is used for transferring messages from one JVM to another over a network.

How to check the EJB version?  

The EJB version can be checked by the following ways:

  • The EJB-jar.xml and application.xml file have to be checked. The version is present in the beginning lines of the XML file.
  • The ejb-jar.xml deployment descriptor can be used to find the version of EJB.

What is a home interface in EJB?

The home interface is an interface that has methods that can be associated with all EJB of a class. It specifies the methods used by a client for developing and retrieving a bean instance. For creating a bean instance, the create method is used. For every creates method an ejbCreate method has to be defined.

Where is ejb-jar.xml located?

The ejb-jar.xml file is located in the following places:

  • In case of a WAR, it is located in the /WEB-INF directory.
  • In case of a JAR, it is located in the /META-INF directory.

What is an EJB singleton?

A singleton session bean is initialized for an application and has a lifetime equal to that of the application. These sessions are created so that a single bean instance can be shared by different clients. The singleton session beans are capable of handling web service endpoints. In case of a server crash or a system shutdown, the session does not maintain the state.

Why should we use EJB over Spring?

The reasons to choose EJB over Spring bean are as follows:

  • EJB has better support for Web services like JAS-WS 2.0 than
  • Messaging is easy in EJB through Message Driven beans whereas Spring needs to be configured for messaging.
  • EJB provides better security through JAAS whereas configuration needs to be added to Spring.

What is the difference between EJB and J2EE?

J2EE is a platform for developing distributed enterprise applications that have many features lime security, state management, resource management, transaction management, etc. EJB is a part of J2EE that is an API used for developing enterprise applications. EJB make the application scalable.

What is EntityManager in EJB?

EJB has a mechanism called persistence. An EntityManager in EJB is a persistence interface that is used for performing operations like add, update, delete or find on a particular persistent entity. It is also used for executing queries through the Query interface.

Explain the difference between Context, InitialContext and Session Context.

  • Context – An EJB context has all the information that is common to both the entity bean and the session.
  • InitialContext – This is a constructor providing the initial context.
  • Session Context – This has the required information for a session bean that it will need from a container.


Advertisement