Exploring Enterprise Java Beans – Series II

Learning EJB

Learning EJB

Introduction: In this EJB II series, our main objective is to take some of the most important features of EJB and answer the related concepts. EJBs are there for a long time in the market, and they are widely used in many large scale applications. But, some time, we find it difficult to answer the specific questions asked in the forum, interviews or discussions. So, this compiled list of questions and answers will definitely give you some idea on the related concepts.







What are the two other life cycle stages available for stateful session bean?

Answer: Two other life cycle stages are
a) PrePassivate callback
b) PostActivate callback

Is there any time out value for stateful session beans?

Answer: Yes, there is a time out value for stateful session beans. If the bean is not used during the time out value then it is deleted by the container itself. But it is always advisable to remove the bean after its use without relying on the time out mechanism.

What is the usage of interceptors in session beans or MDBs?

Answer: Interceptors are generally used to check validation, security checks before the invocation of business logic methods.

What is a default interceptor?

Answer: Default interceptor is a concept provided by the EJB 3.0 specification. It is not defined by any annotation rather it has to be written explicitly in the deployment descriptor of the EJB module.

What is the order of execution of different interceptors?

Answer: They are invoked in the following order
a) Default interceptor
b) Class interceptor
c) Method interceptor

Is it possible to disable invocation of any interceptor?

Answer: Yes, Annotations like @ExcludeDefaultInterceptors and @ExcludeClassInterceptors can be used to disable invocation.

What is dependency injection in EJB 3.0 specification?

Answer: Dependency injection is a powerful way of obtaining Java EE resources without any JNDI look up. It makes the application loosely coupled.

What is the annotation used for EJB injection into a client code?

Answer: The ‘@EJB annotation’ is used to inject session beans into a client.

What is the annotation used for resource injection?

Answer: The ‘@Resource’ annotation is used for injecting resources.

Why setter injection is used?

Answer: The resources should not be directly injected into application code. The resources should be separated in a different component and it will make the code more flexible. The setter injection is used to serve this purpose.

What is the usage of deployment descriptor?

Answer: All the tasks in EJB 3.0 is done by annotations. But the same can be performed by using deployment descriptor.

What are the two name spaces available in EJB 3.0 feature pack?

Answer: Following are the two name spaces available
a) JVM-scoped ejblocal: name space
b) Global JNDI name space







What is the name of the format used for packaging java enterprise applications?

Answer: The name of the format is enterprise application archive (EAR).It contains all other modules like WAR, RAR etc.

What is the name of the deployment descriptor used for deploying java enterprise application?

Answer: The name of the deployment descriptor is ejb-jar.xml.

What are the two default bindings used by the container?

Answer: The two default bindings are
a) Short binding
b) Long binding

What is short binding?

Answer: In short binding, package-qualified Java class name of the interface is only used.

How the long binding is performed?

Answer: In long binding, bean’s component ID is used as an extra qualifier along with the package-qualified interface class name.

What are the different parts of a component ID?

Answer: The component ID for EJB is formed using the enterprise bean’s application name, module name and component name.

Where do you bind local interfaces?

Answer: All local interfaces are bound into the ejblocal: name space, which is accessible only within the same JVM.

Where do you bind the remote interfaces and why?

Answer: All the remote interfaces are bound into the global-scoped name space so that they are accessible from anywhere in the Websphere product cell.

What is the best practice for all EJB related bindings?

Answer: The best practice is to group all the EJB-related bindings under the EJB context.

Where do you provide user defined binding information?

Answer: The user defined binding information is provided in a newly created file called META-INF/ibm-ejb-jar-bnd.xml.

What are the two packaging options available?

Answer: Two available options are as follows
a) Using a Java project or Java Utility project
b) Using an EJB project







What is to be edited in the deployment descriptor when using the java packaging option?

Answer: The following lines need to be added in the application.xml file
<module>
<ejb>MyEJB3Module.jar</ejb>
</module>

Do we need to add anything if use EJB packaging option?

Answer: No, if we are using the EJB project option then the IDE automatically updates the application,xml file and set a ejb-jar.xml file.

What is the usage of ejb-jar.xml file in EJB3.0 specification?

Answer: According to the EJB3.0 specification it is not required to write anything in the ejb-jar.xml file because everything is mentioned through annotations. So the main usage of ejb-jar.xml file is to override the annotations or complete the details provided by the annotations.

What persistence model is used in EJB3.0 specification?

Answer: The java persistence API (JPA) is used in EJB3.0 specification.

What is the advantage of JPA?

Answer: JPA uses a pluggable service interface model. So it is easy to use with different provider implementations.

What are the three major parts of JPA?

Answer: Following are the three major parts of JPA
a) The java persistence API
b) Object relational mapping metadata
c) Query language

What is entity in JPA?

Answer: The main object used for persistence in JPA is called entity.

Does entity extend/implement any class or interface?

Answer: No, the entity is a plain old java object and it does not extend or implement any classes or interfaces.







============================================= ============================================== Buy best TechAlpine Books on Amazon
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Enjoy this blog? Please spread the word :)

Follow by Email
LinkedIn
LinkedIn
Share