0

EJB Quiz

Description: Java - EJB Quiz
Number of Questions: 12
Created by:
Tags: java ejb
Attempted 0/12 Correct 0 Score 0

ejbCreate() method of CMP bean returns.

  1. null

  2. Primary Key class

  3. Home Object

  4. Remote Object


Correct Option: A

AI Explanation

To answer this question, you need to understand the concept of CMP (Container-Managed Persistence) beans in Java Enterprise Edition (Java EE).

In Java EE, CMP beans are entity beans that are managed by the container. The ejbCreate() method is used to create and initialize an instance of a CMP bean.

The ejbCreate() method of a CMP bean does not return any value. It is a void method, meaning it does not have a return type. Therefore, the correct answer is A) null.

How can a EJB pass it’s reference to another EJB ? Which of the following is correct syntax for an Abstract class ?

  1. abstract double area() { }

  2. abstract double area()

  3. abstract double area();

  4. abstract double area(); { }


Correct Option: C
Explanation:

To pass the reference of one EJB to another, you can use Dependency Injection (DI) or JNDI (Java Naming and Directory Interface). In DI, the reference to the EJB is passed through the constructor or a setter method. In JNDI, the EJB is bound to a JNDI name, and the other EJB looks up the name to get a reference to the EJB.

Option C is the correct syntax for an abstract method in a Java abstract class. The abstract keyword is used to indicate that the method has no implementation and must be overridden in a subclass. The parentheses after the method name are used to define the parameter list, and the semicolon at the end indicates the end of the method signature.

Option A is incorrect because it includes a method body, which is not allowed in an abstract method.

Option B is also incorrect because it does not include parentheses to define the parameter list, which is necessary even if the method takes no parameters.

Option D is incorrect because it includes a method body after the semicolon, which is not allowed in an abstract method.

Therefore, the correct answer is:

The Answer is: C

The EJB specification architecture does NOT define

  1. transactional components.

  2. client side security and encryption.

  3. distributed object components.

  4. server-side components.


Correct Option: B
Explanation:

To solve this question, the user needs to have knowledge about the EJB (Enterprise JavaBeans) specification architecture.

The EJB specification architecture defines the structure and behavior of Enterprise JavaBeans, which are server-side components used to develop scalable and distributed enterprise applications.

Let's go through each option and explain why it is right or wrong:

A. transactional components: This option is incorrect. The EJB specification architecture does define transactional components. EJBs can participate in transactions, allowing for ACID (Atomicity, Consistency, Isolation, Durability) properties.

B. client-side security and encryption: This option is correct. The EJB specification architecture does not define client-side security and encryption. It primarily focuses on server-side components and does not specify how the client-side should handle security and encryption.

C. distributed object components: This option is incorrect. The EJB specification architecture does define distributed object components. EJBs are designed to be distributed across multiple servers and can be accessed remotely.

D. server-side components: This option is incorrect. The EJB specification architecture does define server-side components. EJBs are specifically designed to run on the server-side and provide services to client applications.

Therefore, the correct answer is:

The Answer is: B

  1. a web server

  2. an EJB container

  3. an application server

  4. a database server


Correct Option: B
Explanation:

To understand which component executes EJB components, we need to have knowledge about the architecture of Enterprise JavaBeans (EJB) and the roles of different servers in the execution process.

EJB components are server-side components that are used to implement business logic in Java EE applications. They are executed by an EJB container, which is responsible for managing the lifecycle, deployment, and execution of EJB components.

Now let's go through each option and explain why it is right or wrong:

A. a web server: This option is incorrect. A web server is responsible for handling HTTP requests and serving web pages. It does not execute EJB components.

B. an EJB container: This option is correct. An EJB container is specifically designed to execute EJB components. It provides services such as object pooling, concurrency management, security, and transaction management. The EJB container ensures that EJB components are executed in a managed environment.

C. an application server: This option is also correct. An application server is a runtime environment that provides various services to execute enterprise applications. It includes an EJB container as one of its components. The application server manages the execution of EJB components along with other components of the application.

D. a database server: This option is incorrect. A database server is responsible for storing and retrieving data. It does not execute EJB components.

Therefore, the correct answer is:

The Answer is: B. an EJB container

Which describes best an EJB handle?

  1. An EJB handle is used to handle exceptions when accessing EJB objects.

  2. An EJB handle is used to store a reference to a specific EJB object.

  3. An EJB handle is part of the Home interface.

  4. An EJB handle is used for local references inside the EJB container.


Correct Option: B
Explanation:

To answer this question, the user needs to have knowledge of Enterprise JavaBeans (EJB) and how they are used in Java applications.

Now, let's go through each option and explain why it is right or wrong:

A. An EJB handle is used to handle exceptions when accessing EJB objects. This option is incorrect. An EJB handle is not used to handle exceptions. Exceptions in EJBs are typically handled using try-catch blocks or by declaring them in the method signature.

B. An EJB handle is used to store a reference to a specific EJB object. This option is correct. An EJB handle is used to store a reference to a specific EJB object. It allows the client to maintain a reference to an EJB object and use it to invoke methods on that object.

C. An EJB handle is part of the Home interface. This option is incorrect. An EJB handle is not part of the Home interface. The Home interface is used for creating and finding EJB objects, while the handle is used to store a reference to an existing EJB object.

D. An EJB handle is used for local references inside the EJB container. This option is incorrect. An EJB handle is not specific to local references inside the EJB container. It can be used for both local and remote references to EJB objects.

Therefore, the correct answer is:

The Answer is: B

When a developer declares an EJB local reference, what element does NOT need to be specified?

  1. JNDI binding for local home interface

  2. Local home interface

  3. Home interface

  4. ejb-ref-type


Correct Option: C

For a stateful session bean, which method is activated by the container to save the state of the bean?

  1. ejbCreate()

  2. ejbPassivate()

  3. ejbStore()

  4. ejbSave()


Correct Option: C

The EJB SessionContext can be used to get information about users calling session enterprise beans. Which information can NOT be retrieved?

  1. transactional information

  2. security information

  3. data source information

  4. timer service information


Correct Option: C

Client programs that access EJBs make use of the Java Naming and Directory Interface (JNDI). To get access to a Person entity bean, which methods can be used? (2 correct answers). Assume the following code is used to establish the initial context: Propert

  1. PersonHome ph = ctx.lookup("java:comp/env/ejb/Person");

  2. PersonLocalHome ph=(PersonLocalHome)ctx.lookup("java:comp/env/ejb/PersonLocalHome");

  3. PersonHome ph = ctx.lookup("java:comp/env/ejb/PersonHome");

  4. PersonHome ph = javax.rmi.PortableRemoteObject.narrow(ctx, PersonHome.class)

  5. PersonHome ph = (PersonHome)javax.rmi.PortableRemoteObject.narrow(ctx,PersonHome.class)


Correct Option: B,E

What would be a typical use of ejbSelect() methods?

  1. Using ejbSelect() methods in session beans for specifying the selection criteria for a list

  2. Using ejbSelect() methods within ejbHome methods to return entities

  3. Using ejbSelect() methods to access fields of a bean instance

  4. Using ejbSelect() methods to perform operations not specific to a entity instance


Correct Option: D

CMP fields in EJB 2.x are defined via

  1. static fields in the entity bean

  2. an abstract persistence schema

  3. EJB Query Language definitions in the deployment descriptor

  4. the persistence-type attribute in the deployment descriptor


Correct Option: B

In order to use Container Managed Relations (CMR) fields in CMP entity beans, the developer Must

  1. declare the CMR member fields and add ejb-relationship definitions in the deployment descriptor

  2. implement the get/set methods for the CMR fields and add ejb-relationship definitions in the deployment descriptor

  3. implement the ejbLoad() and ejbStore() methods and add ejb-relationship definitions in the deployment descriptor

  4. declare abstract get/set methods for the CMR field and add ejb-relationship definitions in the deployment descriptor


Correct Option: D

AI Explanation

To use Container Managed Relations (CMR) fields in CMP entity beans, the developer must:

D. Declare abstract get/set methods for the CMR field and add ejb-relationship definitions in the deployment descriptor.

Explanation: CMR fields in CMP entity beans are used to define relationships between entity beans. To use CMR fields, the developer needs to declare abstract get/set methods for the CMR field. These abstract methods will be implemented by the container to manage the relationship between the entities.

Additionally, the developer also needs to add ejb-relationship definitions in the deployment descriptor. The deployment descriptor is an XML file that contains configuration information for the EJB module, including the definition of relationships between entity beans.

Therefore, option D is the correct answer.

- Hide questions