EJB MT solutions of Niit Ques. 76 to 100

EJB MT solutions of Niit Ques. 76 to 100












SNo: 76
Ques: Michael is implementing a banking site. He has created a session bean namely, the SavingAccount and added a method the validateClient. He wants that this method should always run in the client's context. Which of the following transaction attribute will help Michael to achieve this?
Options:
  ? 1,Michael can use the REQUIRES_NEW attribute.
  ? 2,Michael can use the REQUIRED attribute.
  ? 3,Michael can use the SUPPORTS attribute.
  ? 4,Michael can use the MANDATORY attribute.
Answer: 4
Marks: 3

=============================================================

SNo: 77
Ques: Samuel is implementing a banking site. He has created a session bean namely, the SavingAccount and added a createNewAccount method to create a new account. He wants that this method should rollback the transaction if any error occurs while creating the user. In such a case, which of the following methods can be used to rollback the transaction attributes?
Options:
  ? 1,The setRollbackOnly method can be called on the transaction to set the flag so that it can be rollbacked once the method returns.
  ? 2,The getRollbackOnly method can be called on the transaction to set the flag so that it can be rollbacked once the method returns.
  ? 3,The setRollback method can be called on the transaction to set the flag so that it can be rollbacked once the method returns.
  ? 4,The rollBack method can be called on the transaction to set the flag so that it can be rollbacked once the method returns.
Answer: 1
Marks: 3

=============================================================

SNo: 78
Ques: Matt is implementing a human resources management site. He has created a Employee stateful session bean and added a processHike(double arg) method to process the salary hike of an employee. This method updates employee record in the database with the increased salary and also updates the salary field of the bean. Matt wants to listen to transaction events so that if the transaction is rolledback outside the processHike method's scope the salary field in the employee bean can be updated back to the original value. Which of the following options can Matt use to listen to transaction events?
Options:
  ? 1,Matt can listen to transaction events by implementing SessionSynchronization interface in the employee bean, so that the bean can get notifications depending upon the state of the transaction.
  ? 2,Matt cannot listen to transaction events as it is not possible to listen to the transaction from a stateful session bean.
  ? 3,Matt can by default listen to transaction events without any extra efforts as stateful session beans by default are notified with transaction states
  ? 4,Matt cannot listen to transaction events as it is possible to listen to the transaction only from a stateless session bean and not from a stateful session bean.
Answer: 1
Marks: 3

=============================================================

SNo: 79
Ques: You are implementing a human resource site. You have created two entity beans named Employee and Person, which has createEmployee and createPerson methods respectively. The createEmployee methods calls createPerson method to create a person record for an employee. You want that the Employee bean should use Manager role while calling the Person bean's method. Identify which of the following options meets this requirement.
Options:
  ? 1,Yes, a run-as annotation can be used to associate a run-as identity to a bean's method.
  ? 2,Yes, a run-as element in deployment descriptor can be added to associate a run-as identity to a bean's method.
  ? 3,No, it is not possible to specify a different identity when a bean method calls another bean's methods.
  ? 4,Yes, a use-caller-identity element in deployment descriptor can be used to associate a run-as identity to a bean's method.
Answer: 2
Marks: 3

=============================================================

SNo: 80
Ques: You have a stateless session bean, the AccountBean which has two methods createAccount and debitAccount. The createAccount method should be executed only by a user with the SYSTEM_ADMINISTRATOR role whereas the debitAccount can be executed by a user with ACCOUNT_MANAGER and SYSTEM_ADMINISTRATOR role. What should be the security implementation for the AccountBean?
Options:
  ? 1,@Stateless @RolesAllowed("SYSTEM_ADMINISTRATOR")
public class AccountBean implements Account{
    public int createAccount() {?}
    public void debitAccount(double value) {?}
}
  ? 2,@Stateless @RolesAllowed({"SYSTEM_ADMINISTRATOR","ACCOUNT_MANAGER"})
public class AccountBean implements Account{
    public int createAccount() {?}
    public void debitAccount(double value) {?}
}
  ? 3,@Stateless
public class AccountBean implements Account{
    @RolesAllowed({"SYSTEM_ADMINISTRATOR","ACCOUNT_MANAGER"})
    public int createAccount() {?}
    @RolesAllowed({"SYSTEM_ADMINISTRATOR","ACCOUNT_MANAGER"})
    public void debitAccount(double value) {?}
}
  ? 4,@Stateless
public class AccountBean implements Account{
    @RolesAllowed("SYSTEM_ADMINISTRATOR")
    public int createAccount() {…}
    @RolesAllowed({"SYSTEM_ADMINISTRATOR","ACCOUNT_MANAGER"})
    public void debitAccount(double value) {…}
}
Answer: 4
Marks: 3

=============================================================

SNo: 81
Ques: Simon is implementing a Job site and has been entrusted with the task of sending a notification to all the users, whose password has expired. To meet this requirement, Simon plans to create a named query using the NamedQuery metadata annotation, to fetch all such user records. The USERS table has USER_ID, USER_NAME, PASSWORD, PASSWORD_EXPIRY_DATE columns and the entity bean created for this table is Users with the fields userId, userName, password, and passwordExpiryDate. Which of the following options will Simon use to create this named query?
Options:
  ? 1,@NamedQuery(name = "findExpiredUsers", query = "select OBJECT(u) FROM Users u WHERE u.passwordExpiryDate is not null and passwordExpiryDate <= :passwordExpiryDate")
  ? 2,@NamedQuery(name = "findExpiredUsers", query = "select OBJECT(u) FROM Users u WHERE u.passwordExpiryDate is not null)
  ? 3,entityManager.createQuery
("select OBJECT(u) FROM Users u WHERE u.passwordExpiryDate is not null "+
" and passwordExpiryDate <= :passwordExpiryDate");
  ? 4,entityManager.createNativeQuery
("SELECT OBJECT(u) FROM Users u WHERE u.passwordExpiryDate is not null "+
" and passwordExpiryDate <= :passwordExpiryDate");
Answer: 1
Marks: 3

=============================================================

SNo: 82
Ques: Sam is implementing a banking site and has created a SavingAccount entity bean for the SAVING_ACCOUNT table. The SavingAccount bean has a validateAccount method, which validates the account data before committing it to the database. The validateAccount method is coded in such a way that if the data is invalid it throws an application exception. While testing the SavingAccount bean Sam found out that even though the application exception is thrown the container does not rollback the transaction. Sam expected that the container would rollback the transaction if the exception is thrown. Which of the following options can be used rectify this unexpected behavior?
Options:
  ? 1,You can rectify this unexpected behavior by modifying the existing application exception with @ApplicationException(rollback=true) annotation to indicate that container needs to rollback the transaction if this exception is thrown.
  ? 2,You can rectify this unexpected behavior by changing the code to throw a SQLException.
  ? 3,You can rectify this unexpected behavior by changing the code to throw a IOException.
  ? 4,You can rectify this unexpected behavior by modifying the existing application exception with @ApplicationException(onErrorRollback=true) annotation to indicate that container needs to rollback the transaction if this exception is thrown.
Answer: 1
Marks: 3

=============================================================

SNo: 83
Ques: Nancy is implementing a social networking site. She has created a Person entity bean for the PERSON table which is used to store the person information. There is a setDateOfBirth(String) method in the entity bean which accepts dates as Strings in dd-mm-yyyy format and converts them to java.util.Date using a date formatter. The date formatter used in the method throws ParseException that should be catched. Nancy wants that if a date string is passed in a wrong format the caller should get an exception. As this condition is non-fatal the transaction should not be rollbacked. Which of the following options she will choose for her catch block to correctly implement her requirement?
Options:
  ? 1,She will catch the ParseException and will not throw any exception in the catch block.
  ? 2,She will catch the ParseException and will throw again a ParseException error in the catch block.
  ? 3,She will catch the ParseException and will throw a wrapper system exception in the catch block.
  ? 4,She will catch the ParseException and will throw a wrapper application exception in the catch block.
Answer: 4
Marks: 3

=============================================================

SNo: 84
Ques: Mira is working on banking site and has created a SavingAccount entity bean for the SAVING_ACCOUNT table. However, Mira's code is giving unexpected results and she asks Wendy to review her code of the SavingAccount bean. Wendy on observation finds that the updateAccount method throwing java.rmi.RemoteException to indicate a catastrophic error. How will Wendy rectify Mira's code?
Options:
  ? 1,Wendy does not need to rectify anything because RemoteException is a valid exception and developers can throw this error from an entity bean.
  ? 2,Wendy will change the code to throw EJBException instead of the RemoteException.
  ? 3,Wendy will change the code to throw an application exception instead of the RemoteException.
  ? 4,Wendy will change the code to throw OutOfMemoryError instead of the RemoteException.
Answer: 2
Marks: 3

=============================================================

SNo: 85
Ques: You are implementing a human resource site. You have created the following named query to fetch names of all the employees along with the name of their manager.
SELECT e.name, m.name FROM Employee e JOIN Manager m WHERE e.managerId = m.managerId
The Employee record is stored in the EMPLOYEE table and the Manager record is stored in the MANAGER table. Primary key column for EMPLOYEE table is EMPLOYEE_ID and primary key column for MANAGER table is MANAGER_ID. MANGER_ID column in the EMPLOYEE table references MANAGER_ID column in the MANAGER table. This site was using a MySQL database till now but now the client wants to move to an Oracle database. In such a case, observe the preceding query and identify whether you need to make any changes to it? If yes how?

Options:
  ? 1,Yes, you will have to make changes as the Oracle database does not support JOIN keyword and the following changes will need to be made to the query.
SELECT e.name,m.name FROM Employee e,Manager m WHERE e.managerId = m.managerId
  ? 2,Yes, you will have to make changes as the Oracle database is case sensitive and the following changes will need to be made to the query.
select e.name,m.name from Employee e join Manager m where e.managerId = m.managerId
  ? 3,Yes, you will have to make changes as the Oracle database is case sensitive and does not support the JOIN keyword. Therefore, the following changes will need to be made to the query.
select e.name,m.name from Employee e, Manager m where e.managerId = m.managerId
  ? 4,No, you will not have to make any changes as named queries created using Java Persistence Query language are database independent and need not be changed while changing the database server vendor.
Answer: 4
Marks: 3

=============================================================

SNo: 86
Ques: You have been entrusted with the task of creating an indexing module for a job site. This module will create indexes of the resumes uploaded by the candidates during registration. These indexes need to be created for better and faster search results. Identify which of the following techniques will you use to develop this module?


Options:
  ? 1,You will create a normal class file which will be called during the registration flow while uploading the resumes to create indexes on the fly.
  ? 2,You will create a Message-driven bean which will perform the indexing job and modify the resume uploading code so that it creates a index as soon as a resume is uploaded.
  ? 3,You will create a timer program which will be scheduled to run daily in the night. This program will look for all the newly uploaded resumes and create indexes for them.
  ? 4,You will create a Java standalone program which will be called manually by the system administrator to create indexes when required.
Answer: 2
Marks: 3

=============================================================

SNo: 87
Ques: Sam is implementing a banking site. He has created a session bean, User which produces messages that are consumed synchronously by entity bean namely SavingAccount. The messages are consumed synchronously so till the SavingAccount bean finishes processing the messages server resources remains locked. Which of the following options can Sam use to optimize the use of resources?
Options:
  ? 1,Create a message driven bean to process the messages instead of SavingAccount bean.
  ? 2,Upgrade the server so that it has ample resources.
  ? 3,Instead of Java EE use some other architecture that allows asynchronous message consumers.
  ? 4,Messages can only be processed synchronously, so nothing can be done in this scenario.
Answer: 1
Marks: 3

=============================================================

SNo: 88
Ques: Sam is using IBM's WebSphere application server for his Java EE based banking site. WebSphere provides special APIs for logging and transaction controls that generates non-JMS messages. Sam wants to use these APIs and non-JMS messages in his application. Can he use non-JMS messages in his application and how?



Options:
  ? 1,Yes, Sam can use non-JMS messages, he can make use of non-JMS message driven bean for non-JMS messages.
  ? 2,Yes, Sam can use non-JMS messages, he can make use of JMS message driven bean for non-JMS messages.
  ? 3,No, Sam cannot use non-JMS messages, as Java EE architecture does not provide support for non-JMS messages.
  ? 4,No, Sam cannot use non-JMS messages, as it requires Java Native Interface to access non-JMS messages and it is not recommended to use JNI from EJBs.
Answer: 1
Marks: 3

=============================================================

SNo: 89
Ques: Sam is using JMS message driven bean for his social networking site. Message produces TextMessages that can be of type NormalText or HTMLText. He is using BlogMessageClient bean to handle these blog messages. To identify whether the object of the BlogMessageClient can handle NormalText or HTMLText, he has added a type field to the class. To initialize this field he has added a initializeType() method. He wants that this method should be called immediately after initialization of the bean. For which of the following events he will create the method as a handler?
Options:
  ? 1,For PostConstruct event he will create initializeType() as a handler.
  ? 2,For PreDestroy event he will create initializeType() as a handler.
  ? 3,For PostActivate event he will create initializeType() as a handler.
  ? 4,For PrePassivate event he will create initializeType() as a handler.
Answer: 1
Marks: 3

=============================================================

SNo: 90
Ques: You have just finished creating a JMS message driven bean, and found that though the bean is getting the allocated resources, the deallocation is not happening properly. Which of the following options will you choose to rectify the issue?
Options:
  ? 1,Overide the finalize method in the bean class and deallocate the resources in that method.
  ? 2,Create a method to handle the PreDestroy life-cycle event of the bean and in this method deallocate the resources.
  ? 3,Create a method to handle the PrePassivate life-cycle event of the bean and in this method deallocate the resources.
  ? 4,Nothing can be done for the issue so you will restart the server each time the Application Server is low on resources.
Answer: 2
Marks: 3

=============================================================

SNo: 91
Ques: Ryan has created a stateless session bean, named BankingBean, which includes the endBanking method as a handler for PrePassivate event. However, the endBanking method, which should be executed during the lifecycle of the bean, never gets called. Observe the partial code given below and identify the reason for this unexpected result.

@Stateless public class BankingBean implements Banking {
public int someMethod(){...};
//...
@PrePassivate private void endBanking() {...};
}


Options:
  ? 1,The endBanking method is called but endBanking method throws a runtime exception and so container does not execute the method.
  ? 2,The endBanking method is not called because stateless beans do not fire PrePassivate life-cycle events.
  ? 3,The endBanking method is not called because the handle is not created properly. The name of the handler is not passed as a parameter such as, @PrePassivate{"EndBankingHanlde"}
  ? 4,The endBanking method is not called because passivation of a stateless session bean is very unpredictable.
Answer: 2
Marks: 4

=============================================================

SNo: 92
Ques: You have a stateful session bean, named as ShoppingCartBean, for which you have created an activateBean method to initialize the bean and generate a unique ID for the shopping cart. You now have to create a code to ensure that the activateBean method is executed on creation and activation of the bean. Which of the following codes will help in the preceding task?
Options:
  ? 1,@PostActivate
@PostConstruct
private void activateBean() {...};
  ? 2,@PostActivate,PostConstruct
private void activateBean() {...};
  ? 3,@PostActivate
private void activateBean() {...};
@PostConstruct
private void activateBean() {...};
  ? 4,@{PostActivate,PostConstruct}
private void activateBean() {...};
Answer: 1
Marks: 4

=============================================================

SNo: 93
Ques: You have created a session bean, namely UserBean by using the following code snippet:

@Stateless
public final class UserBean implements UserInterface{
public boolean validateLogin(String userName, String password){//code to validate login and return a boolean value}
}

While compiling the bean you are getting an error. Identify what is the issue with the preceding code?
Options:
  ? 1,A final keyword cannot be used while defining a session bean.
  ? 2,A default constructor should be defined while defining a session bean.
  ? 3,A session bean class should not implement interfaces.
  ? 4,A session bean should always be an abstract class.
Answer: 1
Marks: 4

=============================================================

SNo: 94
Ques: You have created a session bean, with a stateless annotation. However, you have also added the following entry for the bean in the deployment descriptor.

<session-type>Stateful</session-type>

Which of the following issues will arise in this situation?
Options:
  ? 1,This situation will cause a runtime exception because structural information provided as annotations should not be overridden in the deployment descriptor.
  ? 2,This situation will not cause any issues because the container will ignore the deployment descriptor entry.
  ? 3,This situation will not cause any issues because the container will ignore the annotations entry.
  ? 4,This situation will not cause any issues because the deployment descriptor's entry will override the annotation's entry.
Answer: 1
Marks: 4

=============================================================

SNo: 95
Ques: You have created a session bean, using stateless annotations. However, when you try to compile this session bean it gives you a compile error. You have JDK1.4.2 installed in your machine. Which of the following options do you think is the reason for this error?
Options:
  ? 1,You get a compile error because for compiling session bean java files, you should first install Java EE 5 SDK.
  ? 2,You get a compile error because JDK1.4.2 does not support annotations and you should at least have JDK1.5.0 installed. Annotations were only introduced with JDK1.5.0.
  ? 3,You get a compile error because for compiling session bean java files, you should first install an Application Server like Sun Java? System Application Server.
  ? 4,You get a compile error because the installation of JDK1.4.2 on your machine is corrupt, causing it to behave unexpectedly.
Answer: 1
Marks: 4

=============================================================

SNo: 96
Ques: Billy is using following code for his message driven bean:
@MessageDriven(messageListenerInterface=javax.jms.MessageListener.class,
mappedName = "jms/MessageDrivenBean")
public class MessageDrivenBean{
    public void onMessage(Message message) {//some code}
    @PostConstruct void obtainResource() throws CustomApplicationException{//some code}
    @PreDestroy void releaseResource() throws CustomApplicationException {//some code}
}
Please verify the preceding code to rectify if it contains any issues?
Options:
  ? 1,The above code does not have any issues and will successfully create a message driven bean namely MessageDrivenBean.
  ? 2,MessageDrivenBean is not implementing the MessageListener interface and so when container tries to notify the bean with the message a run time exception will be thrown.
  ? 3,MessageDrivenBean is not explicitly implementing the default constructor and so when container tries to notify the bean with the message a run time exception will be thrown.
  ? 4,It is not recommended that life-cycle event handler methods should throw application exceptions. So the throws clause should be removed.
Answer: 4
Marks: 4

=============================================================

SNo: 97
Ques: Billy is using following code for his message driven bean:
@MessageDriven(messageListenerInterface=javax.jms.MessageListener.class,
               mappedName = "jms/MessageDrivenBean",
               activationConfig =  {
               @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Client-acknowledge"),
               @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
               })
public class MessageDrivenBean{
    public void onMessage(Message message) {//some code}
}
But he is facing a runtime exception with the above code. Please verify the preceding code to rectify if it contains any issues?
Options:
  ? 1,MessageDrivenBean is not implementing the MessageListener interface and so when container tries to notify the bean with the message a run time exception is thrown.
  ? 2,Improper value for property acknowledgeMode is specified in the ActivationConfigProperty annotation and so when container tries to set this value a run time exception is thrown.
  ? 3,MessageDrivenBean is not explicitly implementing the default constructor and so when container tries to notify the bean with the message a run time exception is thrown.
  ? 4,There is no issue with the code, the runtime exception is occurring because of some configuration issue with the server.
Answer: 2
Marks: 4

=============================================================

SNo: 98
Ques: Billy is using following code for his message driven bean:

@MessageDriven(messageListenerInterface=javax.jms.MessageListener.class,
mappedName = "jms/MessageDrivenBean")
public final class MessageDrivenBean{
    public void onMessage(Message message) {//some code}
}

Please verify the preceding code to rectify if it contains any issues?
Options:
  ? 1,The above code does not have any issues and will successfully create a message driven bean namely MessageDrivenBean.
  ? 2,MessageDrivenBean is not implementing the MessageListener interface and so when container tries to notify the bean with the message a run time exception will be thrown.
  ? 3,MessageDrivenBean is not explicitly implementing the default constructor and so when container tries to notify the bean with the message a run time exception will be thrown.
  ? 4,It is not recommended that the JMS message driven beans be created as final classes. So the final keyword should be removed.
Answer: 4
Marks: 4

=============================================================

SNo: 99
Ques: Charlie is implementing a human resources management site and has created an Employee stateless session bean. He wants to listen to transaction events and has therefore added the necessary methods to the bean. The following code snippet displays the beans and the methods:
@Stateless
public class EmployeeBean implements Employee, SessionSynchronization{
    @TransactionAttribute(TransactionAttributeType.MANDATORY)
    public void processPayroll(){//some code}
     public void afterCompletion(boolean committed){...}
    public void afterBegin(){...}
    public void beforeCompletion(){...}
}
However, while compiling his bean he is getting a compilation error. Identify the reason for this unexpected result?
Options:
  ? 1,Charlie is getting the compiler error, because stateless session beans cannot implement SessionSynchronization interface.
  ? 2,Charlie is getting the compiler error, because he has not defined the TransactionManagement annotation.
  ? 3,Charlie is getting the compiler error, because TransactionAttributeType.MANDATORY is not a valid transaction attribute type for a stateless session bean.
  ? 4,Charlie is getting the compiler error, because he has not defined the default constructor for the bean.
Answer: 1
Marks: 4

=============================================================

SNo: 100
Ques: Rick is implementing a human resources management site and has created an Employee stateless session bean and added method createNewEmployee to the bean. He is using BMT for transaction demarcation and wants that whenever the createNewEmployee is called it should be called in a new transaction. The following code snippet displays the beans and the methods:
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class EmployeeBean implements Employee{
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public void createNewEmployee(){
    //code to verify if the transaction is new
    //some more code
    }
}
However, when this bean is executed and createNewEmployee method is called he finds that the method is not called within a new transaction. What could be the reason for this unexpected result?
Options:
  ? 1,Rick is getting this unexpected result because he is using a wrong transaction attribute type i.e. REQUIRES_NEW, instead REQUIRED should be used.
  ? 2,Rick is getting this unexpected result because stateless beans do not support transaction demarcation. As a result, all the methods are called in the same transaction.
  ? 3,Rick is getting this unexpected result because stateless beans do not support BMT. Therefore, all the methods are called in the same transaction.
  ? 4,Rick is getting this unexpected result because he is using BMT because of which the container does not manage the transactions for the bean, it should be managed programmatically.
Answer: 4
Marks: 4

Post a Comment

Previous Post Next Post