You are on page 1of 60

1. If there is a need to use relation join to improve system performance, which EJB will be used ? - correct a. Stateful b.

CMP c. Stateless d. BMP BMP 2. a. b. c. d. What is the use of DAO in Fast Lane Reader pattern - CORRECT Plug & Play Hides code complexity Easier to code Access DB to get all read-only data efficiently

Access DB to get all read-only data efficiently 3. a. b. c. d. e. e. Among the following what are supported by entity? (CB) Data encapsulation Reusability Over loading Polymorphism Inheritance Inheritance

4. a. b.

MDB holds conversation state of client - CORRECT True False

False 5. a. b. c. d. Tom wants API that removes persistent entity instance, finds entities, allows query to run on entities. What should we refer to? - CORRECT Database API JNDI API Serialize API Entity Manager

Entity Manager 6. Difference between JMS server call and MDB from any client. - CORRECT a. In MDB , JMS connection factory look for DB home object b. Client call to both JMS server and MDB is same c. None d. Queue/Topics are mapped to MDB e. JNDI lookup for Queue/Topic are not done in MDB

e. JNDI lookup for Queue/Topic are not done in MDB 7. @SequenceGenerator(name=book_sequence, sequenceName=bookId) public class Book implements Serializable What is the sequence from which the sequence gets generated ? CORRECT Null 0 1(correct ans) Exception thrown 1 initialValue public abstract int initialValue (Optional) The value from which the sequence object is to start generating.

a. b. c. d. c.

Default: 1

8. a.

What annotation is used for openConnection method (verify) @prePassivate(correct ans) @postConstruct openConnection() b. @postActivate lifecycle callback annotation @postConstruct - lifecycle callback annotation openConnection() c. @preActivate openConnection() d. @preActivate @postDestroy openConnection() e, . @preActivate choose this if above option is not given @postConstruct openConnection()

Order different

b. @postActivate lifecycle callback annotation @postConstruct - lifecycle callback annotation openConnection()

o o o o o o o o

New bean instance is created using the default constructor. Resources are injected Now the PostConstruct method is called which in our case is to open a database connection. PostActivate is called on the bean instances which have been passivated and required to be reactivated. It goes on the same cycle as being followed by PostConstruct. @PreDestroy @PrePassivate public void closeConnection()- Again @PreDestroy and @PrePassivate are Lifecycle callback annotation. The lifecycle of these annotation is as follows Bean instances in the pool are used and business methods are invoked. Once the client is idle for a period of time container passivates the bean instance. The closeConnection function is called just before container passivates the bean. If the client does not invoke a passivated bean for a period of time it is destroyed.

Depending on the bean type stateless or stateful a number of key lifecycle events can occur

creation (stateless and stateful) destruction (stateless and stateful) passivation (stateful) activation (stateful)

Lifecycle callbacks are bean methods (not exposed by the business interface) that the container calls to notify the bean about a lifecycle transition or event. When an event occurs the Container can perform an action like initialization or cleanup resources. The callback methods are called using annotations like below @PostConstruct @PostActivate public void openConnection() { try{ connection=datasource.getConnection(); } catch(Exception e) { e.printStackTrace(); } } Note

Annotation @PostConstruct @PreDestroy @PrePassivate @PostActivate

Type of EJB Stateless, Stateful, MDB Stateless, Stateful, MDB Stateful Stateful

What used for Invoke just after the bean instance is created and DI is complete Invoked just before the bean is destroyed Invoke prior to a bean instance being passivated Invoked after the bean instance is activated.

9. How are EJB references cached a. EJB Home b. EJB Home Interface c. Persistence.xml d. Servlets

To avoid a JNDI lookup for every request, cache EJB references at the servlet. 10. a. b. c. d. d. How many types of messaging are there - CORRECT 7 5 4 2 2

JMS provides two types of messaging models: publish-and-subscribe and point-to-point. 11. a. b. c. d. More persistence involving relational database - CORRECT BMP Stateful Stateless CMP

d.

CMP

most persistence tasks involving a relational database, CMP should be the first choice.

12. a. b. c. d.

Transactions can be controlled by (CB) - CORRECT Lazy loading Turning off auto-comit TX_REQUIRED Cannot be controlled completely

b. c.

Turning off auto-comit TX_REQUIRED

13. a. b. c. d.

Which of the following is implemented in EJB when you want full control over transaction - CORRECT Management API Leave it to the container JTA API JDBC API

JTA API 14. Select Object (A) from Customer As A - CORRECT Select C From Customer A

a. b.

The above two are equivalent True False (not sure)

False 15. a. b. c. In container managed txn the attributes are defined through (CB) - CORRECT Dependency Injection Annotations Deployment descriptor

Annotations c. Deployment descriptor

16. a. b. c. d.

MDB interface extends - CORRECT Javax.ejb.SessionInterface Javax.ejb.StatefulInterface Javax.ejb.StatelessInterface Javax.ejb.EnterpriseInterface

d.

Javax.ejb.EnterpriseInterface

interface MessageDrivenBean extends javax.ejb.Enterprisebean, java.io.Serializable public interface MessageDrivenBean extends javax.ejb.EnterpriseBean { public void setMessageDrivenContext(MessageDrivenContext context) throws EJBException; public void ejbRemove() throws EJBException; } 17. a. b. c. d. No large granularity by(verify) - correct Stateless SB Multiple java classes Multiple DB tables Business methods and encapsulating business rules

a.

Stateless SB

18. a. b. c. d. b.

Persistence is achieved through - correct Transaction models Java object serialization & ORM ORM Java object serialization Java object serialization & ORM

19. EJB access data rows with no business logic in them - correct a. True b. False ???????/

a.

True

20. Entities are remotely accessible

a. b.

True (ejb 2.0) False (ejb 3.0)

b.

False (ejb 3.0)

Entities can represent fine-grained persistent objects, because they are not remotely accessible components. 21. a. b. c. d. e. Not a txn attribute- correct Support Supports Supporting Supported None

Support c. Supporting d. Supported

TX_NOT_SUPPORTED will not start a transaction existing transaction is suspended TX_SUPPORTS will not start a transaction existing transaction is not suspended TX_REQUIRED will use existing transaction will start new transaction, commit when method completes TX_REQUIRES_NEW always starts new transaction, commit when complete suspend existing transaction TX_BEAN_MANAGED bean can/may use JTS interface to control transaction TX_MANDATORY must be called within a transaction *****notsupported and supports are the txn attributes 22. Cache-idle-timeout-seconds means - correct a. b. c. Application turns off caching after timeout Idle beans are destroyed from memory after timeout Idle beans are passivated after timeout

c.

Idle beans are passivated after timeout

Cache Idle Timeout Maximum time that a stateful session bean or entity bean is allowed to be idle in the cache. After this time, the bean is passivated to the backup store. The default value is 600 seconds. The corresponding EJB deployment descriptor attribute is cache-idle-timeout-in-seconds.

23. Advantages of messaging (CB) - correct a. Synchronous b. Decoupling

c. d. e.

Reliability Multiple sender & receiver All

b. c. d.

Decoupling Reliability Multiple sender & receiver refer Mastering_EJB_3(292-313).pdf

24. JANE,JAYME,ANN (radio button type qn) Select C from Customer where name like _A%E% - correct The query returns : a. None b. JAYME c. JANE d. ANN

b. c.

JAYME JANE

25. EJB QL (Query Language) used for (CB) - correct a. b. c. d. Finder methods Select methods Create methods Home business methods

a. b.

Finder methods Select methods

EJB QL is a query specification language for the FINDER and SELECT methods of entity beans with container-managed persistence (CMP). 26. Why client txn is not advisable in EJB - correct a. b. c. d. Decreases speed Small granularity DB locks Should be used

c.

DB locks

It's not advisable to use a client's transactions in the EJB environment due to potential problems with the long-running transactions that can cause database lockup. ********Long running transactions result in DB lockup 27. a. b. c. d. Advantages of using session bean for calling entity beans (CB) (verify) BMP No dependency injection CMP Dependency injection

d.

Dependency injection

28. a. b. c. d.

Which bean is best in performance correct Stateful BMP (bean managed persistence) CMP (container managed persistence) MDB (message driven bean)

d.

MDB (message driven bean)

29. a. b. c. d.

Session bean / entity bean throws __________ exception and MDB throws ______ exception- correct Remote,remote No exception,RMI RMI,remote Remote,no exception

d.

Remote,no exception

**** Enterprise Beans are distributed objects that use the Remote Method Invocation (RMI) API, so when an error occurs, an RMI remote exception is thrown. 30. a. b. c. d. Authentication of credit card when swiped is done by (verify) Stateless Steteful Entity (must be) Stateless + MDB

d.

Stateless + MDB

31. a. b. c. d.

Remote interface call by container is - correct Remote / local based on container Flexible to make remote call as network call Always network call Local call

c.

Always network call

32. EJB QL must have(CB) - correct a. Select and from b. Select and where c. Select , from and where d. Based on DB schema e. can accept parameters(could be)

Select and from

SELECT(required): Defines the return type of the query, which can be a local interface, remote interface, or a CMP field.

FROM(required): Defines the identification variable that represents the abstract schema name of an entity bean. WHERE(optional): Defines the conditional expression for the query to restrict the returned results. 33. a. b. c. d. e. Attribute that helps to create a new txn using the existing txn - correct Supports Not supported Required Requires new Never

