1Z0-895 | All About Accurate 1Z0-895 braindumps


Q11. A bean developer wants to write a stateless session bean class that implements the following remote business interface: 

@Remote 

Public interface Foo { 

Void bar () throws Exception; 

Which bean class method is valid? 

A. @Asynchronous 

public void bar () throws Exception { . . . } 

B. @Asynchronous 

Future <void> bar () { . . .} 

C. void bar () throws Exception { . . . } 

D. public void bar () { . . . } 

Answer:

Explanation: with EJB 3.1, you can use a simple session EJB with the @Asynchronous annotation on the method which must be called asynchronously. 

@Stateless 

@Remote(HelloEjbAsynchronousRemote.class) 

public class HelloEjbAsynchronous implements HelloEjbAsynchronousRemote { 

@Asynchronous 

@Override 

public Future<String> ejbAsynchronousSayHello(String name){ 

If your method has a return value, your method has to return an AsyncResult object which is an implementation of Future. 

Q12. A developer implements a system in which transfers of goods are monitored. Each transfer needs a unique ID for tracking purposes. The unique ID is generated by an existing system which is also used by other applications. For performance reasons, the transaction that gets the unique ID should be as short as possible. The scenario is implemented in four steps which are implemented in four business methods in a CMT session bean: 

These methods are called by the addTransfer method of a second CMT session bean in the following order: 

checkGooods, getUniqueId, checkAmount, storeTranfer 

Assuming no other transaction-related metadata, which is the correct set of transaction attributes for the methods in the session beans? 

A. 0.addTransferREQUIRED 

1.checkGoodsREQUIRED 

2.getUnigueIdREQUIRES_NEW 

3.checkAmountsNOT_SUPPORTED 

4.storeTransferMANDATORY 

B. 0.addTransferREQUIRED 

1.checkGoodsREQUIRED 

2.getUnigueIdREQUIRED 

3.checkAmountsREQUIRED 

4.storeTransferREQUIRED 

C. 0.addTransferREQUIRED 

1.checkGoodsREQUIRED 

2.getUnigueIdREQUIRES_NEW 

3.checkAmountsNEVER 

4.storeTransferMANDATORY 

D. 0.addTransferNOT_SUPPORTED 

1.checkGoodsREQUIRED 

2.getUnigueIdREQUIRES_NEW 

3.checkAmountsNOT_SUPPORTED 

4.storeTransferMANDATORY 

Answer:

Explanation: 

Step 2: Must start a new transaction. use REQUIRES_NEW 

Step 3: No need for this step: use Not Supported 

Use the.NotSupported.attribute for methods that don’t need transactions. Because transactions involve overhead, this attribute may improve performance. 

Step 4: Use Mandatory: 

Use the Mandatory attribute if the enterprise bean’s method must use the transaction of the client. 

Note: 

* In an enterprise bean with container-managed transaction (CMT) demarcation, the EJB container sets the boundaries of the transactions. You can use container-managed transactions with any type of enterprise bean: session, or message-driven. Container-managed transactions simplify development because the enterprise bean code does not explicitly mark the transaction’s boundaries. The code does not include statements that begin and end the transaction. 

* A transaction attribute can have one of the following values: 

Required RequiresNew Mandatory NotSupported Supports Never 

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

* RequiresNew Attribute If the client is running within a transaction and invokes the enterprise bean’s method, the container takes the following steps: 

Suspends the client’s transaction Starts a new transaction Delegates the call to the method Resumes the client’s transaction after the method completes If the client is not associated with a transaction, the container starts a new transaction before running the method. 

You should use the RequiresNew attribute when you want to ensure that the method always runs within a new transaction. 

* Mandatory 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 throws the TransactionRequiredException. 

Use the Mandatory attribute if the enterprise bean’s method must use the transaction of the client. 

* NotSupported Attribute If the client is running within a transaction and invokes the enterprise bean’s method, the container suspends the client’s transaction before invoking the method. After the method has completed, the container resumes the client’s transaction. 

If the client is not associated with a transaction, the container does not start a new transaction before running the method. 

Use the NotSupported attribute for methods that don’t need transactions. Because transactions involve overhead, this attribute may improve performance. 

Reference: The Java EE 5 Tutorial, Container-Managed Transactions 

Q13. 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:

Explanation: 

Note: 

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

Q14. Which two are programming restrictions in the EJB specification? (Choose two.) 

A. An enterprise bean must NOT attempt to load a native library. 

B. An enterprise bean must NOT declare static fields as final. 

C. An enterprise bean must NOT attempt to create a new security manager. 

D. An enterprise bean must NOT propagate a RuntimeException to the container. 

E. An enterprise bean must NOT attempt to obtain a javax.naming.InitialContext. 

Answer: AC 

Explanation: The following is a list of Java features that you should avoid, hence restricting their use in your EJB components' implementation code: 

(A) Loading native libraries. 

(C) Attempting to create or obtain a class loader, set or create a new security manager (C), stop the JVM, change the input, output, and error streams. That restriction enforces security and maintains the EJB container's ability to manage the runtime environment. 

(not B) Using static, nonfinal fields. Declaring all static fields in the EJB component as final is recommended. That ensures consistent runtime semantics so that EJB containers have the flexibility to distribute instances across multiple JVMs. 

Reference: Programming restrictions on EJB 

Q15. Suppose an EJB component is named HelloWorldBean is deployed as a standalone ejb-jar. Assuming the HelloWorldBean is implemented as follows: 

Which types of clients are guaranteed to have access to HelloWorldBean: 

A. Java EE application client container applications 

B. Java EE ejb components within the same ejb-jar 

C. Java EE web-tier component applications deployed in the same container 

D. Java EE ejb component applications deployed in the same container 

Answer:

Q16. A developer writes an interceptor class and a stateless session bean: 

A client acquires an EJB reference to the FooLocal business interface and invokes the foo() method one time. Which describes the output? 

A. Foo FooInt AInt 

B. AInt Foo 

C. AInt FooInt Foo 

D. FooInt AInt Foo 

Answer:

Explanation: * At the end of the chain of interceptors, the actual bean method gets called. 

* Interceptors can be bound in three different ways: Default 

Class level 

Method level 

In this question both class level and method level interceptors are used. 

The class level interceptor intercepts before the method-level interceptor. 

Note: 

* Interceptors are used in conjunction with Java EE managed classes to allow developers to invoke interceptor methods on an associated.target class, in conjunction with method invocations or lifecycle events. Common uses of interceptors are logging, auditing, and profiling. 

* An interceptor can be defined within a target class as an interceptor method, or in an associated class called an interceptor class. Interceptor classes contain methods that are invoked in conjunction with the methods or lifecycle events of the target class. 

Interceptor classes and methods are defined using metadata annotations, or in the deployment descriptor of the application containing the interceptors and target classes. 

* javax.interceptor.AroundInvoke 

Designates the method as an interceptor method. 

* The target class can have any number of interceptor classes associated with it. The order in which the interceptor classes are invoked is determined by the order in which the interceptor classes are defined in the.javax.interceptor.Interceptors.annotation. 

Reference: Introduction to EJB3 Interceptors 

Reference: The Java EE 6 Tutorial, Overview of Interceptors 

Q17. An enterprise bean has security permissions set up using declarative security features. 

Under which two conditions can a client be guaranteed to have permission to invoke a business method on the enterprise bean? (Choose two.) 

A. The Application Assembler has marked the enterprise bean method as unchecked. 

B. The client's principal has been assigned a security role with permission to invoke the method. 

C. The Application Assembler has set the security-identity deployment descriptor to run-as. 

D. The Application Assembler has mapped all security role references using the role-link element. 

Answer: AB 

Q18. Which two annotations can be applied at the class, method, and field levels? (Choose two.) 

A. @EJB 

B. @Init 

C. @Resource 

D. @RolesAllowed 

E. @PostActivate 

Answer: AC 

Explanation: A: javax.ejb.EJB Description 

Target: Class, Method, Field 

Specifies a dependency or reference to an EJB business or home interface. 

You annotate a bean’s instance variable with the @EJB annotation to specify a dependence on another EJB. 

C: javax.annotation.Resource Description 

Target: Class, Method, Field 

Specifies a dependence on an external resource, such as a JDBC data source or a JMS destination or connection factory. 

Incorrect: 

B: javax.ejb.Init Description Target:.Method 

D: javax.annotation.security.RolesAllowed Description Target:.Class, Method Specifies the list of security roles that are allowed to access methods in the EJB. 

E: javax.ejb.PostActivate Description Target:.Method Specifies the lifecycle callback method that signals that the EJB container has just reactivated the bean instance. 

Reference: EJB 3.0 Metadata Annotations Reference 

Q19. 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:

Q20. 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 @Init annotated method. 

C. Release references to resources in a @PreDestroy annotated method. 

D. Release references to resources in a @PrePassivate annotated method. 

E. Re-establish references to resources in a @PostActivate annotated method. 

Answer: CDE