Answers to
EJB Mock fodder questions:
New disclaimer: A few *refinements* (OK, errors), were found in these questions. I'll fall on my sword here, sorry. But at least you had the *learning experience* of understanding the topics well enough to spot the *refinements* !
Fixes to the questions will be noted with << >> marks
Old Disclaimers:
You WON'T get any questions on the real exam that say 'choose all that apply' - you will always know exactly how many answers are correct. I use 'choose all that apply' to make these questions harder, you know, to toughen you up a bit
When I say 'choose all that apply', there will ALWAYS be at least one correct answer.
The real exam uses several forms of 'drag and drop' which I'm kind of pseudo-emulating here; read the questions carefully, for instance some are one-to-many, some are not!
Finally, remember the real exam is NOT open-book
End of disclaimers, and on to the questions:
=======================================================
EJB Mock Exam #2
2.1 Which statement about session beans is true?
a). The bean provider must write the method public void remove() in both stateless and stateful session classes.
b). Local clients can remove session beans by calling a method on the bean's home.
c). The << remove >> method in the component interface can be used only by remote clients.
d). To ask the EJBHome to remove a session bean, the client must provide the bean's handle.
Answer: d
revision: 2c was << ejbRemove >>
2.2 Which statement about locating or using a session bean's home interface is true?
a). Acquiring an 'InitialContext' is required only for remote clients.
b). The 'InitialContext' must be narrowed before it can be used.
c). Once acquired by a client, a home interface can be used multiple times.
d). The client can acquire a handle for the bean's local home interface.
Answer: c
2.3 When comparing two session objects, what is true? (Choose all that apply.)
a). Using the 'isIdentical' method, stateless session beans from the same home will always return true.
b). Using the 'isIdentical' method, stateful session beans from the same home will always return true.
c). The 'isIdentical' method can be used only for remote object references.
d). Using the 'equals' method, stateless session beans from the same home will always return true.
e). Using the 'equals' method, stateful session beans from the same home will always return true.
Answer: a
2.4 Which method can be called << without exception >>, by both remote and local clients on a reference to a session bean's component interface?
a). ejbCreate
b). getSessionContext
c). getPrimaryKey
d). getEJBHome
e). remove
Answer: e
revision: added 'without exception'
=======================================================
EJB Mock Exam #3
3.1 Which are directly invoked by the client? (Choose all that apply.)
a). ejbPassivate
b). business methods
c). setSessionContext
d). newInstance
e). create
Answer: b, e
3.2 Which is true about passivation for stateful session beans?
a). The container can passivate a stateful session bean regardless of the bean's << transactional >> state.
b). The client can passivate a session bean.
c). References to JNDI contexts are lost during passivation.
d). References to 'SessionContext' are preserved during passivation.
e). A passivated, stateful session bean instance will always be re-activated prior to removal.
Answer: d
revision: 3.2.a - added << transactional >>
3.3 (Note: The real exam has several types of 'drag and drop' questions, that I'm going to do a lame job of simulating with this question...)
Match the methods on the left with the interfaces in which those methods can be found, on the right. A match is correct if the method is either declared in, or inherited by, the interface. Note: There may be some many-to-one and one-to-many relationships in your answer.
Answers:
a - 1
b - 2
c - 1
d - 2
e - 2
f - 3
<< answer for new method g - 2,4 >>
revision: added a new method
3.4 Which statements about stateful and stateless session beans are true?
(Choose all that apply.)
a). Only stateful session beans support transactions.
b). Only stateful session beans can be passivated.
c). Only stateful session beans have a 'setSessionContext' method.
d). Both stateful and stateless session beans can support overloaded 'ejbCreate' methods.
e). Both stateful and stateless session beans can implement the 'javax.ejb.SessionSynchronization' interface.
f). Both stateful and stateless session beans can have instance variable state.
Answer: b, f
3.5 Which statements about a session bean class are true? (Choose all that apply.)
a). They can be marked 'final'
b). They can support overloaded constructors.
c). Their business methods can be 'private'.
d). Their business method names must start with "ejb".
e). Their 'ejbCreate' methods must not be declared as 'final'.
Answer: e
3.6 For this drag and drop type question, you can use each element only once. Which interface should be matched with which fact, so that all four matches are correct?
Answers:
1 - b
2 - d
3 - a
4 - c
=================================================
11.1 Which two are true about container managed transactions in EJB 2.0? (Choose all that apply.)
a). Differentiating between overloaded methods is possible in the bean's deployment descriptor.
b). A transactional attribute must be individually declared in the method-name tag, for every business method in the bean class.
c). The container will interpose only on method invocations with container-managed transaction demarcation.
d). If an 'onMessage' method returns before committing a transaction the container will throw an exception.
e). A message-driven bean with CMT demarcation must not invoke the EJBContext.getUserTransaction method.
Answers: a, e
11.2 When a business method in an entity bean calls the getRollbackOnly method, which transaction attribute settings will cause the container to throw an exception? (Choose all that apply.)
a). NotSupported
b). Required
c). Supports
d). RequiresNew
e). Mandatory
f). Never
Answers: a, c, f
11.3 When a session bean has container-managed demarcation value of 'Supports', which << three >> methods run in an unspecified transaction context? (Choose << three >>.)
a). ejbActivate
b). getRollbackOnly
c). getUserTransaction
d). ejbRemove
e). afterBegin
f). afterCompletion
Answers: a, d, f
revision: changed 'two' to 'three'
===============================================
If you can stand it, I'll try to post batch #12, soon. (And I promise the answers will be more timely

)
[ June 05, 2003: Message edited by: Bert Bates ]