d.

Requires new

TX_REQUIRED will use existing transaction will start new transaction, commit when method completes

34. Isolation level for removing dirty reads, phantom and repeated reads - correct a. TRANSACTION_COMMITTED b. Serializable

Serializable **TRANSACTION_SERIALIZABLE - Strongest level of isolation. All rows locked for duration of transaction. Can produce deadlocks A transaction ensures that no other transaction can read or write to the data it accesses. Dirty reads, nonrepeatable reads and phantom reads are not possible. **TRANSACTION_REPEATABLE_READ - Dirty reads and nonrepeatable reads are not possible, but phantom reads are. ** TRANSACTION_READ_COMMITTED - Dirty reads are not possible, but nonrepeatable reads and phantom reads are. ** TRANSACTION_READ_UNCOMMITTED - Dirty reads, nonrepeatable reads, and phantom reads are possible. Refer Mastering_EJB_3(292-313).pdf page no 310

35. a. b. c.

Which of the following is used when a stateful bean calls a stateless bean from the same container - correct Local Remote Any

a.

Local

**Session Beans that can be either "Stateful", "Stateless" or "Singleton" and can be accessed via either a Local (same JVM) or Remote (different JVM) interface or directly without an interface[3], in which case local semantics apply. All session beans support asynchronous execution for all views (local/remote/no-interface). **Message Driven Beans (also known as MDBs or Message Beans). MDBs also support asynchronous execution, but via a messaging paradigm. 36. MDB is - correct a. Stateful bean b. Stateless session bean

b.

Stateless session bean

Stateless: Message-driven beans are stateless. This means message-driven beans such as stateless session beans cannot hold client state. As a result, they are not specific for a single client. 37. a. b. c. (DD)Deployment descriptor in EJB 3.0 (CB) - correct Same as 2.0 Not needed as annotations are used Must be used when necessary

a. b.

Same as 2.0 Not needed as annotations are used

**

The deployment descriptor is used to augment or override the source code annotations. The annotations that specify the bean itself (e.g. @Stateless, @Stateful, @MessageDriven, @Service, @Consumer) cannot be overridden. The EJB 3.0 ejb.jar.xml deployment descriptor DTD specifies the majority of tags as optional in order to support annotation augmentation and overrides

38. Primary key denoted using - correct a. @Id

@Id The @Id annotation specifi es the primary key of the entity. The id attribute is a primary key candidate. 39. Jboss detects code changes, deploys those files- correct a. True b. False 40. Which of the following is not used to transform a POJO entity - correct i. DAO 41. Select c.name , a.address from customer c left outer join address a The above query will fetch i. Customers without address ii. Customers with address Which are valid ?(d) a. i b. ii c. both d. none

both 42. In publish / subscribe messaging (CB) - correct a. There can be many receivers b. The receiver need not stay connected

There can be many receivers b. The receiver need not stay connected

43. Which of the following are not generator types (CB) (verify)

a. TABLE b. NULL c. IDENTITY d. ENTITY e. none

NULL ENTITY There are four generator class types, Identity, Sequence, Table and Auto. **Types Generator id table, table generator, sequence generator 44. a. b. c. d. Java objects mapped to relational DB - correct ORM (object relational maping) JPA (java persistence api) Persistence Entity

ORM (object relational maping)

45. Which method must be implemented in CMP - correct a. b. ejbCreate() atleast one ejbFindXXX()

ejbCreate() *** The entity bean class MUST implement the BUSINESS methods, and the ejbCreate<METHOD> and ejbPostCreate<METHOD> methods 46. MessageListener has - correct a. Has only one method b. Has one method c. Hes two methods d. Methods can be added e. Marker interface

Has only one method The MessageListener interface is a part of the JMS API. This interface defines the onMessage() method that the container calls to invoke your bean. The following code snippet shows the MessageListener interface: interface MessageListener { public void onMessage(Message message)

} It's interesting to consider why the MDB implements the MessageListener interface separately from the MessageDrivenBean interface. Why not just put the onMessage() method, MessageListener's only method, 47. Which of the following is valid declaration of remote interface - correct a. @Remote b. remote

a.

@Remote

48. select object(a) from customer c where c.i in (1,2) the query fetches records for which a. i is in position 1 b. i is in position 2 c. i is either in position 1 0r 2 d. none

i is either in position 1 0r 2 49. a. b. c. d. which for the foll is specified while converting java.util.Date to native SQL type - correct java.persistence.DateType javax.persistence.TemporalType java.persistence.SysDateType java.persistence.CalenderType

b.

javax.persistence.TemporalType

*** The javax.persistence.TemporalType passed in as a parameter to the setParameter( ) method tells the Query interface what database type to use when converting the java.util.Date or java.util.Calendar parameter to a native SQL type. 50. a. b. C. Isolation levels can be specified by - correct Deployment descriptor Annotation (could be) None

None Refer Mastering_EJB_3(292-313).pdf page no 314 chapter 10 51. a. b. c. d. e. Remote calls use (CB) - correct RMI/IIOP TCP/IP TCP IIOP/RMI RPC

RMI/IIOP b. TCP/IP Remote Method Invocation (RMI) and RMI-IIOP: RMI is a communication API to invoke remote methods of distributed applications. EJB clients use RMI to communicate with Enterprise Beans. RMI-IIOP is the more recent version of RMI that use the Internet Inter-ORB Protocol (IIOP) of the Object Management Group (OMG) for communication. You use RMI-IIOP to integrate Enterprise Beans with Common Object Request Broker Architecture (CORBA) applications. 52. EntityManager reference can be obtained from inside or outside of EJB container - verify a. True

b.

False

True An EntityManager instance can be acquired both from within the EJB container (Java EE) and outside it (Java SE). This offers clients the flexibility to interact with persistent entity beans in a uniform way, without regard to whether the persistence code is running inside or outside the EE container. 53. a. b. c. d. e. Which of the following does not raise an exception when a method is not called from within a txn - correct REQUIRED REQUIRES_NEW NEVER SUPPORTS NOT_SUPPORTED

c.

NEVER

54. EntityManager can flush data before query ends -correct a. True b. False

True If you would like to control the way a flush() call executes, you may call setFlushMode() before hand. The flush modes are as follows:

COMMIT - Flushing occurs only at transaction commit, or when flush() is called. AUTO - (Default) Flushing occurs before any query execution.

55. Select object(p) from Player p -correct When findAll method is implemented in LocalPlayerHomeInterface the query returns objects of type i. Player ii. LocalPlayer a. i b. ii c. i & ii

c.

i & ii

56. Exception that occur when there is no JNDI lookup match - correct BindingException NamedDoesNotExsistExption NullPointerException DoesNotExsistNamedException

NamedDoesNotExsistExption DoesNotExsistNamedException

*Ans NameNotFoundException NameNotFoundException from JNDI lookup operation There are three causes for a NameNotFoundException: The lookup name is incorrect. The object being looked up is not bound. Two servers with the same name running on the same host are being used to interoperate.

57. Property not annotated but serialized is mapped to column using - correct @Embedded @embeddable @basic @Serialized

@basic if the type of the property is Serializable, it is mapped as @Basic in a column holding the object in its serialized version 58. Design pattern for Read only - correct FastReader AbstractFactory Fastline Reader Singleton

Fastline Reader **The Fast Lane Reader design pattern provides a more efficient way to access tabular, read-only data. The Fast Lane Reader design pattern provides a more efficient way to access tabular, read-only data. 59. MessageListener class is - correct Has one method Is a marked interface Has 2 methods * Ans [ onMessage() ]

Has one method 60. Coarse grained EJB are Fast Slow Difficult to maintain Serializable

Fast Coarse-Grained EJBs Are Faster 61. @Entity @Table Public class entitybean { } What will the table name for this snippet? - correct Same as the class name (i.e. entitybean) Null

None Entity

Same as the class name (i.e. entitybean) Refer mastering ejb chapter 9 ,page 230

62. For which option use of EJB not preferred - correct Fast processiong Transacion processing Security maintenance Content presentation

Content presentation

The major operations of managing transactions, state, multithreading, connection pooling etc. will be managed by the EJB container. The security is also provided by the EJB container.

63 . EJBHomeFactory pattern is used for - correct EJBHome implementation dynamically Satatic home obj lookups Catching EJBHome Objects Factory of EJBHome obj catched for future ref

Factory of EJBHome obj catched for future ref

Abstract EJBHome lookup code into a reusable EJBHomeFactory which can cache EJBHomes for lifetime of the client application.

64. SELECT ac FROM acct AS ac WHERE id in(1,2) Selects id at position 1 Selects id at position 2 Selects id at position 1 or postion 2

Selects id at position 1 or postion 2 65. Default value of @Entity CMP (P) BMP Entity

CMP (P) 66. 17. Messages uses ___ protocol and RMI uses ____ protocol - correct TCP and RMI-IIOP

TCP/IP and RMI-IIOP RMI and TCP RMI-IIOP and TCP

TCP/IP and RMI-IIOP 67. How to limit flush to only after the execution is complete - correct setFlushMode(FlushModeType.COMMIT) setFlush(FlushModeType.COMMIT) None

setFlushMode(FlushModeType.COMMIT)

COMMIT - Flushing occurs only at transaction commit, or when flush() is called. AUTO - (Default) Flushing occurs before any query execution.

@Stateless public class EmployeeDemoSessionEJB implements EmployeeDemoSession { ... public void disemployEmployee(Integer employeeId, Date endDate) { em.setFlushMode(COMMIT); // Avoids find causing flush. Employee employee = (Employee)em.find("Employee", employeeId); employee.getPeriod().setEndDate(endDate); em.flush(); // Causes flush. }

68. Methods of a MDB interface - correct ejbCreate() and setMessageDrivenContext() ejbRemove() and setMessageDrivenContext() ejbactivate() and setMessageDrivenContext() ejbpassivate() and setMessageDrivenContext()

ejbRemove() and setMessageDrivenContext() package javax.ejb; public interface MessageDrivenBean extends javax.ejb.EnterpriseBean { public void setMessageDrivenContext(MessageDrivenContext context) throws EJBException; public void ejbRemove() throws EJBException; 69. What type of bean can be used for records that are read and updated frequently - correct BMP CMP Stateful Sateless

CMP 70. SELECT NEW ejb.30.entity.CustomerRef(c.firstname,c.lastname,c.refreename) FROM C - correct Creates a new CustomerRef object and puts the firstname lastname and refreename to it Illegal

Null Returns a collection of CustomerRef, which contains first name, lastname and refreename of all rows

Creates a new CustomerRef object and puts the firstname lastname and refreename to it 71. Who is Consumer in Topic..? - correct Topic Destruction. Topic subscriber Topic Messages. Topic publisher. Topic consumer.

TopicSubscriber Enables a client to receive a published message from a topic. 72 @version is used in beans that change less frequently. - correct True false

false

73. MDBs are like ______ Stateless beans 74. A large code regarding bean managed transaction (check for the comments) The answer is the option ut=sc.getTransaction(); // to get transaction from sessioncontext 75. MDBs used which of the annotations (verify) a. Postconstruct b. Predestroy @Resource @MessageDriven

@Resource @MessageDriven MDB support the smallest number of annotations, in fact @MessageDriven and @ActivationConfigProperty are the only two MDB specific annotations.

The code for the SimpleMessageBean class illustrates the requirements of a message-driven bean class:

It must be annotated with the @MessageDriven annotation if it does not use a deployment descriptor. The class must be defined as public. The class cannot be defined as abstract or final. It must contain a public constructor with no arguments. It must not define the finalize method.

It is recommended, but not required, that a message-driven bean class implement the message listener interface for the message type it supports. A bean that supports the JMS API implements the javax.jms.MessageListener interface. Unlike session beans and entities, message-driven beans do not have the remote or local interfaces that define client access. Client components do not locate message-driven beans and invoke methods on them. Although message-driven beans do not have business methods, they may contain helper methods that are invoked internally by the onMessage method.

For the Application Server, the @MessageDriven annotation typically contains a mappedName element that specifies the JNDI name of the destination from which the bean will consume messages. For complex messagedriven beans there can also be an activationconfig element containing @ActivationConfigProperty annotations used by the bean. See A Java EE Application That Uses the JMS API with a Session Bean for an example. The onMessage method is called by the beans container when a message has arrived for the bean to service. This method contains the business logic that handles the processing of the message. It is the message-driven beans responsibility to parse the message and perform the necessary business logic. The onMessage method has a single argument: the incoming message. The signature of the onMessage method must follow these rules:

The return type must be void. The method must have a single argument of type javax.jms.Message.

76. Select one of the options dat best describes Entity beans(so many options with large codes will be given) The answer is mostly ITS A POJO CLASS WITH ANNOTATIONS 77. Diff between stateless and stateful bean: Stateful can use return values of one method in another but stateless cant do it 78. a. b. c. d. Which is not a valid bean state? - correct Does Not Exist Ready Pooled No State

No State The lifecycle of an entity beans is divided into the following states: Non existent: The entity bean remains in this state before the container instantiate the bean. Pooled: The entity bean comes in this state after the container instantiates the bean and associates it with the context object EntityContext. The bean in this state is in an instance pool with other entity bean instances. Ready: The entity bean comes in the ready state when the container calls the ejbCreate() method on the bean. The bean in this state gets associated with the clients EJB object and represents the specific data. The container calls the business methods on a bean instance when the instance is in the ready state

79. Which is a client of a session bean implementing local interface? (verify) a. Session,entity and MDB b. Stateless bean c. Stateful bean d. Client class must have a jndi lookup e. mdb(could be)

Session,entity and MDB 80.How to convert an MDB from stateless to stateful. - correct a. 81. Cannot be done

JBoss server capable of hot deploy of services keeping track of dependencies. T/F? correct True 82. Which is a consumer in Topic? MessageSubscriber Topic Subscriber 83. Which is a producer in Topic? MessagePublisher TopicPublisher 84. Which of the following is correct? correct a. b. c. d. e. EntityManager em=context.lookup(); EntityManager em=context.lookup(persistence); EntityManager em=(EntityManager)context.lookup(); EntityManager em=(EntityManager)context.lookup(persistence); EntityManager em=(EntityManager)context.lookup(java:comp/ejb/entitymanager); @Stateless public class EmployeeDemoSessionEJB implements EmployeeDemoSession { protected EntityManager em; ... public EntityManager getEntityManager() { if (em == null} try{ em = (EntityManager)(new InitialContext()).lookup("java:comp/ejb/EntityManager"); } catch (Exception e){}; } return em; } EntityManager em=(EntityManager)context.lookup(java:comp/ejb/entitymanager); 85. Why do we not have any activation or passivation in MDB like in session beans? correct as MDB receives messages at any time asynchronously 86. Match annotation with purpose: @EntityListener- Used for Entity beans call back method. @ExcludeSuperClassListener In an inheritance hierarchy, the super class listener is ignored in the subclass @ExcludeDefaultListener DefaultListener will be ignored.

A method of the entity may be designated as a callback method to receive notification of a particular entity life cycle event. Callbacks methods are annotated by a callback annotation. You can also define an entity listener class to be used instead of the callback methods defined directly inside the entity class. An entity listener is a stateless class with a no-arg constructor. An entity listener is defined by annotating the entity class with the @EntityListeners annotation

You can stop the entity listeners inheritance by using the @ExcludeSuperclassListeners, all superclasses @EntityListeners will then be ignored.

public @interface ExcludeDefaultListeners

Specifies that the invocation of default listeners is to be excluded for the entity class (or mapped superclass) and its subclasses.

87. Which protocol is used for remote calls? -correct RMI-IIOP RMI 88. Which declaration of local interface is correct? correct There was only one option with @Local annotation. 89. If an object is not found during JNDI lookup what exception is thrown? NamingException /NameNotFoundException 90. What has replaced entity beans? correct a. Persitence API b. Database API

Persitence API Entity Beans were replaced by the Java Persistence API in EJB 3.0, though as of 2007, CMP 2.x style Entity beans are still available for backward compatibility 91. If there are too many entities with the EntityManager which of the following should be used? correct a. b. c. d. EntityManager.clear() (must be .remove()) EntityManager.delete() EntityManager.discard() EntityManager.save()

EntityManager.clear() (must be .remove()) 92. Purpose of Service Locator pattern The Service Locator hides the lookup process's implementation details and complexity from clients. The Service Locator pattern locates J2EE (Java 2 Platform, Enterprise Edition) services for clients and thus abstracts the complexity of network operation and J2EE service lookup as EJB (Enterprise JavaBean) Home and JMS (Java Message Service) component factories. The Service Locator hides the lookup process's implementation details and complexity from clients. To improve application performance, Service Locator caches service objects to eliminate unnecessary JNDI (Java Naming and Directory Interface) activity that occurs in a lookup operation.

93. What exception is thrown by EntityManager.find()?. (verify) Returns null IllegalStateException IllegalArgumentException Shefa told returns null find <T> T find(Class<T> entityClass,

Object primaryKey) Find by primary key. Parameters: entityClass primaryKey Returns: the found entity instance or null if the entity does not exist Throws: IllegalStateException - if this EntityManager has been closed. IllegalArgumentException - if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary key

94. What is the XML tag used to set max pool size? max-pool-size the XML tag used to set max pool size max-pool-size 95. Concept of MOM? Ans: client---middleware---server/message oriented middleware 96.What semantics is used by application server to call a remote interface? - verify RMI RMI-IIOP 97. Which bean is used to manage interaction between different entity beans? - verify Session Beans Session beans are used to manage the interactions of entity and other session beans,access resources, and generally perform tasks on behalf of the client. 98. Optimisation of SQL call is present in which EJB? -correct a. CMP b. BMP c. Stateful d. Stateless CMP Another feature of CMP that makes it attractive is its ability to manage optimization of the set of SQL calls that must be made in order to read or write the persistent state of an EJB. CMP:: Advantages: 3)Optimization of SQL code will be done BMP:: Disadvantages: 3)Optimization of SQL code cannot be done by the container because bean it self contains the code. 99. When does Unrepeatable problem occur? -correct

a. b. c.

When one transaction deletes a record and another reads it When one transaction reads a record and another updates it None

b.

When one transaction reads a record and another updates it

The unrepeatable read problem can be described by the following scenario: n Transaction 1 reads account id and balance for all accounts with balance less than 150. n Transaction 2 updates an account entity changing its balance from 100 to 200. n Transaction 1 reads the data again including detailed information such as account name n An account which appeared in the initial summary read is not present in the second detailed read.

100. Why entity beans are called transactional resources? (Expln: Cos they access DB for storing data often) a Cos theyre used in transactions and access DB for storing data 101. The transaction type in persistence.xml is set to JTA transaction. What is the data source used? -correct a. JTA-source b. JTA-persistence c. Resource-local d. None

JTA-source The Java Transaction API (JTA) and non-JTA data sources to be used for an application can be specified through the <jta-data-source> and <non-jta-data-source> elements of the persistence.xml file within an Enterprise JavaBeans (EJB) module.

102. JMSConnectionFactory is ________ (Expln: Factory to get connection object with JMS server) -correct a. Factory to get JMSConnection object b. Factory to get Connection object c. Factory to get JNDCConnection object

Factory to get Connection object 103. Whats the technology that enables you to assign request priority to an EJB component? (Sorry, no options again Request partitioning )

103. How is performance improved by Service Locator pattern? The Service Locator hides the lookup process's implementation details and complexity from clients.

1.

The Service Locator pattern centralizes distributed service object lookups, provides a centralized point of control, and may act as a cache that eliminates redundant lookups. It also encapsulates any vendorspecific features of the lookup process.

The Singleton pattern [ GHJV95 ] ensures that only a single instance of a class exists in an application. The meaning of the term "singleton" is not always clear in a distributed environment; in ServiceLocator it means that only one instance of the class exists per class loader.

The Singleton pattern improves performance because it eliminates unnecessary construction of ServiceLocator objects, JNDI InitialContext objects, and enables caching (see below). The Web-tier service locator also improves performance by caching the objects it finds. The cache lookup ensures that a JNDI lookup only occurs once for each name. Subsequent lookups come from the cache, which is typically much faster than a JNDI lookup.

104. A user is asked to include local and home interface of session bean in classpath. Why? Because they are require to access the bean method from the client. 105. Which annotation is used to call back annotation? -correct javax.annotation.PostConstruct The PostConstruct annotation is used on a method that needs to be executed after dependency injection is done to perform any initialization. This method MUST be invoked before the class is put into service. This annotation MUST be supported on all classes that support dependency injection. The method annotated with PostConstruct MUST be invoked even if the class does not request any resources to be injected. Only one method can be annotated with this annotation.

Specifies the life cycle callback method that the EJB container should execute before the first business method invocation and after dependency injection is done to perform any initialization. You may specify a @PostConstruct method in any bean class that includes dependency injection. Only one method in the bean class can be annotated with this annotation. If you annotate more than one method with this annotations, the EJB will not deploy. The method annotated with @PostConstruct must follow these requirements:

The return type of the method must be void. The method must not throw a checked exception. The method may be public, protected, package private or private. The method must not be static. The method must not be final.

This annotation does not have any attributes 106. Broadcasting is a concept of? -correct a. Publish/Subscribe b. Publish/POP c. Subscribe/POP . POP

Publish/Subscribe 107. Which interface is used for JMS service? MessageListener isIdentical() to know if two ejb object references are pointing to the same session object.

MessageListener

108. How are coarse grained methods helpful in improving performance Method invocation 109. Every field of entity bean is considerd persistent unless u annotate with @transcient 110. Load Balancing is done with which bean? MDB 111. Named method perfered over position method why? because they are self explanatory 112. Exception thrown when entity not created to client? create exception 113. 114. What exception is thrown by JMS server to client ? no eception is thrown What is entity bean? Pojo with annotation For system log which session bean is used? CMP 116. Difference between SQL and EJB QL - correct a)SQL navigates table and EJBQL joins related beans b)SQL joins tables and EJBQL navigates through beans 1)a 2)b 3)a and b 4)neither

115.

b 117. 2)Which gives good performance - correct 1)BMP 2)CMP 3)BMP with read only 4)CMP with read only

4)CMP with read only 118. Advantages of coarse grained EJB - correct 1)Not useful 2)reduce s method invocation

reduce s method invocation 119. 120. Differnece between number of states in stateful and stateless session beans?2 activate & passivate Difference between session and entity beans? Session Performs some logic Entity Persistence / Stores data 121. Findbypositionmethod related questions (2)? findByPosition returns a Collection and the argument must the same type as Position; 122. What does Topic session Object do? creates subscriber(both durable and non-durable) and publisher 123. AUTO_ACKNOWLEDGE property The session automatically acknowledges the message has been sent. 124. Max pool-size where it is stored?<bean-pool> 125. To access data, use JDBC directly True/False True 126. .Interface RemoteInterface { Viod createuser() } How can the bean class specify the interface RemoteInterface as remote? - correct @stateless Public class sessionbean implements RemoteInterface{ Viod createuser(){ //code } } @stateless @Remote(RemoteInterface.class) Public class sessionbean implements RemoteInterface{ Viod createuser(){ //code } } @stateless Public class sessionbean implements RemoteInterface{ @Remote(RemoteInterface.class) Viod createuser(){ //code } } None

--- option b is the answer

@stateless @Remote(RemoteInterface.class) Public class sessionbean implements RemoteInterface{ Viod createuser(){ //code } }

--- option b is the answer

127. Treating EntityBeans as fine grained wrapping them on table rows leads to increased _____ and heavier database communication - correct Network transaction Transaction Speed Performance

Network transaction 128. MDBs are ____ threaded - correct Multi Single Not Can be single/multi

Multi 129. While comparing entity objects of equality, Which is mandatory..? - correct None They have to be of same type. They have to be of same entity. We cannot compare.

They have to be of same entity. 130. Difference in number of states between stateless ans stateful session bean -2 131. Both session and entity beans can implement local and remote client views, and generally the same considerations apply. However, an entity bean must implement a local client view in what situation? A. B. C. D. When the application uses message-driven beans. When the entity bean is a target of a container-managed relationship. When the entity bean is located in a different JVM from the client. When the application uses a session bean as a facade to a set of entity beans.

B.

When the entity bean is a target of a container-managed relationship.

Answer (B): Along with container-managed persistence, the EJB 2.1 architecture allows the container to manage relationships among entity beans and maintain their referential integrity. The specification requires that entity beans implement a local client view if they use containermanaged relationships

132. The EJB 2.1 architecture includes an SQL-like query language, EJB Query Language (EJB QL), that is portable across EJB containers. This language can be used to express queries for A. B. C. D. Message-driven beans Session beans implementing remote client views Entity beans with container-managed persistence Stateless session beans

Entity beans with container-managed persistence Answer (B): The implementation class for a message-driven bean must extend the javax.ejb.MessageDrivenBean interface and a message listener interface that corresponds to the specific messaging system. For example, when JMS is the messaging system, the message listener interface is javax.jms.MessageListener.

133. An EJB application may use message-driven bean components to asynchronously receive messages provided that the messages are delivered by which message service: A. B. C. D. None of the above JMS, JAX-M, or any other messaging system Java Message Service (JMS) Java API for XML Messaging (JAX-M) Any other messaging system JMS, JAX-M, or any other messaging system

134

A message-driven bean developed for a JMS messaging system puts its business processing logic within which method: A. B. C. setSessionContext method onMessage method ejbRemove method

D. E.

setMessageDrivenContext method a user-defined method

B.

onMessage method

Answer (B): A message-driven bean using JMS extends the javax.jms.MessageListener interface, which includes a single method, onMessage. When a message arrives for the bean, the container invokes this onMessage method and that message should contain the business logic to execute upon receipt of a message.

135. If you use container-managed transaction demarcation, you can set a message-driven bean to participate in a transaction. To ensure that message delivery from the message destination to the message-driven bean is part of the subsequent transactional work, set the message-driven beans transaction attribute (in the deployment descriptor) to A. B. C. NotSupported Mandatory Required Supports Answer (C): To ensure message delivery, message consumption can be grouped into one transaction with other transactional work, such as database access, if you use containermanaged transaction demarcation and set the message-driven bean's transaction attribute to Required.

D.

C.

Required

136. B timer service is used for timing notifications. It can be used with A. B. C. D. E. F. B and C CMP entity beans both BMP and CMP entity beans message-driven beans B and C A and C None of the above B and C

Answer (D): The EJB timer service feature can be used with both BMP and CMP entity beans, as well as with stateless session beans and message-driven beans.

137. EJB Timer objects are stateless objects, with the same characteristics as stateless session beans. A. B. True False

Answer (B): Timer objects are persistent objects managed by the container. A timer object survives a crash of the container or process. Since a timer is often stored in a database or other persistent storage, even after a container restart the timer notifications can be delivered and the timer object can be accessed.

B.

False

138. An enterprise bean may set up a timer notification using the TimerService's createTimer method. Such timer notification may occur A. B. C. D. E. After a specified duration At a specified time On a recurring basis All of the above None of the above

Answer (D): The TimerService object contains four createTimer methods. EJB application code can use these four methods to create timers that expire after a specified duration or timers that expire at a specified time. In both cases, these may be one-time timers or recurring timers. All of the above

139. The J2EE 1.4 platform includes a set of Web services technologies for developing Web services applications. Developers can use the following technologies to write a Web service Java interface or service endpoint interface: A. B. C. D. Java API for XML Processing (JAX-P) and Java API for XML Binding (JAX-B) SOAP with Attachments API for Java (SAAJ) Java API for XML-based RPC (JAX-RPC) and enterprise bean components Java API for XML Registries (JAX-R)

Answer (C): Developers can write JAX-RPC service endpoint interfaces or EJB service endpoint interfaces. Java API for XML-based RPC (JAX-RPC) and enterprise bean components 140. To develop a Java interface for a Web service-the service endpoint interface-you must start with the WSDL (Web Services Description Language) document for the service.

A. B.

True False

False

Answer (B): There are two approaches for developing an interface for a new Web service. You may start by creating the Java interfaces with the business methods to be provided by the service. You then generate the associated WSDL from the Java interfaces. Or, you may start with a WSDL document for the Web service and, from this document, generate the Java service endpoint interfaces.

141. Which type of enterprise bean is particularly well suited for developing a JAX-RPC service endpoint interface for a Web service? A. B. C. D. E. A messaged-driven bean An entity bean A stateless session bean A Timer object A stateful session bean

C.

A stateless session bean

Answer (C): Web services and stateless session beans each have no specific instance identity and they share significant features of statelessness. Because Web services endpoints that are described using WSDL are stateless-they do not hold state on behalf of clients across client requests-they map nicely into stateless

142. When developing an enterprise bean as a JAX-RPC service endpoint interface for a Web service, you must adhere to the following rule: A. B. C. The bean must not extend java.rmi.Remote nor should its methods throw java.rmi.RemoteException The bean's methods must use remote reference types Deploy the bean using a special Web services deployment descriptor, webservices.xml. None of the above.

D. Deploy the bean using a special Web services deployment descriptor, webservices.xml.

Answer (C): A stateless session bean implemented as a JAX-RPC service endpoint interface must extend java.rmi.Remote and its methods must throw java.rmi.RemoteException. Likewise, the bean component must be deployed using a special Web services deployment descriptor, webservices.xml. However, the bean methods are expressly forbidden to use remote reference types.

143. Enterprise beans can be used to access Web services. To do so, the bean must: A Declare a service-ref element in its deployment descriptor that contains appropriate information to A. look up the Web service endpoint. B. C. D. Package the Web service endpoint into an ejb-jar file. Create a webservices.xml file containing the Web service. Include a JAX-RPC handler in its code.

Declare a service-ref element in its deployment descriptor that contains appropriate information to look up the Web service endpoint. 144. For a new Web service developed using enterprise beans, you must package its components into an ejb-jar file. Which of the following are not packaged into the ejb-jar file: D A. B. C. D. All classes referenced from the bean class and the interface The WSDL file The deployment descriptor for the Web service The stubs, skeletons, and serialization/deserialization code for translating SOAP requests to invocations on the bean class.

The stubs, skeletons, and serialization/deserialization code for translating SOAP requests to invocations on the bean class. 145. A local home or component interface for an EJB can only be used by: D A. Another EJB B. A web-tier client C. A business logic-tier client D. A client located in the same Java TM Virtual Machine (JVM).

client located in the same Java TM Virtual Machine (JVM). 146. Local interfaces have declarative: A A. Transactions and security B. Transactions only

C. Security only D. Neither, for performance reasons

A. Transactions and security

147. An entity in a unidirectional relationship that is the target of a role with a cmr field: A A. Must have local home and component interfaces B. Must have remote home and compnent interfaces C. May have either local or remote interfaces, but not both D. May have any combination of local or remote interfaces

. Must have local home and component interfaces 148. An entity in a unidirectional relationship that is the source of a role with a cmr field: D A. Must have local home and component interfaces B. Must have remote home and compnent interfaces C. May have either local or remote interfaces, but not both D. May have any combination of local or remote interfaces

. May have any combination of local or remote interfaces

149. The bean class for an entity that uses the EJB 2.0 model of container-managed persistence: B A. Must implement java.io.Serializable B. Is only used for better integration with popular IDEs C. Must be abstract D. Must not be abstract

Must be abstract 150. . The legal collection class type(s) to represent a many-valued relationship are: B A. java.util.Collection only B. java.util.Collection and java.util.Set C. java.util.List, java.util.Set, and java.util.Map D. java.util.Map only

B. java.util.Collection and java.util.Set 151.

. If you call a "set" abstract accessor for a cmr field, it can: C A. Throw a java.sql.SQLException B. Automatically cascade delete an entity C. Automatically change the value of cmr fields in up to three additional beans D. You can never call an abstract accessor

Automatically change the value of cmr fields in up to three additional beans 152. You can only specify cascade-delete on a relationship role if: B A. The role has a multiplicity of 'One' B. The other role in the relationship has a multiplicity of 'One' C. The role has a multiplicity of 'Many' D. The other role in the relationship does not already use cascade-delete

The other role in the relationship has a multiplicity of 'One' 153. If an entity has a relationship to another entity, it must: D A. Declare that entity reference in the deployment descriptor using the <ejb-ref> element B. Declare that entity reference in the deployment descriptor using the <ejb-local-ref> element C. Declare that entity reference in the deployment descriptor using the <ejb-link> element D. No entity reference declaration is required

No entity reference declaration is required

154. The bean developer must be cautious when iterating over a relationship collection class, because: C A. Concurrent transactions can modify the values B. Changes to its contents can violate foreign key constraints in the database C. Changes to its contents can trigger a referential integrity change to the collection class itself D. The container developer is not required to support the Iterator class's next method

Changes to its contents can trigger a referential integrity change to the collection class itself

155. The EJB 2.0 specification introduces ejbSelect methods. These are: A

A. Abstract methods in the bean class that call a query B. The local home interface equivalent of a finder method C. Methods in the component interface that call a query D. A method that allows the bean developer to choose between a local and remote interface

A. Abstract methods in the bean class that call a query 156. The new EJB Query Language (EJB-QL) has three clauses: select, from, and where. Of these: B A. Only the from clause is mandatory B. Only the select and from clauses are mandatory / may accept parameters C. Only the where clause is mandatory. D. All clauses are mandatory.

B. Only the select and from clauses are mandatory / may accept parameters 157. In EJB-QL, date and time literals are represented by: D

A. A string in the format MM-DD-YYYY HH:MM:SS +MILLISECONDS B. A string in a locale-determined format C. A string in a vendor specific format D. A long value that represents a millisecond count, such as 979837813000

long value that represents a millisecond count, such as 979837813000

158. The type of interface (local or remote) returned from an ejbSelect statement can be: B A. Specified in the query B. Specified in the deployment descriptor C. Specified by the client D. Is always a local interface

Specified in the deployment descriptor 159. The functions available for use in the where clause of an EJB-QL query are: D A. All functions defined in standard SQL B. All functions defined by the target database C. All functions with defined escapes in JDBC 2.0

D. A limited subset of the functions defined for JDBC 2.0

D. A limited subset of the functions defined for JDBC 2.0

160. What does the EJB specification architecture define? D A. B. C. D. Transactional components Distributed object components Server-side components All of the above

All of the above

161. What executes EJB components? C A. B. C. D. A web server An application server An EJB container A database server

An EJB container 162. What do enterprise beans use to communicate with the EJB container to get runtime context information? A A. B. C. D. The javax.ejb.EJBContext provided by the container A JNDI ENC context A javax.ejb.EJBHome object provided by the container A javax.ejb.EJBMetaData object provided by the container

The javax.ejb.EJBContext provided by the container 163. Through what interface does an application create, find, and remove enterprise beans? B A. B. C. D. java.rmi.Remote javax.ejb.EJBHome javax.ejb.EJBObject javax.ejb.EntityBean

javax.ejb.EJBHome 164. What type of enterprise bean is used to embody business objects? D A. B. C. D. javax.ejb.EnterpriseBean java.rmi.Remote javax.ejb.SessionBean javax.ejb.EntityBean

D. javax.ejb.EntityBean

165. What type of enterprise bean is used to embody application processing state information? C A. B. C. D. javax.ejb.EnterpriseBean javax.rmi.Remote javax.ejb.SessionBean javax.ejb.EntityBean

C. javax.ejb.SessionBean 166. What interface must the enterprise bean implement so that an application can invoke its operations? C A. B. C. D. javax.ejb.EntityBean javax.ejb.EJBHome javax.ejb.EJBObject javax.rmi.Remote

. javax.ejb.EJBObject 167. At what point, precisely, in the life-cycle is a container-managed entity bean considered created? B A. B. C. D. Immediately prior to the execution of its ejbCreate() method Immediately after the execution of its ejbCreate() method After the CMP bean's data has been committed to the underlying persistent datastore During the execution of its ejbPostCreate() method

Immediately after the execution of its ejbCreate() method

168. What distinguishes a bean-managed persistent (BMP) enterprise bean from a container-managed (CMP) enterprise bean? D

persistent

A. B. C. D.

A BMP bean must implement the ejbLoad() and ejbStore() methods A BMP bean can implement persistence to custom datastores such as legacy systems A BMP bean is responsible for managing its own persistence to a persistent datastore All of the above

All of the above 169. What is a deployment descriptor? A A. An XML file format used by the container to learn about the attributes of a bean, such as transactional characteristics and access control B. A method for transporting enterprise beans back and forth between systems C. An XML file used by enterprise bean clients to learn about the attributes of a bean, such as access control and transactional characteristics. D. A format for bundling enterprise beans for delivery to customers

An XML file format used by the container to learn about the attributes of a bean, such as transactional characteristics and access control 170. How many Local business interfaces can one EJB 3.0 Session bean have? A. 0 B. 1 C. 2 D. As many as it wants.

D. As many as it wants. 171. Given a Session bean class with the following annotations: B AND D private @EJB(name="fooejbref") Foo foo; private @Resource SessionContext sessionCtx; Which of the following could be used to retrieve the ejb dependency declared above? A. (Foo) sessionCtx.lookup("foo"); B. (Foo) sessionCtx.lookup("fooejbref"); C. InitialContext ic = new InitialContext(); (Foo) ic.lookup("java:comp/env/foo"); D. InitialContext ic = new InitialContext(); (Foo) ic.lookup("java:comp/env/fooejbref"); E A and C F B and D B and D 172. Which are valid declarations for a Local business interface?D public interface Foo1 { public void foo(); } import javax.ejb.Local; @Local public interface Foo2 { public void foo(); }

import javax.ejb.*; @Local public interface Foo3 extends EJBLocalObject { public void foo(); } import javax.ejb.*; @Local @Remote public interface Foo4 { public void foo(); } A. Foo1, Foo2, Foo3 B. All of the above C. Foo2 D. Foo1, Foo2

Foo1, Foo2 173. An interceptor class may contain:C A. AroundInvoke methods. B. Lifecycle Callback methods. C. A and B D. None of the above.

A and B 173. Given the following @EJB declarations:B @EJB(beanName="foo") Foo ref1; @EJB(beanName="foo") Foo ref2; @EJB(beanName="bar") Bar ref3; @EJB(beanName="bar") Bar ref4; Where ejb "foo" is a Stateful Session bean with Local business interface Foo and ejb "bar" is a Stateless Session bean with Local business interface Bar After injection has completed, what would be the output of the following code? System.out.println(ref1.equals(ref2)); System.out.println(ref3.equals(ref4)); A. false false B. false true C. true false D. true true

. false true 174.

Which is a valid declaration of a PostConstruct method in a Session bean class? A AND B public @PostConstruct void postConstruct1() {} private @PostConstruct void postConstruct2() {} A. postConstruct1 B. postConstruct2 C. A and B D. None of the above.

A and B 175. Given the following Message Driven Bean declaration:C @MessageDriven public class FooMsgBean implements javax.jms.MessageListener { public void onMessage(Message m) { ... } } Assuming it is deployed without an ejb-jar.xml, which best describes the transactional nature of the onMessage method ?

A. The bean has bean-managed transactions. It is the bean developer's responsibility to demarcate transactions within onMessage(). B. The bean has container-managed transactions and the onMessage method has tx attribute NOT_SUPPORTED. C. The bean has container-managed transactions and the onMessage method has tx attribute REQUIRED. D. The bean has container-managed transactions and the onMessage method has tx attribute REQUIRES_NEW.

C. The bean has container-managed transactions and the onMessage method has tx attribute REQUIRED 176 Given the following Remote business interface: @Remote public interface Hello { public String hello(); } Which exceptions can be received by the caller as a result of invoking the hello() method? A A. javax.ejb.EJBException B. java.rmi.RemoteException C. A and B D. None of the above.

javax.ejb.EJBException 177. In a Stateful Session bean, dependency injection takes place: B A. After the @PostConstruct lifecycle callback is invoked on the bean instance. B. Before any business methods or lifecycle callback methods are invoked on the bean instance. C. After the ejbCreate method is called on the bean instance. D. Stateful Session beans do not support dependency injection.

Before any business methods or lifecycle callback methods are invoked on the bean instance.

178. Which of the following results in the removal of an EJB 3.0 Stateful Session bean? D

A. Calling a business method that has been annotated with @Remove. B. Calling remove() on an EJBObject created from the bean's Adapted Home interface. C. Throwing a runtime exception from one of the bean's business methods. D. All of the above.

All of the above 179. How many number of transaction attributes available? Choices a. 6

NotSupported 2. Supports 3. Required 4. RequiresNew 5. Mandatory 6. Never b. c. d. e. 7 10 3 2

6 180. Which is intermediate between client and DB? Choices a. b. c. d. Stateless session bean Entity bean Entity manager Session bean

Entity bean 181. Which annotation is used to clean up resources such as DB connection and TCP/IP connections(CB) Choices a. javax.ejb.destroy

b. c. d.

javax.ejb.predestroy javax.ejb.passivate javax.ejbprepassivate

javax.ejb.predestroy 182. JNDI lookup methods Choices a. b. c. d. is used to locate home object is used to locate ejb object is used to locate Remote object none of the above

is used to locate home object is used to locate Remote object

183. Entitymanager.createquery() returns which object? Choices a. b. c. d. javax.persistence.query javax.persistence.queryType javax.persistence.queryImpl None

javax.persistence.query 184. On what basis the application causes creation of session bean instance? Choices a. b. c. d. Implementing classes Entity bean During application start(something like that) None

During application start

185. @Entity @Table Public class some_class_name implements serializable {& What will be the value for table Choices a. b. c. Null pointer exception Class name will default for table None Cant remember the fourth option

Class name will default for table 186. What is the purpose of performance tuning? a. b. c. d. Increase speed Fast calculation Increase memory use Cached memory

Increase speed 187. e. f. Annotation used for the mtd cleanup - correct @preDestroy @preActivate @preDestroy @prePassivate @preDestroy @preActivate

g.

h.

@prePassivate @preDestroy

188. A table has zero records and a transaction has inserted 10 records which are uncommitted and are rolled back completely before the transaction complete and another transaction tries to read the table What type of reading is this - correct Dirty Read Phantom read

Repeated Read

Dirty Read 189. How do we manage create/destroy beans - correct Tune the pool size every now and then Cache bean specific data Load data from CMP Explicit use of @remove annotation

Explicit use of @remove annotation 190. Using the annotation prePassivate ______ - correct The container never uses it The container does not tell the bean to relinquish resources heldup before passivation The container tells the bean to relinquish resources heldup before passivation None

The container tells the bean to relinquish resources heldup before passivation

191. What is isolation - correct It guarantees that the concurrent users Read the same data even if it is read multiple times Are isolated from one another even if they access the same DB Does not access the same data(correct ans)

Are isolated from one another even if they access the same DB

192. Persistence task involving relational databases. Which bean is suitable? - correct

e. CMP f. BMP g. Stateless h. Stateful

CMP 193. A question on scope of lifetime of persistent context when a transaction occurs Transaction persistenceTransaction none

Transaction 194. How many receivers can exsist with POP and Publish/Subscribe type of Messaging models (verify) Only one and atleast one(if multiple choice ques, mark this also) Only one and many(correct ans) One or more and only one Many and only one

Only one and many 195. Exception when NEVER is used in trasaction - correct RemoteException TransactionException TransactionRequired RequiredException EJBException

EJBException ** If the client is running within a transaction and invokes the enterprise bean's method, the container throws a RemoteException. If the client is not associated with a transaction, the container does not start a new transaction before running the method. If the client calls with a transaction context, the Container throws the java.rmi.RemoteException exception if the client is a remote client, or the javax.ejb.EJBException if the client is a local client.

196. Query retrieved by.. a.Convection object. b.Session Object

Session Object 197. Which can generate Primary key automatically a.@Id @GenertedValue

200. You have got Client.java,web.xml,RemoteInt.java but still your are not able to make an application complete what is missing a . persistence.Xml b. persistenc-config.xml c. ejb-config.xml d. ejb.xml

persistence.Xml 201. select OBJECT(P) from customer p i. ----------------------ii. p is not persietent 202. How annotations are automatically generated a. @Id ServerGenerate b. @Id automatic c. @Id Generated d.-----------------203. How do you make non-static non-transient as non-persistent..bla bla bla a. b. c. d. @persistent @non-persistent @Transient @basic

@Transient 204. How many that transaction can be controlled in ejb3.0? Ans: a. b. c. d. e. 2 7 5 4 3

2 205. What is the package to be imported for implementing MessageListener interface? Ans: javax.jms.MessageListener

206. Which bean uses @Postconstruct callback methods?(radio button) i. ii. iii. iv. Stateless Stateful MDB Entity Ans: a. b. c. d. I,ii,iii Ii,iv I,iii,iv ii

a.

I,ii,iii

207. Which method in BMP is used to avoid round trips to the database? Ans a. b. c. d. ejbStore() ejbSave() ejbEntity() None

ejbStore() 208. Which bean uses @Postconstruct callback methods?(checkbox) (verify) Ans: a. b. c. Can be used for both stateless and stateful beans Should be used for both stateless and stateful beans Should be used for stateless bean

Can be used for both stateless and stateful beans 209. Select Object(customer) FROM CUSTOMER AS customer Is this query is a. b. c. d. Legal Illegal Not enough query None of the listed options

Legal 210. Select Object(H) FROM Head as H, IN (H.teams) t What does H.teams has? ANS: a. b. c. d. Collection String Object None of the above options

Collection

211. Select Object(C) FROM customer as c,IN(c.oreder)o,IN(o.lnitem)ln Where ln.product_type=Refrigerator What will be query retrieve? Ans: a. b. c. Query will not execute All the orders with item line product as refrigerator(correct ans) Customers with orders for refrigerator

All the orders with item line product as refrigerator

212. What is the valid syntax for MDB? Ans: Import javax.jms.* Import javax.ejb.* Public class sessionbean implements MessageListener,MessageDrivenBean{ ejbRemove(); public void onMessage(Message msg){} (check for void and Message) } 213. What does client need from session bean for entities? Ans: a. b. c. JPA Lookup JMS Cant remember the fourth option

Lookup

214. What annotation is used by session bean to bind to entitymanager?

Ans: a. b. @Persistence @ PersistenceContext Cant remember the other two options

@ PersistenceContext

215. Which one of the following is the missing file listed below for creating entities Web.xml,customer.java,jspservelet.java,entity bean class? Ans: a. b. c. d. ejb-config.xml config.xml XML deployment descriptor Persistence.xml

Persistence.xml

216. Entity manager should be used to access ____________ from session beans ? Entity bean JPA JSF JNDI lookup

217.

Entity bean Entity beans known as transactional resources since? Used in transaction Speed Statefull nature Used in transaction 218. One question had the words entire object to be a primary key True False 219. False

Correct implementation of statefull session bean ?----find the declaration--@Statefull

220. Purpose of Service Locator pattern - The Service Locator hides the lookup process's implementation details and complexity from clients. To improve application performance, Service Locator caches service objects to eliminate unnecessary JNDI (Java Naming and Directory Interface) activity that occurs in a lookup operation 221. How to declare query timeout in JBOss 3.0 Query.setHint 222. One question on identify the stateful session bean. [checkbox] You select those two option which have @stateful above the class name.

1.
{

public class CreditCard - correct

Private String cardID; Private Integer limit; Public string ownerName; Pubic void setCardInformation(String cardID, String ownerName, Integer limit) { This.cardID=cardID; This.ownerName=ownerName; This.limit=limit; } } Which statement is true? a. The class is fully encapsulated b. The code demonstrates polymorphism. c. The onwerName variable breaks encapsulation. (correct ans) d. The cardID and limit variables break polymorphism e. The setCardInformation method breaks encapsulation 2. Through which of the following interface does an application create, find and remove enterprise beans? a. javax.ejb.EJBHome (correct ans) b. javax.ejb.EJBObject c. javax.ejb.EntityBea d. javax.rmi.Remote

3. Which of the following is EJB System exception? 1. javax.ejb.ObjectNotFoundException 2. javax.ejb.EJBException (correct ans) 3. javax.ejb.DuplicateKeyException 4. javax.ejb.CreateException 4. Which of the following is correct about MDB? 1. can execute in client transactional context 2. All messages from the client services by the same MDB 3. MDBs do not have a client visible identity 4. MDB can hold client conversation state 5. Which is not a typical action of a catch block? 1. partial processing of the exception 2. complete handling 3. Throwing exceptions 4. Rethrow same exception to the calling environment 6. Possible to iterate multiple times over an iterator (True or false)- False 7. What is the function of isIdentical() method? Ans. Compares two EJB object remote reference & returns true if two EJB objet references represents the same bean even if EJB object stubs are different obj instance (correct ans) One option was returns true if both came from same home 8. Which of the following is the requirement of the message driven bean? Select if options are from any of these: foll s the google result


9. class classname{

It must implement the MessageDrivenBean and MessageListener interfaces. The class must be defined as public. The class cannot be defined as abstract or final. It must implement one onMessage method. It must implement one ejbCreate method and one ejbRemove method. It must contain a public constructor with no arguments. It must not define the finalize method.

\public static void main(String args[]) \{ Int [][] a1={{1,2,3},{4,5,6},{7,8,9,10}}; System.out.print(a1[0][2]+,+a1[1][0]+,+a1[2][1]); }} What is the result of attempting to compile and run the program?

a.

Prints:3,4,8 B. prints: 7,2,6 C. compile time error

D. Run time error E. none of the above 10. Class classname{ Public static void main(Stirng[] args) { Int [][] a1={{1,2},{3,4,5},{6,7,8,9},{}}; For(int i=0;i<a.length;i++) System.out.print(a1[i].lenthg+,); }}} What is the result of attempting to compile and run the program? a. b. c. d. e. Prints: 2,3,4,0 (correct ans) Prints: 1,2,5,0 Compile time error Runtime error None of the above

11. what is MDB? Ans: asynchronous messaging object MDB is stateless session bean 12. How may number of transaction attributes available? a. 6 b. / c. 10 d. 3 e. 2 13. Which is intermediate between client and DB? a. stateless session bean b. entity bean (correct ans) c. entity manager d. session bean 14. Which annotation is used to clean up resources such as DB connection and TCP/IP connections a. javax.ejb.destroy b. javax.ejb.predestroy (correct ans) c. javax.ejb.passivate d. javax.ejb.prepassivate (correct ans) 15.JNDI look up methods z. is used to located home object b. is used to locate ejb object

c. is used to locate Remote object d. none of the above 16. On what basis the application causes creation of session bean instance? a. implementing clases b. entity bean c. during application start d. none 17. Which bean uses the postactivate and prepassivate annotations a. stateful session b. stateless session 18.In POP messaging a. sender waits for acknowledgement b. sender does not wait for ack c. sender blocks the channel 20. What is the result of leaving the beans for too long a time as a result of which it gets serialized? - correct Performance is reduced 21. What is broadcasting a.POP b. publish/subscribe 22. What is the difference between calling an eJB from MDB and java 23. What is the valid syntax for MDB? Ans: Import javax.jms.*; Import javax.ejb.*; Public class sessionbean implements MessageListener,MessageDrivenBean{ ejbRemove(); public void onMessage(Message msg){} } 24. What does client need from session bean for entities? a.JPA b.lookup c.JMS d.Cant remember 26. What are the advantages of local interface? a. it improves performance

b. it makes coding easier c. could not remember 27.which method in BMP is used to avoid round trips to the database? a.ejbStore() (correct ans) b.ejbSave() c.ejbEntity() d.None 28.Which bean uses @Postconstruct callback methods?(checkbox) a. can be used for both stateless and stateful beans,(also MDB) b. should be used for both stateless n stateful beans c. should be used for stateless bean d. should be used for stateful bean e. can be used for stateful bean 29.Public class class_name implements serializable { } What wl be the value for @Table Ans: same as class name (correct ans0029 30. der r 100 beans in JNDI and the context lokup() method takes time 2 lokup.how do u handle the situation to make it easy retrieval of the bean ? Ans: home cache, so tht we need not look up jndi evry time 31. how multiple EJB instances are managed? a) connection pooling b) caching of ejb instances c) ejb passivation d) all the above 32. At wat stage the life cycle of a CMP can b assumed 2 b started? a) before ejb create() is executed b) after ejb create() is executed (correct ans) c)in postcreate() method d) after executing ejbStore() 33. ejbActivate () Vs ejbPassivate() 34. ejbCreate() Vs ejbPostCreate() 35.ejbLoad() Vs ejbStore() 36.which type of bean can use bean pooling ? stateless 37. hw can u call an ejb from a jsp/servlet? 38.wich of the foll is an application level exception ? a)nullpointerexception

b)ArrayOutOfBoundException c)CreateException d)ObjectNotFoundException e) all the above f) none of the above 39.CMP provides a)empty implementation of ejbStore() and ejbLoad() b)concrete implementation of ejbStore() and ejbLoad() 40. which bean is called as multi threaded bean? a) entity bean b) stateless session c)stateful session d)pooled stateless session bean 41. ejbStore() method is equivalent to a)select b)insert c) update d) delete

1.

EJB SQL and SQL difference SQL joins tables and EJBQL navigates through beans How to declare a stateful session bean------@stateful Isolation level in EJB.- Cannot modify the isolation level for container-managed persistence

2.
3.

What is the sequence of steps in the life cycle of a Stateless Session Bean? A B C D class.newInstance(), setSessionContext (ctx), ejbCreate() ejbCreate(), setSessionContext (ctx), class.newInstance() class.newInstance(), ejbCreate(), setSessionContext (ctx) setSessionContext (ctx), ejbCreate(), class.newInstance()

When Stateless Session Beans transition from 'Does Not Exist' to 'Method Ready Pool', the container invokes newInstance(), setSessionContext() and ejbCreate() methods. Hence choice A is correct.

a) Stateful beans are also Persistent session beans. They are designed to service business processes that span multiple method requests or transactions. Stateless beans are designed to service business process that last only for a single method call or request. b) Stateful session beans remembers the previous requests and reponses. Stateless session beans do not remember the previous request and responses. c)Stateful session beans does not have pooling concept. Stattless session bean instances are pooled. d) Stateful S.Beans can retain their state on behave of an individual client. Stateless S.Beans donot maintain states. e) Stateful S.Beans can be passivated and reuses them for many clients.

Stateless S.Beans, client specific data has to be pushed to the bean for each method invocation which result in increase of network traffic. Stateful session beans have the passivated and Active state which the Stateless bean does not have. Use stateless session EJBs to cache and manage infrequently changed data,Stateless session beans are soooo much faster. Always access entity beans from session beans. If only using an entity bean for data access, use JDBC directly instead. Use the Data Access Object pattern to decouple business logic from data access logic, Use the Fast-Lane Reader pattern to accelerate read-only data access by not using enterprise beans. Use the Front Controller pattern to centralize incoming client requests Use the Page-by-Page Iterator pattern to efficiently access a large, remote list by retrieving its elements one sublist of value objects at a time Use the Session Facade pattern to provide a unified, workflow-oriented interface to a set of enterprise beans, thus minimizing client calls to server EJBs. Use the Value Object pattern to efficiently transfer remote, fine-grained data by sending a coarsegrained view of the data. Use CMP except in specific cases when BMP is necessary: Stateless session beans are much more efficient than stateful session beans. Facade objects (wrappers) allow local entity beans to be called remotely. This pattern incurs very little overhead for remote calls.

6. Possible to iterate multiple times over an iterator (True or false) . Semantics for calling remote interface Pass by value pass by reference no semantics

false)

Semantics for calling local interface pass by reference

4. Goal of performance tuning increase speed faster calculations

5. What is the result of leaving the beans for too long a time as a result of which it gets serialized 7. What is the difference between calling an EJB from MDB and java

9. Postconstruct annotation is used for which bean Session Bean ???

2) If there are 100 beans in JNDI & the context.lookup() method takes time to lookup. How do you handle the situation to make it easy retrieval of the bean ? Ans: home cache, so that we dnt need to lookup jndi everytime. 11) How multiple EJB instances are managed ? (a) Connection Pooling (b) Caching of EJB instances (c) EJB Passivation (d) All the above 12) At what stage, the life cycle of a CMP bean can be assumed to be started ? (a) before ejbCreate() method is executed (b) after ejbCreate() method is executed (c) in postCreate() method (d) after executing ejbStore() 28) ejbActivate() Vs ejbPassivate() (ans below) 38)ejbCreate() Vs ejbPostCreate()(ans below) 39)ejbLoad() Vs ejbStore()(ans below) 29)Which type of EJB can use bean pooling ? stateless 30) How can you call an EJB from a JSP/Servlet ? 34)What is the difference between normal beans and EJBs ? 37)CMP bean provides (a) Empty implementation of ejbLoad() and ejbStore() (a) Concrete implementation of ejbLoad() and ejbStore() Ans:-Concrete implementation of ejbLoad() and ejbStore() 38)Which bean can be called as Multi-Threaded bean ? (a) Entity beans (b) Stateless Session beans (c) Stateful Session beans (d) Pooled Stateless Session beans Ans:-Entity beans, Stateless Session beans

9. Which will not throw exception if the client does not call EJB method in transaction (Check Box) Required Non_Supported (P) Never (P) Required_New Mandatory

11. The method that must be implemented with a CMP Atleast one ejbSelect() Atleast one ejbCreate() Atleast one ejbFindPrimaryKey() Atleast one ejbFindXXX()

13 For which option use of EJB not preferred Fast processiong Transacion processing Security maintenance Content presentation

19. How to limit flush to only after the execution is complete setFlushMode(FlushModeType.COMMIT) setFlush(FlushModeType.COMMIT) None

21. What type of bean can be used for records that are read and updated frequently BMP CMP Stateful Sateless

22. Isolation levels in EJB are set in??????? Annotation Deployment descriptor Both (P) none

35. A question Diff b/w stateful and steles session beanSimple difference

In CMP data access code is handled by container itself but in BMP data access code in written by EJB coder in bean methods like ejbcreate etc. In CMP EJB Query language is used while in BMP coder have to write data access code either in EJB or using DAO that is more challenging Diff between stateless and stateful bean: ??????? Stateful can use return values of one method in another but stateless cant do it

1.

Diff between stateless and stateful bean: Stateful can use return values of one method in another but stateless cant do it

EJB Service Locator Strategy

The Service Locator for enterprise bean components uses EJBHome object, shown as BusinessHome in the role of the ServiceFactory. Once the EJBHome object is obtained, it can be cached in the ServiceLocator for future use to avoid another JNDI lookup when the client needs the home object again. Depending on the implementation, the home object can be returned to the client, which can then use it to look up, create, and remove enterprise beans. Otherwise, the ServiceLocator can retain (cache) the home object and gain the additional responsibility of proxying all client calls to the home object. Priyas Set 1. Which does not denote large granularity?

Low granularity (fine grained class) could lead to low performance. The most effective way to improve the overall performance of EJB-based applications is to minimize the amount of method invocations, making the communications overhead negligible compared with the execution time. This can be achieved by implementing coarse-grained methods. For optimal performance, entity beans should be designed to: have large granularity, which usually means they should contain multiple Java classes and support multiple database tables; be associated with a certain amount of persistent data, typically multiple database tables, one of which should define the primary key for the whole bean; support meaningful business methods and encapsulate business rules to access the data. 2. 3. Findbyposition method related questions (2)? What does Topic session Object do?

A TopicSession object provides methods for creating TopicPublisher, TopicSubscriber, and TemporaryTopic objects. It also provides a method for deleting its client's durable subscribers. A TopicSession is used for creating Pub/Sub specific objects. In general, use the Session object, and use TopicSession only to support existing code. Using the Session object simplifies the programming model, and allows transactions to be used across the two messaging domains. A TopicSession cannot be used to create objects specific to the point-to-point domain. The following methods inherit from Session, but must throw an IllegalStateException if used from TopicSession:

createBrowser createQueue createTemporaryQueue

***************************************************** Lazy Loading - The advantage of lazy load is that the data is fetched only if an access to an attribute or relation takes place. This reduces the memory consumption. The disadvantage could be that this just in time fetching of persistent data may be slow down the application.

Increased speed - Cache as many beans in the EJB caches as possible to increase speed (equivalently, decrease response time). Caching eliminates CPU-intensive operations. However, since memory is finite, as the caches become larger, housekeeping for them (including garbage collection) takes longer. Decreased memory consumption - Beans in the pools or caches consume memory from the Java virtual machine heap. Very large pools and caches degrade performance because they require longer and more frequent garbage collection cycles. Improved functional properties - Functional properties such as user time-out, commit options, security, and transaction options, are mostly related to the functionality and configuration of the application. Generally, they do not compromise functionality for performance. In some cases, you might be forced to make a trade-off decision between functionality and performance. This section offers suggestions in such cases. In EJB QL, an expression can traverse--or navigate--to related beans. These expressions are the primary difference between EJB QL and SQL. EJB QL navigates to related beans, whereas SQL joins tables.

The simple explanation is that in fine grained EJB's, every object will be made a separate EJB. With coarse grained EJB's, you wil have big "fat" EJB,s, containing a lot of application logic. An example: You want to represent an order consting of a number of order lines. You can make each order line its own EJB (fine grained), or you can have one EJB encompassing the entire order (coarse grained). Of course, in the coarse grained case, the order EJB can still use other helper classes for the actual implementation, but they are not exposed to the client. There are pro's and con's to each approach - in general, coarse grained EJB's seem to be preferred. Coarse grained: + Fewer EJB calls - less network load, fewer transaction context, + Simpler deployment + Fewer objects for the application programmer to learn - CMP harder to set up - Potentially less reuse - Less distribution Read-only entity beans cache data from the database. Application Server supports read-only beans that use both bean-managed persistence (BMP) and container-managed persistence (CMP). Of the two types, CMP read-only beans provide significantly better performance. In the EJB lifecycle, the EJB container calls the ejbLoad() method of a read-only bean once. The container makes multiple copies of the EJB component from that data, and since the beans do not update the database, the container never calls the ejbStore() method. This greatly reduces database traffic for these beans. If there is a bean that never updates the database, use a read-only bean in its place to improve performance. A read-only bean is appropriate if either:

Database rows represented by the bean do not change. The application can tolerate using out-of-date values for the bean.

Transaction can be controlled by Turning off auto-commit for jdbc transactions TX_REQUIRED for EJBs 2. Ejb Object Vs Java Object Ejb Object follows ejb specs & remotely identified in application server Java object can be deployed in applic. Server & connot be identified 3. Stateful beans can be converted to stateless beans by adding parameters that holds entire state to the bean method 4. ejbLoad() ejbStore() To synchronise bean with data from To synchronise bean data with database database Triggers a ASELECT statement Triggers an UPDATE statement Refreshes insance variables Writes instance vaiables 5. ejbCreate() Vs ejbPostCreate() ejbcreate ejbpostcreate accessible by session, entity & MDB bean doesnot return void invoked prior to bean being created

1.

accessible only by entity returns void invoked after the bean instance is created

for every ejbcreate there must be a matching ejbpostcreate ejbpostcreate initializes what has been created by ejbcreate

133. Implementing a message-driven bean requires that the developer extend two interfaces: a message listener interface and BlankX Answer (B): The implementation class for a message-driven bean must extend the javax.ejb.MessageDrivenBean interface and a message listener interface that corresponds to the specific messaging system. For example, when JMS is the messaging system, the message listener interface is javax.jms.MessageListener.

Apart from all these,

1.I dont rem the questionthe options where a)N b)N+1 c)N-1 d)1 2. Lazy loading question-----after bean(I dont remember the exact word) instantiation 3. I dont rem the questionthe options where a)pooled b)ready c)pooled to ready 4. MDB stands for-------Message Driven Bean 5.Credit card swipe uses which bean--------MDB+stateless

You might also like