InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
How EJB Container handles exceptions? |
|
Answer» When Application Exception occurs, ejb container intercepts the exception but returns the same to the client as it is. It does not roll back the transaction unless it is specified in code by EJBContext.setRollBackOnly() method. EJB Container does not wrap the exception in case of Application Exception. When System Exception occurs, ejb container intercepts the exception, rollbacks the transaction and start the clean up tasks. It wraps the exception into RemoteException and throws it to the client. |
|
| 2. |
What is System level Exception in EJB? |
|
Answer» Any exception which is not caused by business logic or business code. RuntimeException, RemoteException are SystemException. For example, error during ejb lookup.Then EJB container treats such exception as System level exception. |
|
| 3. |
What is Application level Exception in EJB? |
|
Answer» If business rule is voilated or exception occurs while executing the business logic. Then EJB container treats it as Application level exception. |
|
| 4. |
What is EJBQL? |
|
Answer» EJB 3.0, ejb query language is quite handy to write custom queries without worrying about underlying database details. It is quite similar to HQL, hibernate query language and is often referred by name EJBQL. |
|
| 5. |
Explain annotation in EJB to do the database entity relationships/mappings. |
|
Answer» EJB 3.0 provides option to define database entity relationships/mappings like one to one, one to many, many to one and many to many relationships. Following are the relevant annotations:
|
|
| 6. |
What is JNDI? Explain its terms in terms of EJB. |
|
Answer» JNDI stands for Java Naming and Directory Interface. It is a set of API and service interfaces. Java based applications use JNDI for naming and directory services. In context of EJB, there are two terms:
|
|
| 7. |
Which are the attributes of Container Managed Security? |
|
Answer» EJB 3.0 has specified following attributes/annotations of security which EJB containers implement:
|
|
| 8. |
Which are the attributes of Bean Managed Transactions? |
|
Answer» In Bean Managed Transactions, Transactions can be managed by handling exceptions at application level. Following are the key points to be considered:
|
|
| 9. |
Which are the attributes of Container Managed Transactions? |
|
Answer» EJB 3.0 has specified following attributes of transactions which EJB containers implement:
|
|
| 10. |
What is Bean Managed Transactions? |
|
Answer» In this type, developer manages the life cycle of transaction states. |
|
| 11. |
What is Container Managed Transactions? |
|
Answer» In this type, container manages the transaction states. |
|
| 12. |
Explain ACID in context of transaction management. |
Answer»
|
|
| 13. |
What ACID stands for? |
|
Answer» ACID stands for Atomic, Consistent,Isolated and Durable. |
|
| 14. |
Which types of java classes can be mapped using Lob annotation? |
|
Answer» Following java types can be mapped using Lob annotation:
|
|
| 15. |
Explain Lob annotation. |
|
Answer» EJB 3.0 provides support for Blob and Clob types using Lob annotation. |
|
| 16. |
Explain Embeddable annotation. |
|
Answer» EJB 3.0 provides option to embed JAVA POJO (Plain Old Java Object) into an entity bean and allows to map column names with the methods of the embedded POJO class. A java POJO to be embedded must be annotated as Embeddable. |
|
| 17. |
What is method level interceptor in EJB? |
|
Answer» Method level interceptor is invoked for a particular method of the bean. Method level interceptor can be applied both by annotation of via xml(ejb-jar.xml). |
|
| 18. |
What is default interceptor in EJB? |
|
Answer» Default interceptor is invoked for every bean within deployment.Default interceptor can be applied only via xml (ejb-jar.xml). |
|
| 19. |
What is class level interceptor in EJB? |
|
Answer» Class level interceptor is invoked for every method of the bean. Class level interceptor can be applied both by annotation or via xml(ejb-jar.xml). |
|
| 20. |
What is an EJB Interceptor? |
|
Answer» EJB 3.0 provides specification to intercept business methods calls using methods annotated with AroundInvoke annotation. An interceptor method is called by ejbContainer before business method call it is intercepting. |
|
| 21. |
How EJB implements dependency injection? |
|
Answer» EJB 3.0 specification provides annotations which can be applied on fields or setter methods to inject dependencies. EJB Container uses the global JNDI registry to locate the dependency. |
|
| 22. |
Which annoatation is used to inject SessionContext into an ejb? |
|
Answer» Resource annotation is used to inject SessionContext into an ejb. |
|
| 23. |
Which annoatation is used to inject singleton services like timer service into an ejb? |
|
Answer» Resource annotation is used to inject singleton services like timer service into an ejb. |
|
| 24. |
Which annoatation is used to inject an datasource into an ejb? |
|
Answer» Resource annotation is used to inject an datasource into an ejb. |
|
| 25. |
Which annoatation is used to inject an ejb into another ejb? |
|
Answer» EJB annotation is used to inject other EJB reference. |
|
| 26. |
What is a timer service in EJB? |
|
Answer» Timer Service is a mechanism using which scheduled application can be build. For example, salary slip generation on 1st of every month. EJB 3.0 specification has specified Timeout annotation which helps in programming the ejb service in a stateless or message driven bean. EJB Container calls the method which is annotated by Timeout. EJB Timer Service is a service provided by Ejb container which helps to create timer and to schedule callback when timer expires. |
|
| 27. |
What are the callback annotations for entity bean? |
|
Answer» Following is the list of callback annotations for entity bean:
|
|
| 28. |
What are the callback annotations for message driven bean? |
|
Answer» Following is the list of callback annotations for message driven bean:
|
|
| 29. |
What are the callback annotations for stateful bean? |
|
Answer» Following is the list of callback annotations for stateful bean:
|
|
| 30. |
What are the callback annotations for stateless bean? |
|
Answer» Following is the list of callback annotations for stateless bean:
|
|
| 31. |
What is Callback in EJB? |
|
Answer» Callback is a mechanism by which life cycle of an enterprise bean can be intercepted. EJB 3.0 specification has specified callbacks for which callback handler methods are to be created. EJB Container calls these callbacks. We can define callback methods in the ejb class itself or in a separate class. EJB 3.0 has provided many annotations for callbacks. |
|
| 32. |
Explain javax.ejb.PostActivate annotation. |
|
Answer» javax.ejb.PostActivate annotation is used to specify callback method of ejb lifecycle. This method will be called when EJB container just activated/reactivated the bean instance. This interface is used to expose the business methods to local clients which are running in same deployment/application as EJB. |
|
| 33. |
Explain javax.ejb.ActivationConfigProperty annotation. |
|
Answer» javax.ejb.ActivationConfigProperty annotation is used to specify properties required for a message driven bean. For example end point, destination, message selector etc. This annotation is passed as a parameter to activationConfig attribute of javax.ejb.MessageDrivenBean annotation.Following are its attributes:
|
|
| 34. |
Explain javax.ejb.Remote annotation. |
|
Answer» javax.ejb.Remote annotation is used to specify Remote interface(s) of a session bean. This remote interface states the business methods of the session bean (which can be stateless or stateful). This interface is used to expose the business methods to remote clients which are running in different deployment/application as EJB. Following are its attributes:
|
|
| 35. |
Explain javax.ejb.Local annotation. |
|
Answer» javax.ejb.Local annotation is used to specify Local interface(s) of a session bean. This local interface states the business methods of the session bean (which can be stateless or stateful). This interface is used to expose the business methods to local clients which are running in same deployment/application as EJB. Following are its attributes:
|
|
| 36. |
Explain javax.ejb.EJB annotation. |
|
Answer» javax.ejb.EJB annotation is used to specify or inject a dependency as ejb instance into another ejb. Following are its attributes:
|
|
| 37. |
Explain javax.ejb.MessageDrivenBean annotation. |
|
Answer» javax.ejb.MessageDrivenBean annotation specifies that a given ejb class is a message driven bean.Following are its attributes:name - Used to specify name of the message driven bean.messageListenerInterface - Used to specify message listener interface for the message driven bean.activationConfig - Used to specify the configuration details of the message-driven bean in operational environment of the message driven bean.mappedName - Used to specify the JNDI name of the message driven bean.description - Used to provide description of the message driven bean. |
|
| 38. |
Explain javax.ejb.Stateful annotation. |
|
Answer» javax.ejb.Stateful annotation specifies that a given ejb class is a stateful session bean.Following are its attributes:
|
|
| 39. |
Explain javax.ejb.Stateless annotation. |
|
Answer» javax.ejb.Stateless annotation specifies that a given ejb class is a stateless session bean.Following are its attributes:
|
|
| 40. |
Is Message Driven bean a stateless bean? |
|
Answer» Message driven bean is a stateless bean and is used to do task asynchronously. |
|
| 41. |
What are the key components of persistence API in EJB? |
|
Answer» Following are the key components of persistence API in EJB:
|
|
| 42. |
What are the differences between stateful session bean and stateless session bean? |
|
Answer» Following are the differences between stateful session bean and stateless session bean:
|
|
| 43. |
What a remote session bean is used in EJB? |
|
Answer» if ejb client is in different environment where ejb session bean is to be deployed then we use remote session bean. |
|
| 44. |
When a local session bean is used in EJB? |
|
Answer» If ejb client is in same environment where ejb session bean is to be deployed then we use local session bean. |
|
| 45. |
What is Message Driven Bean in EJB? |
|
Answer» A message driven bean is a type of enterprise bean which is invoked by EJB container when it receives a message from queue or topic. Message driven bean is a stateless bean and is used to do task asynchronously. |
|
| 46. |
What is Entity Bean in EJB? |
|
Answer» Entity beans represents persistent data storage. User data can be saved to database via entity beans and later on can be retrived from the database in the entity bean. |
|
| 47. |
What is Stateless Session Bean in EJB? |
|
Answer» A stateless session bean is a type of enterprise bean which is normally used to do independent operations. A stateless session bean as per its name does not have any associated client state, but it may preserve its instance state. EJB Container normally creates a pool of few stateless bean's objects and use these objects to process client's request. Because of pool, instance variable values are not guaranteed to be same across lookups/method calls. |
|
| 48. |
What is Stateful Session Bean in EJB? |
|
Answer» A stateful session bean is a type of enterprise bean which preserve the conversational state with client. A stateful session bean as per its name keeps associated client state in its instance variables. EJB Container creates a separate stateful session bean to process client's each request. As soon as request scope is over, statelful session bean is destroyed. |
|
| 49. |
What is a Session Bean in EJB? |
|
Answer» Session bean stores data of a particular user for a single session. It can be stateful or stateless. It is less resource intensive as compared to entity beans. Session bean gets destroyed as soon as user session terminates. |
|
| 50. |
What are the benefits of EJB? |
|
Answer» Following are the key benefits of EJB.
|
|