310-091 Sun Certified Bus. Component Developer Java EE Test Set 3

A developer is creating an entity which is mapped to a table that has a primary key constraint

defined on two character columns and would like to use mapping defaults as much as possible to

simplify the code. Which two mapping options can be chosen? (Choose two.)

A. Use an @Id property that constructs a private field as a concatenation of two columns.

B. Use a separate class to map those two columns and use an @IdClass annotation to denote the

primary key field or property in the entity.

C. Use a separate @Embeddable class to map those two columns and use an @EmbeddedId

annotation to denote a single primary key field or property in the entity.

D. Use a separate @Embeddable class to map those two columns and add two fields or

properties to the entity, each marked as @Id, that correspond to the fields or properties in the

embeddable class.

E. Use a separate class to map those two columns. Specify that class using @IdClass annotation

on the entity class. Add two fields or properties to the entity, each marked as @Id, that correspond

to the fields or properties in that separate class.


Options are :

  • C,A
  • C,B
  • C,E
  • C,D

Answer : C,E

An Application Assembler is given the following stateless session bean:

10. @Stateless public class MyBean implements MyInt {

11. @RolesAllowed("SECRET")

12. public void methodA(int x) {}

13. public void methodA(String y) {}

14. public void methodB(String z) {}

15. }

A deployment descriptor is also supplied, a portion of which reads as follows:

20. <method-permission>

21. <role-name>AGENT</role-name>

22. <method>

23. <ejb-name>MyBean</ejb-name>

24. <method-name>methodA</method-name>

25. </method>

26. </method-permission>

Which statement is true?



Options are :

  • A client in any role will be able to access any of the methods.
  • A client in the role "AGENT" will be able to access methodB and methodA(String), but not methodA(int).
  • A client in the role "AGENT" will be able to access any of the methods.
  • A client in the role "SECRET" will be able to access methodA(int) and methodB, but NOT methodA(String).
  • A client in the role "SECRET" will be able to access any of the methods.

Answer : A client in the role "AGENT" will be able to access any of the methods.

While executing a business method in a stateless session bean the container rolls back the

method's transaction. Which three are possible causes for the container's behavior? (Choose

three.)

A. The bean uses container-managed transactions and invokes EJBContext.setRollbackOnly.

B. The bean uses container-managed transactions and invokes EJBContext.getRollbackOnly.

C. The business method invokes a method that throws an uncaught

java.lang.NullPointerException.

D. The business method throws a checked exception of a class type that is marked with the

@ApplicationException annotation with the rollback element value false.

E. The business method throws an unchecked exception of a class type that is marked with the

@ApplicationException annotation with the rollback element value true.

F. The bean uses container-managed transactions and throws a checked exception of a class type

that is marked with the @ApplicationException annotation with the rollback element value false.


Options are :

  • A,C,E
  • A,C,D
  • A,C,B
  • D,C,E

Answer : A,C,E

310-091 Sun Certified Bus. Component Developer Java EE Test Set 4

An application wants to utilize side-effects of cascading entity-manager operations to related

entities. Which statement is correct?



Options are :

  • The persist operation is always cascaded to related entities for one-to-one and one-to-many relationships
  • To minimize the effect of the remove operation applied to an entity participating in a many-tomany relationship the remove operation should be cascaded to entities on both sides of the relationship.
  • The remove operation applied to a removed entity X is cascaded to entities referenced by X if the relationship from X to these other entities is annotated with the cascade=REMOVE or cascade=ALL annotation element value.
  • The persist operation applied to a new entity X is cascaded to entities referenced by X if the relationship from X to these other entities is annotated with the cascade=PERSIST or cascade=ALL annotation element value.

Answer : The persist operation applied to a new entity X is cascaded to entities referenced by X if the relationship from X to these other entities is annotated with the cascade=PERSIST or cascade=ALL annotation element value.

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.

<ejb-local-ref>

<ejb-ref-name>barRef</ejb-ref-name>

<local>acme.Bar</local>

<ejb-link>BarBean</ejb-link>

<injection-target>

<injection-target-class>acme.FooBean</injection-target-class>

<injection-target-name>bar</injection-target-name>

</injection-target>

</ejb-local-ref>

Which environment annotation, when declared within the FooBean bean class, is equivalent to the

ejb-local-ref shown above?




Options are :

  • @EJB(beanName="BarBean") private acme.Bar barRef;
  • @EJB(name="barRef", beanName="BarBean") private acme.Bar bar;
  • @EJB(name="ejb/barRef", beanName="BarBean") private acme.Bar bar;
  • @EJB(name="bar", beanName="BarBean") private acme.Bar barRef;

Answer : @EJB(name="barRef", beanName="BarBean") private acme.Bar bar;

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


Options are :

  • A,D
  • A,E
  • A,B
  • A,C

Answer : A,C

310-091 Sun Certified Bus. Component Developer Java EE Test Set 5

Given :

public class MyException extends Exception { }

The business interface Foo declares a method work():

1. public void work() throws MyException;

The bean class FooBean contains the following:

10. @Stateless

11. @Remote(Foo.class)

12. public class FooBean {

13. public void work() throws MyException {

14. //do some work not shown here

15. throw new MyException();

16. }

Assuming there is no deployment descriptor, which statement is true when the work() method is

invoked by a client with an existing transaction context and execution reaches Line 15?



Options are :

  • The container does not roll back the transaction.
  • The client receives javax.ejb.EJBTransactionRequiredException.
  • The client receives javax.ejb.EJBTransactionRolledbackException.
  • The container marks the transaction for rollback by calling the EJBContext.setRollbackOnly method.

Answer : The container does not roll back the transaction.

Given:

11. @Entity public class X {

12. @Id int id;

13. Y y;

14. }

A public class Y with NO Java Persistence annotations is defined in the same package.

Which statement is correct about these classes if NO other annotations and mapping descriptors

are provided?



Options are :

  • Class Y must be marked as an entity.
  • The entity X is not defined correctly.The field y must be marked as @Lob.
  • Class Y must be serializable.
  • Class Y must be accessed by a persistence application through a public interface.

Answer : Class Y must be serializable.

A company has a business application that allows end users to order products over the web. A

developer in the company wants to add the following capability to the application:

When the web-tier handles a new order, it should notify all the interested beans in the EJB-tier.

To satisfy this new capability, the developer wants to use a message-driven bean and must

choose between associating it with a javax.jms.Topic destination or a javax.jms.Queue

destination.

Which two are true about this decision? (Choose two.)

A. JMS Topics are intended to be used to solve this type of scenario.

B. JMS Queues are intended to be used to solve this type of scenario.

C. Only Queue destinations allow for messages to survive a server crash.

D. Topic destinations allow the developer to configure subscription durability.


Options are :

  • A,B
  • A,D
  • A,C
  • B,D

Answer : A,D

310-091 Sun Certified Bus. Component Developer Java EE Test Set 6

Which statement is true about the Timer service in an EJB 3.0 stateless session bean?



Options are :

  • The timeout callback method can throw application exceptions to report business logic failures.
  • The timeout callback method contains the business logic that handles the timeout event.
  • A bean class can implement multiple timeout callback methods, each associated with a different timer.
  • The timeout callback method must be declared as a business method in business interfaces.

Answer : The timeout callback method contains the business logic that handles the timeout event.

Which is the correct way of declaring bean-managed transaction demarcation for an EJB 3.0

message-driven bean?



Options are :

  • @MessageDriven public class MyMessageBean implements MessageListener { @TransactionManagement(TransactionManagementType.BEAN) public void onMessage(Message message) {...}
  • @MessageDriven(transactionManagement=TransactionManagementType.BEAN) public class MyMessageBean implements MessageListener {
  • @MessageDriven @TransactionManagement(TransactionManagementType.BEAN) public class MyMessageBean implements MessageListener {
  • @MessageDriven public class MyMessageBean implements MessageListener, UserTransaction {

Answer : @MessageDriven @TransactionManagement(TransactionManagementType.BEAN) public class MyMessageBean implements MessageListener {

Which Java Persistence query uses the aggregate function correctly, assuming that chairs field is

of type int?



Options are :

  • SELECT ANY(r.chairs) FROM Room r
  • SELECT NEW Integer(MAX(r.chairs)) FROM Room r
  • SELECT c FROM Chair c WHERE LOCATE (c.type, 'lazyboy') > -1
  • SELECT r FROM Room r WHERE r.chairs > AVG(r.chairs)

Answer : SELECT NEW Integer(MAX(r.chairs)) FROM Room r

310-091 Sun Certified Bus. Component Developer Java EE Test Set 7

Which two APIs must an EJB 3.0 container make available to enterprise beans at runtime?

(Choose two.)

A. The JXTA 1.1 API

B. The MIDP 2.0 API

C. The Java SE 6 API

D. The Java SE 5 JNDI API

E. The Java SE 5 JDBC API


Options are :

  • D,C
  • D,B
  • D,E
  • D,A

Answer : D,E

Which statement is true about the use of a persist operation in a transaction?



Options are :

  • The persist operation on an entity always cascades to its related entities.
  • If a user persists a managed entity an exception may be thrown by the persist operation.
  • If a user persists a new entity with an existing primary key the transaction will fail.
  • If a user persists a detached object it always becomes managed.

Answer : If a user persists a new entity with an existing primary key the transaction will fail.

A developer creates a stateful session bean that is used by many concurrent clients. The clients

are written by other development teams 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.


Options are :

  • C,D,A
  • C,D,B
  • B,D,E
  • C,D,E

Answer : C,D,E

310-091 Sun Certified Bus. Component Developer Java EE Test Set 8

Which two statements are true? (Choose two.)

A. All types of enterprise beans can be transaction-aware.

B. Typically, fine-grained objects, such as an employee record, should be remotely accessible.

C. The client view of any given enterprise bean will be consistent across all EJB 3.0 containers

without the need to recompile the bean.

D. As long as a given enterprise bean is NOT recompiled, its security attributes are guaranteed to

be consistent across all EJB 3.0 containers in which it is deployed.


Options are :

  • D,C
  • A,B
  • A,C
  • A,D

Answer : A,C

Given this code snippet from a JMS message-driven bean class X:

11. public X() { System.out.print("1 "); }

12. public void onMessage(Message m) throws java.rmi.RemoteException {

13. try {

14. TextMessage tm = (TextMessage) m;

15. String text = tm.getText();

16. System.out.print("2 ");

17. } catch (JMSException e) {

18. throw new java.rmi.RemoteException();

19. }

20. }

When this bean class handles a message, which is correct?



Options are :

  • This is NOT an EJB 3.0 compliant bean.
  • After a message delivery the result is unpredictable.
  • After a message delivery the result is 1.
  • After a message delivery an exception is thrown.

Answer : This is NOT an EJB 3.0 compliant bean.

A developer wants to release resources within a stateless session bean class. The cleanup

method should be executed by the container before an instance of the class is removed. The

deployment descriptor is NOT used. Which three statements are correct? (Choose three.)

A. The cleanup method may declare checked exceptions.

B. The cleanup method must have no arguments and return void.

C. The cleanup method is executed in an unspecified transaction and security context.

D. The developer should mark the cleanup method with the @PreDestroy annotation.

E. The developer should mark the cleanup method with the @PostDestroy annotation.

F. The cleanup method is executed in the transaction and security context of the last business

method invocation.


Options are :

  • B,C,A
  • B,C,D
  • B,C,F
  • B,C,E

Answer : B,C,D

310-091 Sun Certified Bus. Component Developer Java EE Test Set 9

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 perfomance 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:

1.checkGoods Checks goods in a database

2.getUniqueId Retrieve the unique ID

3.checkAmount Checks the amount in a non-transactional system

4.storeTransfer Stores the transfer in a database as part of the calling transaction.

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

following order:

checkGoods, getUniqueId, checkAmount, storeTransfer

Assuming no other transaction-related metadata, which is the correct set of transaction attributes

for the methods in the session beans?



Options are :

  • 0.addTransferREQUIRED 1.checkGoods REQUIRED 2.getUniqueIdREQUIRES_NEW 3.checkAmountsNEVER 4.storeTransferMANDATORY
  • 0.addTransferNOT_SUPPORTED 1.checkGoods REQUIRED 2.getUniqueIdREQUIRED 3.checkAmountsNOT_SUPPORTED 4.storeTransferMANDATORY
  • 0.addTransfer REQUIRED 1.checkGoods REQUIRED 2.getUniqueIdREQUIRES_NEW 3.checkAmountsNOT_SUPPORTED 4.storeTransferMANDATORY
  • 0.addTransferREQUIRED 1.checkGoods REQUIRED 2.getUniqueIdREQUIRED 3.checkAmountsREQUIRED 4.storeTransferREQUIRED

Answer : 0.addTransfer REQUIRED 1.checkGoods REQUIRED 2.getUniqueIdREQUIRES_NEW 3.checkAmountsNOT_SUPPORTED 4.storeTransferMANDATORY

Which two statements are correct about EJB 3.0 stateful session beans and stateless session

beans? (Choose two.)

A. Both can have multiple remote and local business interfaces.

B. Both can be passivated by the EJB container to preserve resources.

C. Both can choose to implement the javax.ejb.SessionSynchronization interface.

D. Only the stateful session bean class is required to implement java.io.Serializable.

E. Both bean classes can have the field injection of javax.persistence.EntityManager.


Options are :

  • A,D
  • A,B
  • A,C
  • A,E

Answer : A,E

The Java Persistence API defines the Query interface. Which two statements about the

Query.executeUpdate method are true? (Choose two.)

A. It must always be executed within a transaction.

B. It throws a PersistenceException if no entities were updated.

C. It throws an IllegalStateException if called on a Query instance created with a Java Persistence

SELECT query.

D. All managed entity objects corresponding to database rows affected by the update will have

their state changed to correspond with the update.


Options are :

  • A,D
  • D,C
  • A,C
  • A,B

Answer : A,C

310-110 Sun Certified Mobile Application Developer for J2ME Set 1

Given:

A session bean Foo uses container-managed transactions

The container throws a javax.transaction.TransactionRolledBackException when the

doStuff method runs

Which transaction attribute can the doStuff method have for this to occur?



Options are :

  • NOT_SUPPORTED
  • NEVER
  • REQUIRES_NEW
  • MANDATORY

Answer : MANDATORY

A developer writes two session beans which cooperate. The first session bean, ShoppingCart,

collects orders and is implemented as a stateful session bean. The second session bean,

CalculateDiscount, is implemented as a stateless session bean and runs on a different server.

ShoppingCart contains the method getTotalPrice, which calculates the total price of the order in

the ShoppingCart, including discounts. Discounts are calculated by CalculateDiscount using the

information on the ShoppingCart bean, combined with data from a database. Which scenario can

accomplish this?



Options are :

  • The CalculateDiscount offers a method calculate which is invoked by the ShoppingCart bean. CalculateDiscount accesses the state of ShoppingCart by dependency injection.
  • The CalculateDiscount offers a method calculate which is invoked by the ShoppingCart bean. CalculateDiscount accesses the ShoppingCart instance by JNDI lookup.
  • The CalculateDiscount offers a method calculate which is invoked by the ShoppingCart bean passing the this reference.
  • The CalculateDiscount offers a method calculate which is invoked by the ShoppingCart bean passing its reference obtained from the SessionContext.getBusinessObject method.

Answer : The CalculateDiscount offers a method calculate which is invoked by the ShoppingCart bean passing its reference obtained from the SessionContext.getBusinessObject method.

A session bean calls the setRollbackOnly method on the EJBContext interface within a business

method with an active transaction. Which two are correct? (Choose two.)

A. The transaction timeout is immediately disabled.

B. The container will ensure that the transaction will never commit.

C. The bean must have started the current transaction for this to be legal.

D. The bean must have bean-managed transaction demarcation for this to be legal.

E. The bean must have container-managed transaction demarcation for this to be legal.


Options are :

  • B,D
  • B,C
  • B,E
  • B,A

Answer : B,E

310-110 Sun Certified Mobile Application Developer for J2ME Set 11

A developer needs to include a set of managed classes in a persistence unit. Which two solutions

are correct? (Choose two.)

A. Place the class files in the orm.xml file.

B. Place the class files in the root of the persistence unit.

C. Place the class files in any mapping file that is included on the classpath.

D. Place the class files in any jar on the classpath that is included in the persistence unit.


Options are :

  • B,C
  • B,D
  • B,A
  • A,D

Answer : B,D

Which statement about mapping using the Java Persistence API is correct?



Options are :

  • User-defined XML mapping files can be used only if orm.xml file is NOT present.
  • The orm.xml file must be placed into the persistence unit's root to be processed by the persistence provider.
  • Mapping information specified in the XML mapping file overrides all annotations and default mappings.
  • All mapping files other than orm.xml must be listed explicitly in the persistence.xml descriptor.

Answer : All mapping files other than orm.xml must be listed explicitly in the persistence.xml descriptor.

A developer writes an interceptor class called FooInterceptor containing the following

AroundInvoke method:

11. @AroundInvoke

12. public Object intercept(InvocationContext ctx) {

13. return "intercepted";

14. }

FooInterceptor is applied to a business method in a stateless session bean:

11. @Interceptors(FooInterceptor.class)

12. public String testzero(int i) {

13. return (i == 0) ? "zero" : "not zero";

14. }

Which describes the result when a client invokes the testzero method with a value of 1?



Options are :

  • The intercept method is NEVER invoked.
  • The client receives a return value of "not zero".
  • The client receives a return value of "zero".
  • The client receives a return value of "intercepted".

Answer : The client receives a return value of "intercepted".

310-110 Sun Certified Mobile Application Developer for J2ME Set 12

A developer wants to use the Java Persistence query language. Which two are true? (Choose

two.)

A. A WHERE clause is required in every query.

B. The WHERE clause can restrict the scope of a delete operation.

C. The WHERE clause can be used to order the results returned by a query.

D. The WHERE clause is used to determine the types of objects to be retrieved from a persistent

store.

E. The WHERE clause is used to restrict the contents of a collection of objects that are returned

from a query.


Options are :

  • B,A
  • B,D
  • B,C
  • B,E

Answer : B,E

You have been asked to develop business methods for an enterprise bean to fulfill the following

objective:

If the JDBC connection is NOT available, the current state of the shopping cart session must be

serialized.

A serialized state must be written to a text file using a java.io.PrintWriter.

Data must be shared with a Web services end point.

Logging information must be displayed in a javax.swing.JPanel component.

Which is true?



Options are :

  • All of the requirements can be fulfilled using either session beans or message-driven beans.
  • Both session beans and message-driven beans can fulfill some but not all of the requirements.
  • The requirements can be fulfilled only in message-driven beans.
  • None of the requirements can be fulfilled using either session beans or message-driven beans.
  • The requirements can be fullfilled only in session beans.

Answer : Both session beans and message-driven beans can fulfill some but not all of the requirements.

A developer wants to create a business interface for both local and remote usage. For

performance reasons the remote interface should NOT be called by a client in the same JVM.

Which statement is required to accomplish this, assuming there is no deployment descriptor?



Options are :

  • The business methods are defined twice in one interface. One method is annotated with @Local and the other is annotated with @Remote.
  • The business methods are defined in a common interface. It is extended by two interfaces, annotated with @Local and @Remote respectively. Both interfaces are implemented by the bean class.
  • The business methods are defined in one interface which must be annotated with both @Local and @Remote.
  • The business methods are defined in a common interface by two other interfaces which are annotated with @Local and @Remote respectively. The bean implements the super interface.

Answer : The business methods are defined in a common interface. It is extended by two interfaces, annotated with @Local and @Remote respectively. Both interfaces are implemented by the bean class.

310-110 Sun Certified Mobile Application Developer for J2ME Set 2

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions