Download of 1Z0-895 exam price materials and bundle for Oracle certification for IT candidates, Real Success Guaranteed with Updated 1Z0-895 pdf dumps vce Materials. 100% PASS Java Platform, Enterprise Edition 6 Enterprise JavaBeans Developer Certified Expert Exam exam Today!

2021 Jul 1Z0-895 training

Q41. A developer is writing client code to access a session bean deployed to a server instance. 

The client can access the session bean under which of these circumstances? (Choose three) 

A. The client is deployed in the same JVM as the session bean and the session bean has a local interface. 

B. The client is deployed in the same JVM as the session bean and the session bean exposes a no-interface view. 

C. The client is deployed in a different JVM from the session bean and the session bean has a local interface. 

D. The client is deployed in a different JVM from the session bean and the session bean has a remote interface. 

E. The client is deployed in a different JVM from the session bean and the session bean has a no-interface implementation. 

Answer: ABD 

Explanation: D: If your architecture has a requirement whereby the client application (web application or rich client) has to run on a different JavaVirtual Machine (JVM) from the one that is used to run the session beans in an EJB container, then you need to use the remote interface. 

Q42. An ejb-jar also contains three interceptor classes: AInt, BInt, CInt. Each interceptor class defines an AroundInvoke method called intercept. 

The ejb-jar also contains a stateless session bean FooBean with a local business interface Foo that declares a method foo (): 

10. @Stateless 

11. @Intercaptors ({CInt.class, BInt.class}) 

12. public class FooBean implements Foo { 


14. public void foo () {} 


16. } 

The ejb-jar contains a META-INF/ejb-jar.xml file with an <interceptor-binding> section: 

<interceptor-binding> <ejb-name>FooBean</ejb-name> <interceptor-order> <interceptor.class>com.acme.AInt</interceptor-class> </interceptor-order> 


What is the interceptor order when the business methodfoo() is invoked? 

A. AInt 

B. AInt, CInt, BInt 

C. CInt, BInt, AInt 

D. AInt, BInt, CInt 

Answer: B 

Explanation: With the interceptor-order clauses Aint will be first in the order of interceptors. 

Within each group (default, class, method) the order of the interceptors are from left to right as defined in the @Interceptors annotation, and then the xml interceptors. 

In this scenario, with the @Intercaptors ({CInt.class, BInt.class}) line, the ordering continues with CInt and BInt. 

Note 1: By default the ordering of interceptors when invoking a method are 

* External interceptors ** Default interceptors, if present ** Class interceptors, if present ** Method interceptors, if present 

* Bean class interceptor method Note 2: You can override the default sort order of the external interceptors by specifiying an interceptor-binding with an interceptor-order specifying the order of the interceptors 

Reference: EJB Interceptors 

Q43. MyMsgBean is a JMS message-driven with container-managed transaction demarcation. FooBean is an EJB 3.x stateless session bean that sends messages to the JMS destination with which MyMsgBean is associated. 

MyMsgBean’s message listener method has transaction attribute REQUIRED, and is defined as follows: 

Which statement is true about the result of the message processing? 

A. FooBean receives javax.ejb.EJBException. 

B. The container discards the MyMsgBean bean instance. 

C. FooBean receives the original RuntimeException thrown from the message listener method. 

D. The container does NOT roll back the transaction, and FooBean can continue the transaction. 

Answer: B 



* Required Attribute If the client is running within a transaction and invokes the enterprise bean’s method, the method executes within the client’s transaction. If the client is not associated with a transaction, the container starts a new transaction before running the method. 

The Required attribute is the implicit transaction attribute for all enterprise bean methods running with container-managed transaction demarcation. You typically do not set the Required attribute unless you need to override another transaction attribute. Because transaction attributes are declarative, you can easily change them later. 

Q44. Which two statements are correct about stateless session beans? (Choose two.) 

A. The bean class may declare instance variables. 

B. The lifetime of the bean instance is controlled by the client. 

C. The container may use the same bean instance to handle multiple business method invocations at the same time. 

D. The container may use the same bean instance to handle business method invocations requested by different clients, but not concurrently. 

Answer: AC 

Explanation: * A: Stateless session beans are EJB's version of the traditional transaction processing applications, which are executed using a procedure call. The procedure executes from beginning to end and then returns the result. Once the procedure is done, nothing about the data that was manipulated or the details of the request are remembered. There is no state. 

These restrictions don't mean that a stateless session bean can't have instance variables and therefore some kind of internal state. There's nothing that prevents you from keeping a variable that tracks the number of times a bean has been called or that tracks data for debugging. An instance variable can even hold a reference to a live resource like a URL connection for writing debugging data, verifying credit cards, or anything else that might be useful. 

C: A stateless session bean is relatively easy to develop and also very efficient. Stateless session beans require few server resources because they are neither persistent nor dedicated to one client. Because they aren't dedicated to one client, many EJB objects can use just a few instances of a stateless bean. A stateless session bean does not maintain.conversational state relative to the EJB object it is servicing, so it can be swapped freely between EJB objects. As soon as a stateless instance services a method invocation, it can be swapped to another EJB object immediately. Because there is no conversational state, a stateless session bean doesn't require passivation or activation, further reducing the overhead of swapping. In short, they are lightweight and fast! 

* The Lifecycle of a Stateless Session Bean Because a stateless session bean is never passivated, its lifecycle has only two stages: nonexistent and ready for the invocation of business methods. The EJB container typically creates and maintains a pool of stateless session beans, beginning the stateless session bean’s lifecycle. The container performs any dependency injection and then invokes the method annotated @PostConstruct, if it exists. The bean is now ready to have its business methods invoked by a client. 

At the end of the lifecycle, the EJB container calls the method annotated @PreDestroy, if it exists (not B). The bean’s instance is then ready for garbage collection. 

Q45. A developer writes a Singleton bean that uses the java Persistence API within a business method: 

Two different concurrently executing caller threads acquire an EJB reference to PersonBean and each invoke the getPerson () method one time. How many distinct transaction are used to process the caller invocations? 

A. 0 

B. 1 

C. 2 

Answer: B 

Explanation: Only one transaction is required. LockType READ allows simultaneous access to singleton beans. 

Note: READ 

public static final LockType READ For read-only operations. Allows simultaneous access to methods designated as READ, as long as no WRITE lock is held. 

Reference: javax.ejb, Enum LockType

Abreast of the times 1Z0-895 exams:

Q46. 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. 


* 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 cast and 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"); 

Q47. Which is a valid use of the EJB 3.x TimerHandle object? 

A. To retrieve all active timers associated with this bean 

B. To adapt EJB 3.x timers to EJB 2.1 and earlier timers 

C. To obtain a seralizable timer handle that may be persisted 

D. To be implemented by EJB classes that are to be registered with the timer service 

Answer: C 

Explanation: The TimerHandle interface allows the bean provider to obtain a serializable timer handle that may be persisted. 

Since timers are local objects, a timer handle must not be passed through a bean's remote business interface, remote interface or web service interface. 

Reference: javax.ejb, Interface TimerHandle 

Q48. A developer wants to create an enterprise bean that uses the EJB Timer service. 

Which two are true? (Choose two.) 

A. Once created, a timer cannot be canceled. 

B. The bean can be used within a transaction. 

C. Once created, the timer will survive a container crash. 

D. The enterprise bean must implement the TimedObject interface. 

E. The developer can use either a message-driven bean, stateless session bean, or stateful session bean. 

Answer: BC 

Explanation: B: An enterprise bean usually creates a timer within a transaction. If this transaction is rolled back, the timer creation also is rolled back. Similarly, if a bean cancels a timer within a transaction that gets rolled back, the timer cancellation is rolled back. 

C: Timers are persistent by default. If the server is shut down or crashes, persistent timers are saved and will become active again when the server is restarted. If a persistent timer expires while the server is down, the container will call the @Timeout method when the server is restarted. 

Reference: The Java EE 6Tutorial. PartNo: 821– Transactions andTimers 

Q49. A developer creates a stateless session bean, EmployeeServiceBean, and its interface, EmployeeService. The session bean uses two annotated entity classes, Employee.class and Department.class. 

Which two package options can the developer use when creating a deployable EAR? The proposed directory structure is listed for each option. (Choose two) 

A. Emp.ear emp-ejb.jar META-INF/persistence.xml EmployeeService.class EmployeeServiceBean.class lib/emp-classes.jar Employee.class Department.class 

B. Emp.ear META-INF/orm.xml EmployeeService.class EmployeeServiceBean.class Employee.class Department.class 

C. Emp.ear emp-ejb.jar META-INF/persistence.cml Employee.class Department.class EmployeeService.class EmployeeServiceBean.class 

D. Emp.ear emp-ejb.jar persistence.xml Employee.class 

Department.class EmployeeService.class EmployeeServiceBean.class 

Answer: AC 

Q50. A developer writes a stateless session bean FooBean with one remote business interface FooRemote containing one business method foo. Method foo takes a single parameter of application-defined type MyData. 

11. public class MyData implements { 

12. int a; 

13. } 

Methods foo is implemented with the FooBean class as: 

11. public void foo (MyData data) { 

12. data.a = 2; 

13. } 

Another session bean within the same application has a reference to FooRemote in variable fooRef and calls method foo with the following code: 

11. MyData data = new MyData(); 

12. data.a = 1; 


14. System.out.printIn(data.a); 

What is the value of data.a when control reaches Line 14 of the client? 

A. 0 

B. 1 

C. 2 

Answer: B