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

A developer implemented a Java class called Store. The class is annotated correctly to act as an

entity. The developer created a stateless session bean to create, lookup, and remove Store

objects. This session bean has a container-managed entity manager injected into field em and a

removeStore method with transaction attribute REQUIRED.

Given the following code :

32. public void removeStore(Store store) {

33. em.remove(store);

34. }

What is a possible reason that an IllegalArgumentException is thrown at Line 33 when the

removeStore method is called by a remote client?



Options are :

  • The passed object is NOT serializable.
  • The passed object is NOT found in the database.
  • The passed object is NOT managed by the entity manager.
  • There is no active transaction to manage the database removal.

Answer : The passed object is NOT managed by the entity manager.

A developer is implementing a message-listener method of an EJB 3.0 message-driven bean. The

developer wants to make sure that the message receipt is immediately rolled back in case the

message listener method is aborted with a runtime exception. Which option can the developer

use?



Options are :

  • Use Container-Managed Transactions with transaction attribute REQUIRED.
  • Use Bean-Managed Transactions and write a try-catch-finally block that calls UserTransaction.rollback in case of a RuntimeException.
  • Use Container-Managed Transactions with transaction attribute NOT_SUPPORTED.
  • Use Bean-Managed Transactions and the JMS API for message acknowledgement.

Answer : Use Container-Managed Transactions with transaction attribute REQUIRED.

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 :

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

Answer : A,D

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

Which is a valid way of injecting a container-managed transaction-scoped persistence context into

an EJB 3.0 session bean assuming the application contains only one persistence unit?



Options are :

  • @Resource(name="persistence/em", authenticationType=AuthenticationType.CONTAINER) protected EntityManager em;
  • @PersistenceContext private EntityManager em;
  • @PersistenceUnit public EntityManager em;
  • @TransactionManagement(TransactionManagementType.CONTAINER) public EntityManager em;

Answer : @PersistenceContext private EntityManager em;

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
  • @Basic to the grossAmmount field
  • @Column to the name field
  • @EmbeddedId to the id field

Answer : @Basic to the grossAmmount field

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 packaging 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

emp-ejb.jar

EmployeeService.class

EmployeeServiceBean.class

Employee.class

Department.class

C. emp.ear

emp-ejb.jar

META-INF/persistence.xml

Employee.class

Department.class

EmployeeService.class

EmployeeServiceBean.class

D. emp.ear

emp-ejb.jar

persistence.xml

Employee.class

Department.class

EmployeeService.class

EmployeeServiceBean.class


Options are :

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

Answer : A,C

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

Your application uses the Java Persistence API to access a database. This application must reject

adding an instance to the database if it does NOT pass validation tests for values of two

persistence properties. The database contains some data that will NOT pass such validation. Only

the new records must be validated. Which option will achieve this behavior?



Options are :

  • Add the PrePersist callback method with all of the validation logic.
  • Add PrePersist and PreUpdate callback methods with all of the validation logic.
  • Add validation logic to the setter methods for each property.
  • Add the PostPersist callback method with all of the validation logic.

Answer : Add the PrePersist callback method with all of the validation logic.

A developer obtains a java.security.Principal object by calling the

SessionContext.getCallerPrincipal method from within a business method of a session bean.

Which statement is true?



Options are :

  • The roles which the Principal is in can be determined from this Principal object.
  • The returned Principal object can be null.
  • The return value of Principal.getName depends on the security realm which was used to authenticate the caller.
  • The return value of the Principal.getName method is exactly the same as the username used for authentication of the caller.

Answer : The return value of Principal.getName depends on the security realm which was used to authenticate the caller.

The Java Persistence entity LineItem defines a composite primary key that is defined by the two

columns ORDERID and LINEITEMID in the database. Which two are true? (Choose two.)

A. LineItem must define a primary key class to represent the composite primary key.

B. The composite primary key is mapped as two fields in LineItem. No extra primary key class is

necessary.

C. The combination of @Embedded and @Embeddable annotations can be used to denote the

composite primary key.

D. The semantics of the equals and hashCode methods of the primary key class must be

consistent with the database equality.


Options are :

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

Answer : A,D

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

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 ITEM table.
  • The relationship is mapped using a join table AUCTION_ITEM.
  • The relationship is mapped to a foreign key in the AUCTION table.

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

Which statement is correct about a Java EE client of a message-driven bean?



Options are :

  • The client can use JNDI to obtain a reference to a dependency injection.
  • The client can use JNDI to obtain a reference to a message-driven bean instance.
  • The client can use JNDI to look up a reference to the message-driven bean's home interface.
  • The client can use JNDI to obtain a reference to a message destination.

Answer : The client can use JNDI to obtain a reference to a message destination.

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

