QUESTION 1
You are writing a client that sends a message to a JMS queue.
What two statements are true?
A. You cannot use resource injection to access a JMS destination from a Java EE application client.
B. You can use resource injection to access a JMS destination from a servlet.
C. You must use a JNDI lookup to access a JMS destination from a standalone Java class.
D. You cannot use a JNDI lookup to access a JMS destination from a session bean.
Answer: BC
Explanation:
B:In addition to injecting a connection factory resource into a client program, you usually inject a destination resource. Unlike connection factories, destinations are specific to one domain or the other.
Note:
*A destination is the object a client uses to specify the target of messages it produces and the source of messages it consumes. In the PTP messaging domain, destinations are called queues. In the pub/sub messaging domain, destinations are called topics.
* In addition to looking up a connection factory in a client program, you usually look up a destination. Unlike connection factories, destinations are specific to one domain or the other. To create an application that allows you to use the same code for both topics and queues, you castand assign the destination to a Destination object. To preserve the semantics of queues and topics, however, you cast and assign the object to a destination of the appropriate type. For example, the following line of code performs a JNDI lookup of the previously created topic jms/MyTopic and casts and assigns it to a Destination object:
Destination myDest = (Destination) ctx.lookup(“jms/MyTopic”); The following line of code looks up a queue named jms/MyQueue and casts and assigns it to a Queue object:
Queue myQueue = (Queue) ctx.lookup(“jms/MyQueue”);
QUESTION 2
You are writing a client that sends a message to a JMS queue. The client includes the following code snippet:
A. The message can be consumed by durable subscriber.
B. In the first line, the argument to the createProducer method needs to be cast to a Destination.
C. The message is sent using non-default deliver mode, priority, and expiration time values.
D. You could add more name-value pairs to the message body of the MapMessage if they were required
by your application.
Answer: D
Explanation:
createMapMessage
MapMessage createMapMessage()
throws JMSException
Creates a MapMessage object. A MapMessage object is used to send a self-defining set of namevalue pairs, where names are String objects and values are primitive values in the Java programming language.
Reference:
javax.jms,Interface Session
QUESTION 3
Given the following stateless session bean implementation classes:
Assuming no other transaction-related metadata, what are the transaction attributes of methodA, methodB, and methodC respectively?
A. MANDATORY, MANDATORY , and MANDATORY
B. REQUIRED, MANDATORY, and REQUIRES_NEW
C. MANDATORY, MANDATORY , and REQUIRES_NEW
D. REQUIRED, REQUIRES_NEW, and REQUIRES_NEW
Answer: C
Explanation:
Note:
*You can only bring out the effects of transaction attributes only when you call the method through a session bean instance and NOT through a direct method call. Even if your methods are within the same bean, you need to get the local instance of the same bean and call through its local interface instead of a direct method invoke.
*The enum TransactionAttributeType is used with the TransactionAttribute annotation to specify whether the methods of a session bean or message driven bean are called with a valid transaction context.
*MANDATORY
If a client invokes the enterprise bean’s method while the client is associated with a transaction context, the container invokes the enterprise bean’s method in the client’s transaction context.
*REQUIRES_NEW
The container must invoke an enterprise bean method whose transaction attribute is set to REQUIRES_NEW with a new transaction context.
Reference:
TransactionAttributeType.MANDATORY
QUESTION 4
Which API must an EJB 3.1 container make available to enterprise beans at runtime? (Choose one)
A. The JXTA 1.1 API
B. The MIDP 2.0 API
C. The Java SE 6 JNDI API
D. The Java SE 5 JDBC API
Answer: CD
QUESTION 5
A developer wants to write a stateful session bean using the following interface as local business interface:
1. package acme;
2. public interface Bar {
3. public void bar ();
4. }
Assuming there is not an ejb-jar.xml file, which code can be inserted into Lines 4-6 below to define the bean with the ejb name of BarBean?
1. package acme;
2. import javax.ejb.*;
3. import java.io.*;
4.
5.
6.
7. }
A. @Stateful
public class BarEJB implements Bar {
public void bar () {}
B. @Stateful (name = “Bar”)
public class Barbean implements Bar {
public void bar () {}
C. @Stateful
public class BarBean implements Serializable, Bar {
public void bar () {}
D. @Stateful (name = “bar”)
public class BarBean implements Serializable, Bar {
public void bar () throws java.rmi.RemoteException {}
Answer: C
QUESTION 6
A developer creates a stateful session bean that is used by many concurrent clients. The clients are written by other development team; and it is assumed that these clients might not remove the
bean when ending their session. The number of concurrent sessions will be greater than the defined bean cache size.
The developer must consider that the state of the session bean can be influenced by either passivation or timeout.
Which three actions should the developer take to make the bean behave correctly in passivation and timeout situations? (Choose three.)
A. Release references to resources in a @Remove annotated method.
B. Re-establish references to resources in an omit annotated method.
C. Release references to resources in a @preDestroy annotated method.
D. Release references to resources in a SPrePassivate annotated method.
E. Re-establish references to resources in a @PostActivate annotated method.
Answer: CDE
QUESTION 7
A stateful session bean contains a number of instance variables. The types of instance variables A and B are serializable. Instance variable B is a complex type which is populated by many business calls, and can, therefore, not be refilled by the client without starting all over. A helper instance variable C is defined as having a Serializable type, and can hold all the information which is in variable B. for example, B is of type XML-DOM tree and C of Type String.
Which two solutions, when combined, maintain the state of the session bean over a passivation and activation by the container? (Choose two.)
A. The value of helper variable C is used to create the value of Instance variable B in the beans no-arg
constructor.
B. The value of helper variable C is used to create the value of instance variable B in a @postcreate
annotated method.
C. The value of helper variable C is used to create the value of instance variable B in a @postActivate
annotated method.
D. Instance variable A must be made null and instance variable B must be converted to a Serializable
type and assigned to another instance variable in a @preDestroy annotated method.
E. Instance variable A must be defined transient. Instance variable B must be converted to a Serializable
type, set to null, and assigned to the instance variable C in a @PrePassivate annotated method.
Answer: CE
QUESTION 8
A developer creates a stateless session bean. This session bean needs data from a remote system. Reading this data takes a long time. Assume that the data will NOT change during the life time of the bean and that the information to connect to the remote system is defined in JNDI.
Which statement describes how to manage the data correctly?
A. Read the data in the bean’s constructor.
B. The data can only be read in the bean’s business methods.
C. Read the data in a method which is annotated with @PrePassivate.
D. Read the data in a method which is annotated with @PostActivate.
E. Read the data in a method which is annotated with @PostConstruct.
Answer: E
QUESTION 9
Assume a client will be accessing a Singleton bean.
Which client views is a Singleton bean capable of exposing? (Choose two)
A. Web Service
B. Message listener
C. EJB 2.x Remote Home
D. EJB 3.x local business
E. Java Persistence API entity
Answer: AB
QUESTION 10
A developer writes a stateful session bean FooBean with two local business interfaces Foo and bar. The developer wants to write a business method called getBar for interface Foo that returns a Bar reference to the same session bean identity on which the client onvokes getBar.
Which code, when inserted on line 12 below implements the getBar method with the wanted behavior?
10. @Resource SessionContext sessionCtx;
11. public Bar getbar () {
12.
13. }
A. Return (bar) this;
B. Return (bar) new FooBarBean();
C. Return (bar) sessionCtx.lookup(“FooBarBean”)
D. Return (bar) sessionCtx.getBusinessObject(Bar.class);
E. Return (bar) session Ctx.lookup(“java: comp/env/ejb/FooBarBean”);
Answer: D
Passing your Oracle 1Z0-895 Exam by using the latest 1Z0-895 Exam Dump Full Version: http://www.braindump2go.com/1z0-895.html