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

A developer writes an enterprise application and packages it into an .ear file. The application

contains two persistence units defined at the .ear level with persistence unit names FooPU and

BarPU. The application also contains an ejb-jar with one stateless session bean. Which code,

when added to the stateless session bean class, injects an EntityManagerFactory at runtime?



Options are :

  • @PersistenceContext private EntityManagerFactory emf;
  • @Resource(name="BarPU", type=EntityManagerFactory.class) private EntityManagerFactory emf;
  • @PersistenceUnit private EntityManagerFactory emf;
  • @PersistenceUnit(unitName="BarPU") private EntityManagerFactory emf;

Answer : @PersistenceUnit(unitName="BarPU") private EntityManagerFactory emf;

A session bean's business method invokes UserTransaction.setRollbackOnly and receives an

IllegalStateException. Under which circumstance can this happen?



Options are :

  • There is no circumstance that would cause setRollbackOnly to throw an IllegalStateException.
  • The setRollbackOnly method is invoked within a bean-managed transaction, and UserTransaction.commit has NOT been invoked.
  • The bean is using bean-managed transactions regardless of whether there is an active transaction.
  • The bean is using bean-managed transaction demarcation, and UserTransaction.begin has NOT been invoked.

Answer : The bean is using bean-managed transaction demarcation, and UserTransaction.begin has NOT been invoked.

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

A session bean's business method throws an exception during execution. Which two are

responsibilities of the Bean Provider when throwing the exception? (Choose two.)

A. For application exceptions, ensure that if the current transaction commits there will be no loss

of data integrity.

B. For application exceptions, ensure that the current transaction will commit.

C. For system errors, when the client is remote, throw a java.rmi.RemoteException that wraps the

original exception.

D. For checked exceptions from which the bean cannot recover, throw an EJBException that

wraps the original exception.


Options are :

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

Answer : A,D

Which statement is correct about the Java Persistence API support for the SQL queries?



Options are :

  • SQL queries are NOT allowed to use parameters.
  • SQL queries are expected to be portable across databases.
  • The result of an SQL query is not limited to entities.
  • Only SELECT SQL queries are required to be supported.

Answer : The result of an SQL query is not limited to entities.

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,E
  • A,C
  • A,B
  • A,D

Answer : A,E

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

Given a stateless session bean with container-managed transaction demarcation, from which two

methods can a developer access another enterprise bean? (Choose two.)

A. bean constructor

B. Timeout callback method

C. PreDestroy lifecycle callback method

D. PostConstruct lifecycle callback method

E. business method from the business interface


Options are :

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

Answer : B,E

FooBean and BarBean are both EJB 3.0 stateless session beans with container-managed

transaction demarcation. All business methods in FooBean have transaction attribute

REQUIRED, and all business methods in BarBean have transaction attribute REQUIRES_NEW.

The business method foo in FooBean invokes the business method bar in BarBean.

Given:

10. public class BarBean {

11. public void bar() {

12. throw new RuntimeException("unexpected error...");

13. }

Which is true about the result of this method invocation assuming execution reaches Line 12?



Options are :

  • FooBean.foo method receives javax.ejb.EJBTransactionRolledbackException.
  • FooBean.foo method receives the original RuntimeException thrown from BarBean.bar method.
  • FooBean.foo method receives javax.ejb.EJBException.
  • The BarBean bean instance is in ready state for the next invocation.

Answer : FooBean.foo method receives javax.ejb.EJBException.

A developer writes a stateful session bean with local business interface Bar containing method

test. Method test is implemented as :

11. @Remove

12. public void test() {}

A business method in a stateless session bean invokes a reference to bean Bar as follows :

11. @EJB Bar bar;

12.

13. public void foo() {

14. bar.test();

15. bar.test();

16. }

Assuming execution reaches Line 15, what is the expected result?



Options are :

  • A javax.ejb.NoSuchEntityException is thrown.
  • Method foo returns without error.
  • A java.rmi.NoSuchObjectException is thrown.
  • A javax.ejb.NoSuchEJBException is thrown.

Answer : A javax.ejb.NoSuchEJBException is thrown.

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

Given:

A stateless session bean's business method invokes EJBContext.setRollbackOnly and receives

an IllegalStateException.

Under which of these conditions could this be possible?



Options are :

  • The business method is marked with the NOT_SUPPORTED transaction attribute.
  • This is NOT possible; a stateless session bean cannot invoke EJBContext.setRollbackOnly.
  • The business method is marked with the MANDATORY transaction attribute.
  • The bean has no metadata (in annotations or deployment descriptor) which specifies the transaction attribute for the method.

Answer : The business method is marked with the NOT_SUPPORTED transaction attribute.

Given the following entity class:

11. @Entity public class Customer {

12. @Id private int id;

13. private transient String name;

14. private java.math.BigDecimal grossAmmount;

15. }

Which mapping annotation can be added to the fields of this entity?



Options are :

  • @JoinColumns to the grossAmmount field
  • @EmbeddedId to the id field
  • @Column to the name field
  • @Basic to the grossAmmount field

Answer : @Basic to the grossAmmount field

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,C
  • A,D
  • A,B
  • D,C

Answer : A,C

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

Which statement is true about both stateful session beans and stateless session beans?



Options are :

  • Any bean instance must be able to handle concurrent invocations from different threads.
  • The container passivates and activates them using methods annotated with @PrePassivate and @PostActivate annotations.
  • Bean instances are NOT required to survive container crashes.
  • A bean with bean-managed transactions must commit or roll back any transaction before returning from a business method.

Answer : Bean instances are NOT required to survive container crashes.

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.Serializable {

12. int a;

13. }

Method foo is implemented within 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.println(data.a);

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



Options are :

  • 2
  • 3
  • 1
  • 0

Answer : 1

Consider the following classes:

11. @Entity Auction {

12. @Id int id;

13. @OneToOne Item item;

14. }

11. @Entity Item {

12. @Id int id;

13. @OneToOne (mappedBy="item") Auction auction;

14. }

Given that the Auction entity maps to an AUCTION database table and the Item entity maps to an

ITEM database table, which statement is correct assuming there is NO mapping descriptor?



Options are :

  • The relationship is mapped to foreign keys in both ITEM and AUCTION tables.
  • The relationship is mapped to a foreign key in the AUCTION table.
  • The relationship is mapped to a foreign key in the ITEM table.
  • The relationship is mapped using a join table AUCTION_ITEM.

Answer : The relationship is mapped to a foreign key in the AUCTION table.

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

A developer is required to declare a persistent entity named Truck to map to a database table

VEHICLE. Which entity class declaration is correct, assuming there is NO mapping descriptor?



Options are :

  • 1. @Entity @Table(name="VEHICLE") public class Truck { 2. @Id int vehId; 3. double payload; 4. }
  • 1. @Entity(name="VEHICLE") public class Truck { 2. @Id int vehId; 3. double payload; 4. }
  • 1. @Entity(table="VEHICLE") public class Truck { 2. @Id int vehId; 3. double payLoad; 4. }
  • 1. @Embedded @Table("VEHICLE") public class Truck { 2. @Id int vehId; 3. double payload; 4. }

Answer : 1. @Entity @Table(name="VEHICLE") public class Truck { 2. @Id int vehId; 3. double payload; 4. }

Given the following client-side code that makes use of the session bean Foo:

10. @EJB Foo bean1;

11. @EJB Foo bean2;

//more code here

20. boolean test1 = bean1.equals(bean1);

21. boolean test2 = bean1.equals(bean2);

Which two statements are true? (Choose two.)

A. If Foo is stateful, test1 is true, and test2 is true.

B. If Foo is stateful, test1 is true, and test2 is false.

C. If Foo is stateless, test1 is true, and test2 is true.

D. If Foo is stateful, test1 is false, and test2 is false.

E. If Foo is stateless, test1 is true, and test2 is false.

F. If Foo is stateless, test1 is false, and test2 is false.


Options are :

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

Answer : B,C

XYZ Software develops business components using both the EJB 2.1 and EJB 3.0 APIs. Some

customers are reluctant to completely migrate to the EJB 3.0 model, but are willing to have EJB

2.1 session beans invoke EJB 3.0 session beans. How should XYZ Software enhance these

components to meet this customer requirement?



Options are :

  • Use @RemoteHome and @LocalHome to adapt EJB 3.0 beans so that EJB 2.1 beans can look up the adapted home interfaces using JNDI.
  • Add an EJB 3.0-style business interface to EJB 2.1 beans to achieve interoperability between EJB 2.1 and EJB 3.0 beans.
  • Use in ejb-jar.xml for the EJB 2.1 bean to declare a reference to the EJB 3.0 business interface.
  • Use @EJB to inject a reference to the EJB 3.0 business interface into the EJB 2.1 bean class.

Answer : Use @RemoteHome and @LocalHome to adapt EJB 3.0 beans so that EJB 2.1 beans can look up the adapted home interfaces using JNDI.

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

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



Options are :

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

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

A developer maps the abstract entity class Account with concrete entity sub-classes

CreditCardAccount and SavingsAccount using the single table per class hierarchy strategy. Which

two statements are true? (Choose two.)

A. Instances of CreditCardAccount and SavingsAccount are stored in the same table.

B. All columns that correspond to fields declared in Account must be defined as nullable in the

database.

C. The fields declared in Account are stored in a different table than the ones declared in

CreditCardAccount and SavingsAccount.

D. All columns that correspond to fields declared in CreditCardAccount or SavingsAccount must

be defined as nullable in the database.


Options are :

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

Answer : A,D

Given the following code snippet from an EJB 3.0 entity class:

1. package com.foo;

2. // more code here...

10. @Entity

11. @Table(name="A")

12. public class Order {

And the following excerpt from the persistence unit's orm.xml mapping file:

10. <entity class="com.foo.Order" access="PROPERTY">

11. <table name="B"/>

What is the name of the database table for Order objects?



Options are :

  • ORDER
  • The result is unpredictable.
  • A_B
  • B
  • A

Answer : B

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

A developer writes a stateless session bean with one local business interface and with containermanaged

transactions. All business methods have transaction attribute REQUIRED. The bean has

an injected field sessionCtx of the type SessionContext. Which two operations are allowed in a

business method of the bean? (Choose two.)

A. sessionCtx.getEJBObject

B. sessionCtx.setRollbackOnly

C. sessionCtx.getMessageContext

D. sessionCtx.getBusinessObject

E. sessionCtx.getEJBLocalObject


Options are :

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

Answer : B,D

Which statement is correct about the Java Persistence API support for the SQL queries?



Options are :

  • Only SELECT SQL queries are required to be supported.
  • The result of an SQL query is not limited to entities.
  • SQL queries are expected to be portable across databases.
  • SQL queries are NOT allowed to use parameters.

Answer : The result of an SQL query is not limited to entities.

A CMT session bean named MrBean contains a method storeStuff which is annotated as follows:

22. @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

23. public void storeStuff() {

All other methods of this bean have no transaction annotations.

Given the following part of an ejb-jar.xml:

23. <container-transaction>

24. <method>

25. <ejb-name>MrBean</ejb-name>

26. <method-name>*</method-name>

27. </method>

28. <transaction-attribute>NotSupported</transaction-attribute>

29. </container-transaction>

Which statement is correct about the methods in MrBean?



Options are :

  • Method storeStuff has transaction attribute REQUIRES_NEW and the other methods have transaction attribute REQUIRED.
  • All methods of MrBean have transaction attribute NOT_SUPPORTED.
  • Method storeStuff has transaction attribute NOT_SUPPORTED and the other methods have transaction attribute REQUIRED.
  • Method storeStuff has transaction attribute REQUIRES_NEW and the other methods have transaction attribute NOT_SUPPORTTED.
  • All methods of MrBean have transaction attribute REQUIRED.

Answer : All methods of MrBean have transaction attribute NOT_SUPPORTED.

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

A Java Persistence application has been developed for a Java SE environment and the

persistence.xml file looks like this:

<persistence-unit name="OrderManagement"

transaction-type=RESOURCE_LOCAL>

<mapping-file>order-mappings.xml</mapping-file>

<class>com.acme.Order</class>

<class>com.acme.Customer</class>

<class>com.acme.Item</class>

<properties>

<property name="com.acme.persistence.monitoring" value="ON"/>

</properties>

</persistence-unit>

Now the developer wants to repackage it as a Java EE application and try it on several compliant

Java EE 5 containers using injection to get an entity manager.

Which change is needed to make to the persistence.xml?



Options are :

  • Remove the vendor-specific properties.
  • Remove the list of all managed classes.
  • Remove the transaction type attribute.
  • Specify the JTA datasource.

Answer : Remove the transaction type attribute.

The ejb-jar file format is a contract between which two EJB role pairs? (Choose two.)

A. Deployer and System Administrator

B. Application Assembler and Deployer

C. Bean Provider and Application Assembler

D. Bean Provider and EJB Container Provider

E. EJB Server Provider and EJB Container Provider

F. Application Assembler and EJB Container Provider


Options are :

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

Answer : B,C

A developer is working with an entity User, which has an identity field and a salary field. Which

Java Persistence query will return those users with the highest salaries?



Options are :

  • SELECT u FROM User u WHERE u.salary >= ALL (SELECT d.salary FROM User d)
  • SELECT u FROM User u WHERE u.salary >= ANY (SELECT d.salary FROM User d)
  • SELECT u FROM User u WHERE u.salary >= (SELECT ALL(d.salary) FROM User d)
  • SELECT u FROM User u WHERE ALL(u.salary >= (SELECT d.salary FROM User d))

Answer : SELECT u FROM User u WHERE u.salary >= ALL (SELECT d.salary FROM User d)

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

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 client receives a return value of "zero".
  • The intercept method is NEVER invoked.
  • The client receives a return value of "not zero".
  • The client receives a return value of "intercepted".

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

EJB 3.0 containers must provide a specific subset of which two APIs? (Choose two.)

A. JSP APIs

B. JavaMail APIs

C. JAX-WS APIs

D. Java Card APIs

E. Sun Studio APIs


Options are :

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

Answer : B,C

Session bean A is a client of session bean B. Bean A is using container-managed transactions

and Bean A invokes a business method of bean B. Under which two circumstances does bean A

know for certain that continuing the transaction is fruitless? (Choose two.)

A. Bean A receives an application exception.

B. Bean A receives a java.rmi.RemoteException.

C. Bean A's invocation of UserTransaction.getStatus returns false.

D. Bean A's invocation of EJBContext.getRollbackOnly returns true.

E. Bean A receives a javax.ejb.EJBTransactionRolledbackException.


Options are :

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

Answer : D,E

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

Which two are true about specifying Java EE environment annotation metadata for session bean

classes? (Choose two.)

A. It is possible to inject a resource without using annotations.

B. Only field-level annotations can be overriden by the deployment descriptor.

C. Only type-level annotations can be overriden by the deployment descriptor.

D. Resource annotations cannot be specified on a superclass of the session bean class.

E. Type-level, method-level, and field-level annotations can all be overridden by the deployment

descriptor.

F. Only field-level annotations and method-level annotations can be overridden by the deployment

descriptor.


Options are :

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

Answer : A,E

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions