1Z0-895 | The Up to date Guide To 1Z0-895 dumps


Q41. A developer writes a stateless session bean HelloBean that exposes a local business interface Hello: 

The developer wants to test HelloBean using the EJB 3.1 Embeddable API. Given a main method with the following code: 

100. EJBContainer container = EJBContainer.createEJBContainer(); 

Assuming HelloBean is packaged in hello.jar and included in the classpath, which code correctly acquires a reference to HelloBean? 

A. InitialContext ic = new InitialContext(); 

Hello h = (Hello) ic.lookup(“java:global/hello/HelloBean”); 

B. InitialContext ic = new InitialContext(); 

Hello h = (Hello) ic.lookup(“com.acme.Hello”); 

C. Context c = container.getContext(); 

Hello h = (Hello) ic.lookup(“com.acme.Hello”); 

D. Context c = container.getContext(); 

Hello h = (Hello) ic.lookup(“java:global/hello/HelloBean”); 

Answer:

Explanation: You can initialize the InitialContext class to obtain a context, that can further be used to perform the lookup. 

Q42. A developer writes an interceptor class containing an AroundInvoke method, and applies it to the local business interface method of a stateless session bean: 

11. @Interceptors(FooInterceptor.class) 

12. public void bar() () 

A client obtains a reference to the bean’s local business interface, and calls the method bar two times from the same thread. Assuming that the container dispatches both cell to the same stateless session bean instance, how many instances of the FooInterceptor class will be used? 

A. 0 

B. 2 

C. 1 

D. Either 1 or 2 

Answer:

Explanation: You can specify one nonbusiness method as the interceptor method for a stateless or stateful session bean. Each time a client invokes a session bean business method, OC4J intercepts the invocation and invokes the interceptor method..

Reference: Configuring an Around Invoke Interceptor Method on an EJB 3.0 Session Bean 

Q43. A developer writes a stateless session bean FooBean and uses its deployment descriptor to declare a local ejb dependency on a stateful session bean in the same ejb-jar. 

Which environment annotation, when declared within the FooBean bean class, is equivalent to the ejb-local-ref shown above? 

A. @EJB(beanName=“BarBean”) Private acme.Bar barRef; 

B. @EJB(name=“bar”, beanName=“BarBean”) Private acme.Bar barRef; 

C. @EJB(name=“barRef”, beanName=“BarBean”) Private acme.Bar bar; 

D. @EJB(name=“ejab/barRef”, beanName=“BarBean”) Private acme.Bar bar; 

Answer:

Explanation: name is barRef 

Example: 

ejb-local-ref share [gp].share [fb].share [tw].contribute Via annotation Usable by EJB, Interceptor, Servlet, Filter, or Listener package org.superbiz.refs; 

import javax.ejb.EJB; 

import javax.ejb.Stateless; 

import javax.naming.InitialContext; 

@Stateless 

@EJB(name = "myFooEjb", beanInterface = FooLocal.class) 

public class MyEjbLocalRefBean implements MyBeanInterface { 

@EJB 

private BarLocal myBarEjb; 

public void someBusinessMethod() throws Exception { 

if (myBarEjb == null) throw new NullPointerException("myBarEjb not injected"); 

// Both can be looked up from JNDI as well 

InitialContext context = new InitialContext(); 

FooLocal fooLocal = (FooLocal) context.lookup("java:comp/env/myFooEjb"); 

BarLocal barLocal = (BarLocal) 

context.lookup("java:comp/env/org.superbiz.refs.MyEjbLocalRefBean/myBarEjb"); 

Via xml 

The above @EJB annotation usage is 100% equivalent to the following xml. 

<ejb-local-ref> 

<ejb-ref-name>myFooEjb</ejb-ref-name> 

<local>org.superbiz.refs.FooLocal</local> 

</ejb-local-ref> 

<ejb-local-ref> 

<ejb-ref-name>org.superbiz.refs.MyEjbLocalRefBean/myBarEjb</ejb-ref-name> 

<local>org.superbiz.refs.BarLocal</local> 

<injection-target> 

<injection-target-class>org.superbiz.refs.MyEjbLocalRefBean</injection-target-class> 

<injection-target-name>myBarEjb</injection-target-name> 

</injection-target> 

</ejb-local-ref> 

Q44. A stateless session bean FooBean implements an asynchronous business method foo() on its bean class: 

@Asynchronous 

public void foo() ( … ) 

The asynchronous business method is exposed through a remote business interface FooRemote. A caller acquires an EJB reference to this bean and invokes it as follows: 

100. fooRemoteRef.foo(); 

Which exception can result from the invocation on line 100? 

A. java.rmi.RemoteException 

B. java.util.concurrent.ExecutionException 

C. javax.ejb.EJBException 

D. java.lang.IllegalArgumentException 

Answer:

Explanation: 

Note: 

* RemoteRef represents the handle for a remote object. A RemoteStub uses a remote reference to carry out a remote method invocation to a remote object. 

* invoke 

public Object invoke(Remote obj, Method method, Object[] params, long opnum) throws Exception Invoke a method. This form of delegating method invocation to the reference allows the reference to take care of setting up the connection to the remote host, marshaling some representation for the method and parameters, then communicating the method invocation to the remote host. This method either returns the result of a method invocation on the remote object which resides on the remote host or throws a RemoteException if the call failed or an application-level exception if the remote invocation throws an exception. Parameters: 

Q45. 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 java.io.Serialization { 

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; 

13. Fooref.foo(data); 

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:

Q46. Which is true about caller security principal propagation for asynchronous EJB method Invocations? 

A. Caller security principal propagates along with an asynchronous EJB method invocation. 

B. Caller security principal does not propagate along with an asynchronous EJB method invocation. 

C. Caller security principal propagates along with an asynchronous EJB method invocation only if the target bean has at least one protected method. 

D. Caller security principal propagates along with an asynchronous EJB method invocation only if the calling bean has at least one protected method. 

Answer:

Explanation: One important caveat of asynchronous method invocation is that transactions are not propagated to the asynchronous method—a new transaction will be started for the asynchronous method. However, unlike transactions, the security principal will be propagated. 

Declarative security is based only on the principal and the method being invoked, whereas programmatic security can take state into consideration. 

Q47. Which two statements are true JMS message-driven beans? (Choose two.) 

A. The developer can use JMS message selector declarations to restrict the message that the bean receives. 

B. The developer can associate the bean with a specific queue or topic using the resource-ref element of the deployment descriptor. 

C. To achieve concurrent processing of more than one message at a time, more than one bean class must be associated with the same JMS queue. 

D. The developer can use the activationConfig element of the MessageDriven annotation to specify whether the bean should be associated with a queue or a topic. 

Answer: AD 

Explanation: A: Elements in the deployment descriptor 

The description of a MDB (message-driven beans) in the EJB 2.0 deployment descriptor contains the following specific elements: 

* the JMS acknowledgement mode: auto-acknowledge or dups-ok-acknowledge 

* an eventual JMS message selector: this is a JMS concept which allows the filtering of the messages sent to the destination 

* a message-driven-destination, which contains the destination type (Queue or Topic) and the subscription 

D: Example: 

The following example is a basic message-driven bean: 

@MessageDriven(activationConfig={ 

@ActivationConfigProperty(propertyName="destination", propertyValue="myDestination"), 

@ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue") 

}) 

public class MsgBean implements javax.jms.MessageListener { 

public void onMessage(javax.jms.Message msg) { 

String receivedMsg = ((TextMessage) msg).getText(); 

System.out.println("Received message: " + receivedMsg); 

Reference: Developing message-driven beans 

Reference: Message Driven Beans Tutorial 

Q48. An enterprise developer has received ejb-jars from multiple Bean Provides and wants to combine them into a single ejb-jar as well as altering the method permissions on some of the beans without recompiling any of the code contained in the ejb-jar. Which is correct? 

A. Bean Provide is the only role that can perform this task. 

B. Deployed is the most appropriate role to perform this task. 

C. Either a Deployer or System Administrator role many perform this task. 

D. This problem cannot be solved using an EJB 3.x-compliant approach. 

E. Application Assembler is the most appropriate role to perform this task. 

Answer:

Explanation: Application Assembler 

The Application Assembler combines enterprise beans into larger deployable application units. The input to the Application Assembler is one or more ejb-jar files produced by the Bean Provider(s). The Application Assembler outputs one or more ejb-jar files that contain the enterprise beans along with their application assembly instructions. 

Note: 

* EJB Structure 

The EJB Java ARchive (JAR) file is the standard format for assembling enterprise beans. This file contains the bean classes (home, remote, local, and implementation), all the utility classes, and the deployment descriptors (ejb-jar.xml and sun-ejb-jar.xml). 

* The Application Assembler can also combine enterprise beans with other types of application components when composing an application. 

Reference: Match the seven EJB roles with the corresponding description of the role's responsibilities. 

Q49. How many interceptor classes can be applied to a single stateful session bean? 

A. a maximum of one 

B. any number may be applied 

C. one for each business method 

D. one for each business interface 

Answer:

Explanation: The @Interceptors annotation can take an array of classes, so you can bind more than one class-level interceptor this way, e.g. 

@Stateless @Interceptors ({TracingInterceptor.class, SomeInterceptor.class}) public class EmailSystemBean { 

Reference: EJB Interceptors 

http://docs.jboss.org/ejb3/app-server/tutorial/interceptor/interceptor.html 

Q50. Suppose a developer wants to create an automatic persistent timer that performs data validation every hour. Given the following stateless session bean: 

@Stateless 

Public class OrderVerificationBean { 

Private void verificationExternalOrders () { 

/ / do something 

What is the minimum modification you would need to make to the bean to create the automatic persistent timer? 

A. Modify the verifyExternalOrders methos to look like this: @Schedule private void verifyExternalOrders () { / do something } 

B. Modify the verifyExternalOrders method to look like this: 

@Schedule (hour = “*”) 

private void verifyExternalOrders () { 

/ / do something 

C. Modify the verifyExternalOrders method to look like this: 

@Schedule (persistent = true) 

private void verifyExceptionalOrders () { 

/ / do something 

D. Modify the verifyExternalOrders method to look like this: 

@Schedule (hour = “*”, persistent = true) 

private void verifyExceptionalOrders () { 

/ / do something 

Answer:

Explanation: 

Not D: 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. 

Nonpersistent programmatic timers are created by calling TimerConfig.setPersistent(false) and passing the TimerConfig object to one of the timer-creation methods.