Given:

11. @PersistenceContext EntityManager em;

12. public boolean test(Order o) {

13. boolean b = false;

14. o = em.merge(o);

15 em.remove(o);

16. o = em.merge(o);

17. b = em.contains(o);

18. return b;

19. }

Which statement is correct?



Options are :

  • The method will throw an exception.
  • The method will return FALSE.
  • The method will return TRUE.
  • The Order instance will be removed from the database.

Answer : The method will throw an exception.

A Java Persistence application uses entities mapped to tables from two datasources in the same

transaction. What statement is correct?



Options are :

  • The entities must be packaged using two different persistence.xml files.
  • The entities must be packaged into two persistence units.
  • This is NOT possible.
  • The entities can be packaged into a single persistence unit

Answer : The entities must be packaged into two persistence units.

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

Answer : B,D

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

A developer has created an application-managed entity manager. Which statement is correct?



Options are :

  • A new persistence context begins when the entity manager is invoked in the context of a resource-local transaction.
  • A new persistence context begins when a new JTA transaction begins.
  • A new persistence context begins when the entity manager is invoked in the context of a JTA transaction.
  • A new persistence context begins when the entity manager is created.

Answer : A new persistence context begins when the entity manager is created.

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 :

  • The requirements can be fulfilled only in message-driven beans.
  • All of the requirements can be fulfilled using either session beans or message-driven beans.
  • None 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 fullfilled only in session beans.

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

A User entity is in a one-to-many relationship with a Book entity.

A developer writes a query to delete users that have a first name of 'Fred' or 'Ginger', and writes

the following Java Persistence query language statement:

DELETE FROM User u WHERE u.name IN ('Fred', 'Ginger')

If the query fails with a PersistenceException, what can be the cause?



Options are :

  • The query causes a foreign key integrity constraint to be violated.
  • The entities corresponding to the users with the name 'Fred' or 'Ginger' are already being managed by the persistence context.
  • The database does NOT have any users with the name 'Fred' or 'Ginger'.
  • None
  • The syntax of the query is NOT correct.

Answer : The query causes a foreign key integrity constraint to be violated.

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

A developer creates a stateless session bean. This session bean needs data from a remote

system. Reading this data takes a long time. Assume that the data will NOT change during the

lifetime of the bean and that the information to connect to the remote system is defined in JNDI.

Which statement describes how to manage the data correctly?



Options are :

  • The data can only be read in the bean's business methods.
  • Read the data in a method which is annotated with @PostActivate.
  • Read the data in a method which is annotated with @PrePassivate.
  • Read the data in the bean's constructor.
  • Read the data in a method which is annotated with @PostConstruct.

Answer : Read the data in a method which is annotated with @PostConstruct.

FooBean is an EJB 3.0 session bean that can make valid use of UserTransaction. Which is

guaranteed to work in an EJB container for FooBean to obtain the UserTransaction object?



Options are :

  • Perform JNDI lookup with the name "jdbc/UserTransaction" on an InitialContext.
  • Invoke a method on a SessionContext that returns a UserTransaction object.
  • Use the @TransactionManagement annotation to inject an instance variable of type UserTransaction in a bean class.
  • Perform JNDI lookup with name "java:/UserTransaction" on an InitialContext.

Answer : Invoke a method on a SessionContext that returns a UserTransaction object.

A developer writes client code that runs in a Java EE container and accesses an EJB 3.0 stateful

session bean. Which three statements are correct? (Choose three.)

A. The client can obtain a reference to the bean's business interface through JNDI lookups.

B. The client can obtain a reference to the bean's business interface through dependency

injection.

C. If the client calls a business method after the bean instance has been removed an exception

will occur.

D. After obtaining a reference to the bean's business interface, the client must call the create

method before it may call business methods.

E. After the bean instance has been passivated, the client needs to re-obtain a reference to the

bean's business interface to activate the bean instance.


Options are :

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

Answer : A,B,C

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

A developer is designing a Java Persistence application that is mapped to a set of existing tables.

This set includes table EMPLOYEE, DEPARTMENT, and PROJECT. Tables EMPLOYEE and

DEPARTMENT do NOT define any foreign key constraints to table PROJECT. Table PROJECT

defines foreign key constraints with references to tables EMPLOYEE and DEPARTMENT and an

extra column called COST. The table EMPLOYEE is mapped to an entity Employee and the table

DEPARTMENT to an entity Department.

How can the table PROJECT be mapped so the persistence application can be portable?



Options are :

  • Map the table PROJECT to bidirectional many-to-many relationships between the Employee and Department using a java.util.Map as the type of the field or property.
  • Such sets of tables cannot be mapped and keep the application portable.
  • Map the table PROJECT as a secondary table for either the Employee or Department entity.
  • Map the table PROJECT to an entity Project with a field or property cost mapped to the column COST and one-to-many relationships to this entity in the Employee and the Department.

Answer : Map the table PROJECT to an entity Project with a field or property cost mapped to the column COST and one-to-many relationships to this entity in the Employee and the Department.

A Java Persistence application wants to use optimistic locking. Which statement that describes the

functionality of optimistic locking is correct?



Options are :

  • Optimistic locking can be used by Java Persistence applications to set optimistic locks on tables in the database.
  • Optimistic locking ensures that updates or deletes are consistent with the current state of the database and that intervening updates are not lost.
  • The Version attribute of an entity using optimistic locking can be mapped to a secondary table.
  • The Version attribute of an entity using optimistic locking is verified each time the instance is loaded from the database.

Answer : Optimistic locking ensures that updates or deletes are consistent with the current state of the database and that intervening updates are not lost.

A developer writes a stateful session bean FooBarBean 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 invokes 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. }



Options are :

  • return (Bar) sessionCtx.getBusinessObject(Bar.class);
  • return (Bar) new FooBarBean();
  • InitialContext ic = new InitialContext(); return (Bar) ic.lookup("java:comp/env/ejb/FooBarBean");
  • return (Bar) this;
  • return (Bar) sessionCtx.lookup("FooBarBean")

Answer : return (Bar) sessionCtx.getBusinessObject(Bar.class);

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

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

Answer : A,C

A developer wants to implement a relationship between Company and Department entity classes.

Every department belongs to one company, and one company has several departments. In this

application it is essential to quickly determine which company a department belongs to and to also

easily access all departments of a given company. Which two declarations provide a solution to

these requirements? (Choose two.)

A. In class Department:

@ManyToOne

private Company company;

B. In class Department:

@OneToMany

private Company company;

C. In class Department:

@OneToMany(mappedBy="department")

private Collection<Company> companies;

D. In class Company:

@ManyToOne(mappedBy="company")

private Collection<Department> departments;

E. In class Company:

@OneToMany(mappedBy="company")

private Collection<Department> departments;


Options are :

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

Answer : A,E

Within a Java EE environment, which annotation can be used to inject an entity manager factory?



Options are :

  • @JTAFactory
  • @Factory
  • @Entity
  • @PersistenceUnit
  • @PersistenceContext

Answer : @PersistenceUnit

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

A developer wants to create a Java Persistence query that restricts the results of an age-based

query. Specifically, the developer wants to select everyone who is NOT a teenager. (A teenager is

someone who is 13, 14, 15, 16, 17, 18, or 19 years old.) Which expression in the query's WHERE

clause is correct?



Options are :

  • WHERE p.age NOT BETWEEN 13 and 19
  • WHERE p.age NOT BETWEEN 12 and 19
  • WHERE p.age NOT BETWEEN 13 and 20
  • WHERE p.age NOT BETWEEN 12 and 20

Answer : WHERE p.age NOT BETWEEN 13 and 19

Which two are true about EJB 3.0 exception classes? (Choose two.)

A. The javax.ejb.NoSuchEJBException is an application exception.

B. The javax.ejb.EJBException extends java.lang.RuntimeException.

C. The javax.ejb.EJBTransactionRequiredException is an application exception.

D. An application exception must NOT be a subclass of java.rmi.RemoteException.

E. The javax.ejb.EJBTransactionRolledbackException is an application exception.

F. Any subclass of java.lang.RuntimeException is always considered a system exception.


Options are :

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

Answer : B,D

A deployer is given the following session bean:

10. @Stateless

11. @RolesAllowed("BATH")

12. @DeclareRoles("SOAP")

13. public class ShowerBean implements Shower {

14. public void plug() {}

15. }

and the following associated excerpt from the ejb-jar.xml descriptor file:

20. <assembly-descriptor>

21. <security-role>

22. <role-name>TOWEL</role-name>

23. </security-role>

24. </assembly-descriptor>

Which roles is the deployer expected to map to users or user groups?



Options are :

  • BATH and TOWEL
  • TOWEL
  • BATH and SOAP
  • BATH and SOAP and TOWEL

Answer : BATH and SOAP and TOWEL

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

The execution of the find method in the following code throws an exception:

11. em.find(Customer.class, custId);

12. //Where em is a reference to a extended scoped entity manager.

Which scenario can cause the exception?



Options are :

  • The data type of custId is NOT a valid type for the Customer entity primary key.
  • The entity corresponding to the requested primary key has been removed.
  • The find method was called without a transaction.
  • The entity corresponding to the requested primary key has been detached.

Answer : The data type of custId is NOT a valid type for the Customer entity primary key.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions