oDesk Enterprise Java Beans (EJB) 2.0 Test 2015
·
1. Which of the following constitute
the enhancements made to EJB 2.0?
Answers:
• JMS (Java
Message Service) integration
• Improved
support for container-managed persistence (CMP)
• Support for RMI/IIOP
protocol for network interoperability
• Management of
beans relationships
• All of the
above
2. A client wants to access Enterprise Java
Bean for some processing. The first step will be looking up the class that
implements its home interface. Which of the following should be used for the
purpose?
Answers:
• JNDI
• MTS
• JTS
• JTA
• Java IDL
3. A pre-cached instance is used to load state
information on creation of an EJB.
Answers:
• True
• False
4. What will happen to the running session
beans if the EJB container crashes or restarts?
Answers:
• They will get destroyed
• They will keep
on running
• Their execution
will be halted temporarily
• None of the
above
5. An online shop employs a stateless session
bean (named 'Eshop') to process the requests. 'Eshop' uses a declarative
transaction management system. The following code is from the xml deployment
descriptor file of the bean:
1.
<ejb-jar>
2.
<enterprise-beans>
3.
<session>
4.
<ejb-name>Eshop</ejb-name>
5.
<home>com.solution.EshopHome</home>
6.
<remote>com.solution.Eshop</remote>
7.
<local-home>com.solution.EshopLocalHome</local-home>
8.
<local>com.solution.EshopLocal</local>
9.
<ejb-class>com.solution.EshopBean</ejb-class>
10.
11.
12.
</session>
13.
</enterprise-beans>
14.
</ejb-jar>
The session and transaction attributes are to
be coded in the lines numbered 10 and 11. Which of the following options should
be used to make the bean work as expected?
Answers:
•
<session>Stateless</session>
<transaction>Container</transaction>
• <session>Stateful</session>
<transaction>Bean</transaction>
•
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
•
<session-type>Stateful</session-type>
<transaction-type>Bean</transaction-type>
•
<session-type>Stateless</session-type>
<transaction>Container</transaction>
6. A heavy tool manufacturing company manages
its business and production by using enterprise beans. A session bean named
'Status' is used to get the production status for the day. The following code
gets the context:
Context initialContext = new InitialContext();
The bean provides a local client view. For the
local home interface named 'StatusHome.' What should be the lookup?
Answers:
• StatusHome statusHome =
(StatusHome) initialContext.lookup("java:tools/env/ejb/status");
• StatusHome
statusHome = Context.lookup("java:tools/env/ejb/status");
• StatusHome
statusHome = javax.rmi.PortableRemoteObject.narrow(
Context.lookup("java:tools/env/ejb/status"),StatusHome.class);
• StatusHome
statusHome = (StatusHome) javax.rmi.PortableRemoteObject.narrow(
initialContext.lookup("java:tools/env/ejb/status"),StatusHome.class);
7. Which of the following statements is correct with regard to JavaBeans and Enterprise JavaBeans?
Answers:
• Both can be
visible or non-visible at run time
• Both can be
deployed as an Active X control
• Both require a
Manifest file
• Both have some
mechanism to tell the builder-tool/IDE about their functionality
• Both define
their deployment descriptors
8. One of the methods of your entity bean
retrieves the names of all the patients admitted in a particular ward of a
hospital. Using a connection named 'con', you want to execute the following
query:
//secId is the parameter received by the
method
String query = "SELECT admissionId,
patientFirstName, patientLastName FROM ADMISSION WHERE sectionId=" +
secId;
Which of the following options will help you
execute the query?
Answers:
• Statement
stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(query);
• Statement
stmt=new Statement(); ResultSet rs=stmt.executeQuery(query);
• Statement
stmt=con.createStatement(); ResultSet rs=stmt.execute(query);
• Statement
stmt=con.getStatement(); ResultSet rs=stmt.executeQuery(query);
• Statement
stmt=con.getStatement(); ResultSet rs=con.executeQuery(query);
9. The following method signature is found in
an implemented entity bean named 'CustomerBean.' 'CustomerPK' is a class
representing the primary key.
public CustomerPK
ejbFindByPrimaryKey(CustomerPK key)
throws FinderException
By context look up, a client gets the
reference to the home object of the above bean, named 'custHome'. It gets the
'CustomerPK' class named 'PK' by a different method. The name of EJBObject is
'Customer', which represents a customer. Which of the following options will
you select to invoke the above mentioned method in the client?
Answers:
• Customer =
custHome.findByPrimaryKey(PK);
• Customer =
custHome.ejbFindByPrimaryKey(PK);
• custHome =
custHome.ejbFindByPrimaryKey(PK);
• Customer =
findByPrimaryKey(PK);
• PK =
custHome.findByPrimaryKey(PK);
10. The EJB specification defines six distinct
roles in the application development and deployment life cycle. Which of the
following roles is not mentioned in it?
Answers:
• Enterprise Bean
Provider
• EJB Developer
• EJB Server
Provider
• Application
Assembler
• EJB Deployer
• System
Administrator
11. The transaction attribute of a bean is set
to 'TX_REQUIRES_NEW.' What do you infer about its behavior?
Answers:
• It initiates a
new transaction only when the previous one is concluded
• It initiates a
new transaction without even waiting for the previous one to conclude
• It sends the
request to the EJB container for initiating a new bean
• The bean
manages its own transaction
12. Which of the following statements is
incorrect with regard to the process of Instance Pooling in EJB?
Answers:
• It increases
the overall efficiency of the system
• It facilitates
sharing of 'EJB bean instances' among multiple clients
• It is used with
stateless session beans
• It is used with
entity beans
• None of the
above
13. You define an enterprise bean as follows:
Public class CalcSessionBean implements
javax.ejb.SessionBean
Which of the following method definitions is
not mandatory?
Answers:
• public void
ejbCreate() {}
• public void
ejbActivate() {}
• public void
ejbPassivate() {}
• public void
ejbRemove() {}
• public void
ejbObject() {}
• public void
setSessionContext(SessionContext ctx) {}
14. The principal finder method that must be implemented
by every entity bean class is:
Answers:
•
ejbFindByPrimaryKey()
•
ejbGetByPrimaryKey()
•
ejbFindPrimayKey()
• getPrimaryKey()
• getFinder()
15. Which of the following services does an
EJB Server/Container provides to EJB?
Answers:
• Life cycle management
and Instance pooling
• Activation and
Passivation
• Transaction and
Security support
• Enforcement of
policies and restrictions
• All of the
above
16. How do Enterprise Java Beans access the
database?
Answers:
• By using Java
Database Connectivity
• By using Open
Database Connectivity
• Both a and b
• None of the
above
17. Which of the following statements is not
correct for an Enterprise Java Bean?
Answers:
• Entity beans
model business data
• Session beans
model business processes
• Message beans
send synchronous messages
• None of the
above
18. Which of the following transaction modes
are supported by Enterprise Java Beans?
Answers:
•
TX_NOT_SUPPORTED
• TX_BEAN_MANAGED
• TX_REQUIRED
• TX_MANDATORY
• All of the
above
19. Which of the following is not implemented
by a stateless session bean?
Answers:
• SessionContext
•
SessionSynchronization
• SessionObject
• EJBContext
20. Which of the following statements is not
correct with regard to Passivation of beans?
Answers:
• The process is
possible in all the enterprise beans
• It is
accompanied by some vendor specific methods, which are similar to java
serialization
• Both a and b
• None of the
above
21. The method ejbCreate() allows session
beans to perform initializations. Which of the following methods should be
called by the container before ejbCreate()?
Answers:
• newInstance()
•
setSessionContext()
• newInstance()
and setSessionContext()
• ejbRemove()
22. By interoperating via IIOP, an EJB can
directly access:
Answers:
• Existing
production systems wrapped in CORBA interface
• Existing
production systems wrapped in RMI interface
• Network
Technologies
• Messaging
Interface
• Language
Mapping
23. Which of the following is a name of the
design pattern not associated with EJB?
Answers:
• Session Facade
• Entity Command
• Message Facade
• EJB Command
24. An online medical shop uses Container
Managed persistent beans for its operations. An OrderBean uses a query to list
all the orders where payable amount is more than $800. The XML query tag in the
deployment descriptor is as follows:
1. <query>
2. <query-method>
3.
<method-name>findBigOrders</method-name>
4.
<method-params></method-params>
5. </query-method>
6.
7. </query>
If the name of the table is 'Order' and total
amount payable is in the column named 'amount,' which of the following queries
can be placed in line 6?
Answers:
•
<ejb-sql>SELECT * FROM Order o WHERE o.amount > 800</ejb-sql>
•
<ejb-sql>SELECT OBJECT(o) FROM Order o WHERE o.amount > 800</ejb-sql>
•
<ql>SELECT OBJECT(o) FROM Order o WHERE o.amount > 800 </ql>
•
<ejb-ql><![CDATA[SELECT OBJECT(o) FROM Order o WHERE o.amount>800
]]></ejb-ql>
•
<ejb-ql>SELECT OBJECT(o) FROM Order o WHERE o.amount > 800
</ejb-ql>
25. The interface that must be implemented by
a stateless session bean is javax.ejb.SessionBean.
Answers:
• True
• False
26. Which of the following statements is
correct with regard to entity, session, and message-driven beans?
Answers:
• All of them
allow sending messages
• All of them
must define a remote and home interface
• Both a and b
• None of the
above
27. To disable the Passivaton process, set the
EJBPassivationTimeout() variable to zero.
Answers:
• True
• False
28. Which of the following statements is
correct with regard to 'poison' message?
Answers:
• A JMS
destination sends this message to the consumer only once
• It is not
acknowledged by the consumer
• JMS destination
gets the acknowledgement only once
• The process of
sending a 'poison' message is possible with all the enterprise beans
29. The methods declared in Session Bean
interface are known as Callback (methods).
Answers:
• True
• False
30. What are the three classes that a Session
EJB class must provide?
Answers:
• Home Interface,
EJB Remote Interface, and Session context
• EJB class, Home
Interface, and EJB Remote Interface
• EJB class,
Session context, and EJB Remote Interface
• EJB class, EJB
Remote Interface, and Session Synchronization Interface
31. Which of the following statements are
correct with regard to EJB QL?
Answers:
• The EJB QL
defines finder methods for entity beans with container managed persistence
• EJB QL is
introduced in EJB 2.0
• EJB QL is
provided for navigation across a network of enterprise beans
• EJB QL is a language
that can be compiled
• All of the
above
32. SessionSynchronization Interface must be
implemented to reset the instance variables.
Answers:
• True
• False
33. Which of the following is a language in
which IDL compiler of CORBA generates proxies and skeletons?
Answers:
• Mapping proxies
• Language map
• Language
mapping
• Proxy language
maps
34. You don't have any database
recovery/backup system in place. Which of the following statements is true with
regard to committed and uncommitted data of your entity bean?
Answers:
• Committed data
cannot survive a server crash
• Neither
committed nor uncommitted data survives a server crash
• Both committed
and uncommitted data survive a server or database crash
• Both committed
and uncommitted data survive a server crash if clustering is used
35. The PrimaryKey class is used to provide
each entity bean with a ____________:
Answers:
• Serial identity
• Unique,
serializable identity
• Unique identity
only
• Not null
identity
• Serializable
identity only
36. Which of the following services does EJB
container provide to a bean?
Answers:
• Support for
security
• Support for
managing multiple instances
• Support for
persistence
• Support for
transactions
• All of the
above
37. Which of the following statements is
correct with regard to the method ejbSelect()?
Answers:
• It is similar
to finder method of entity beans
• It is available
to the client for querying
• It cannot be
used to extract data from other entity beans
• It cannot return
entity bean/beans
• It can return
values that are defined as CMP-TYPE
38. You are working with EJB2.0. You have to
retrieve a previously saved handle to an EJBObject named 'bookEJBObject.' In
order to restart the processing for that particular request, you need to get
the remote interface. The following code has been written for the same:
1. ObjectInputStream stream =
2.
new ObjectInputStream(new FileInputStream(fileName));
3.
4. Handle bookHandle = (Handle)
stream.readObject();
5.
6. BookRemoteInterface bookEjbObject =
(BookRemoteInterface) XX() ;
Which of the following should substitute
Method XX() of line 6?
Answers:
•
javax.rmi.PortableRemoteObject(bookHandle.getEJBObject(), BookRemoteInterface);
• javax.rmi.PortableRemoteObject(EJBObject,
BookRemoteInterface);
•
javax.rmi.PortableRemoteObject.narraow(bookHandle.getEJBObject(),
BookRemoteInterface.class);
•
javax.rmi.PortableRemoteObject.narraow(bookHandle, BookRemoteInterface);
•
bookHandle.getEJBObject()
39. We are saving a handle to an EJBObject
named 'bookEJBObject' for an online book shop:
1. javax.ejb.Handle bookHandle =
_____________;
2.
3. ObjectOutputStream stream =
4.
new ObjectOutputStream(new FileOutputStream(fileName));
5.
6. stream.writeObject(bookHandle);
7. stream.close();
Which of the following methods should be
filled in the blank?
Answers:
• (Handle)
bookEJBObject()
•
bookEJBObject.getHandle()
•
bookEJBObject.getEJBHandle()
•
newHandleInstance()
40. Both RMI and CORBA define messaging
protocols called:
Answers:
• OMP
• JRMP
• IIOP
• JRMP and IIOP
• OMP, JRMP, and
IIOP
41. What is the restriction that EJB
specification imposes on CMP fields?
Answers:
• They must be
public
• They must not
be transient
• They must be
non-static
• They must be
final
• All of the
above
42. Database connection pooling is beneficial
because:
Answers:
• It avoids the
overhead of establishing a new database connection
• Maintaining an
open database connection consumes resources on the database
• Both a and b
• ODBC is not
required for establishing a connection
43. Which of the following must be implemented
by a JMS message-driven bean?
Answers:
•
MessageDrivenBean and MessageDrivenContext interfaces
• MessageListener
and MessageDrivenBean interfaces
• MessageProducer
and MessageDrivenBean interfaces
• ObjectMessage
and MessageDrivenBean interfaces
44. Which of the following methods should be
invoked by the container to get a bean back to its working state?
Answers:
• EJBPassivate()
• EJBActivate()
• EJBRemove()
• EJBOpen()
• EJBActivation()
45. Which of the following statements is not
correct with regard to relationships in EJB?
Answers:
• The tag
<relationships> is used by CMP to enclose the relations
• These can be
managed by CMP or BMP
• The
relationship can be declared in the deployment descriptor
• Directional
relationship is always multidirectional