Monday, January 31, 2011

EJB Interview Questions - Part1


Q.Briefly describe EJB architecture.
A.The EJB architecture is an extension of Web architecture. It has an additional tier. The clients of an enterprise bean can be a traditional java application – an applet, a JSP or servlet.Like in a web application, client browser has to go all the way to web container to use a servlet or JSP, the communication between beans and clients is performed by the EJB container.The following is flow of the EJB architecture.
1.The client is working on a web browser.
2.There is a database server that hosts a database, like MySQL / Oracle.
3.The J2EE server machine is running on an application server
4.The client interface is provided with JSP / Servlet. The enterprise beans reside in the business tier providing to the client tier.
5.The Application Server manages the relationships between the client and database machines.
Q.Explain the various services that the EJB container offers to the application developer.
A.
1.Component Pooling :
An EJB component is a server component that provides methods with business logic in distributed applications. These methods are to be handled using Enterprise Java Beans. These beans are maintained by the EJB container. The container maintains a pool of enterprise beans in order to respond to client requests.
2.Lifecycle management :
The EJB container , based on the server load, automatically increases and reduces the number of available bean instances.
3.Database Connection pooling:
By using a single user login and password to access the entire database system is known as connection pooling. This one single login and password will have full access to the database.Using the connection pooling, the performance of executing database commands can be enhanced. Tearing down the connections is more costly than executing the commands and needs hard coding.These flaws are handled properly by having a connection pool. Connections are available for one database, so that new connections does not need to be established. If the no. of connections exceed the limit, a queue of instances can be made.
4.Transaction Management
A transaction is a subtask that can execute at once at a time. To make a successful transaction management, every transaction must be executed successfully. EJB provides two types of transaction management:
1.Container-managed transactions (CMT) : CMT is all about the commitment or rolling back the transaction on behalf of the bean.
2.Bean-managed transactions (BMT) : BMT is all about to have overall control on transactions that can be managed by the client or in the bean itself, if the transaction is to be managed by the session.
5.Authentication:
Container encapsulates EJBs and acts as its security manager.
EJB supports authentication and role-driven access control. An EJB container implements authentication mechanism which are often rely on the web container. Bean developer should never code for authentication.
6.Persistence:
The container provides persistent services such as, transactions, security, concurrency, and naming at runtime.The persistence feature of the container is associated with the entity bean to generate various methods to perform the data persistence for the entity bean instances. The generated methods involve in transferring the data between entity bean instances and the specific resource manger. This persistence is done at runtime. The container is capable of managing the mapping between the relationships at runtime and manages the referential integrity.
7.Client Session Management:
Client session management is implementing the business logic for a client. This is performed by the Session Bean. For example, a session bean can perform various calculations for employee payroll application, processing orders, encrypting and decrypting data, data validation etc. for a client. The container manages to make the session beans reside, as long as the client’s session using them.
Q.What is the difference between EJB and Java beans?A.Java Beans:
Java beans are reusable components that can be used for customized user objects. Java beans adhere to two methods known as setter and getter methods and one public constructor. For example an Employee object can be used to set (setter method) and get (getter method) employee details which are a customized object. AWT and Swing components are based on java beans.
Enterprise Java Beans:
EJB are reusable components that are developed to comply with enterprise specification adhering to setter and getter methods and one public constructor. These beans run in an EJB container of J2EE architecture.
Q.What’s new in the EJB 2.0 specification?A.The following are the differences specified by Sun in EJB 2.0
Local interfaces, which improve the efficiency of intra-container entity relationships - to access lightweight entities only within the EJB container. The remote access overhead associated with remote interface can be avoided with local interfaces, so that the tightly coupled beans can communicate more efficiently.
Container-managed relationships, in which the container manages object relationships between entity beans –In the earlier versions Entity beans relationships are being managed manually, which is a burden for the EJB developers. In EJB 2.0 the entity bean itself can manage the relationships which are based on integrity model.
Changes to EJB QL, a query language for portable EJB finder methods – It is a container-persistence model. It provides the navigation facility through networks of entity beans connected by container-managed relationships.
It is made mandatory to use the SELECT clause in EJB QL queries.Duplicate result set can now be eliminated using DISTINCT in SELECT clause.Objects can also be selected using an OBJECT operator in the SELECT clause.The presence or absence of a value in a collection is a choice that is provided by MEMBER OF operator to search.
Q.What is the difference between EAR, JAR and WAR file?A.
1.jar files: These files have .jar extension. A .jar file contains .class files, resources like .java and property files. The .jar file can be appended to environment variable CLASSPATH in order any java application to access from remote package.
2.War files: These files have the .war extension. The web application that is to be deployed on servlet or JSP container is too converted into .war file and can be deployed using Tomcat browser. The .war file can have .jsp, html, .js and any other files which would necessary for a web application.
3.ear files: The enterprise applications that are to be deployed in EJB container are to be placed in an .ear file.
Q.What is EJB client JAR file?A.EJB client JAR file: This file is used for client projects. This file includes the .class files of the client. When exported this project to client, the EJB client JAR files are used and this file is described in the deployment descriptor of the EJB JAR file using element. It is the path name which specifies the location of EJB client JAR file in the containing J2EE Enterprise Application Archive (.ear) file.
Q.What is Deployment descriptor?A.A deployment descriptor is a configuration file for a web application or EJB application which is to be deployed to web or EJB container. The deployment descriptor should contain standard structural information for all enterprise beans in an EJB application. The file name is ejb-jar.xml The descriptor of EJB informs the EJB server about the classes that make up the implementation of bean, the both home and remote interfaces. A standard deployment descriptor should contain structural information for each enterprise bean.
Q.How EJB Invocation happens?A.The following are the invocation steps for EJB:
Step 1: Using JNDI, retrieve Home Object reference from Naming Service
Step 2: Send or return Home Object reference to the client.
Step 3: Create a new EJB Object through Home Object interface.
Step 4: Create EJB Object from the Ebb Object
Step 5: Send or return EJB Object reference to the client.
Step 6: Invoke business method using EJB Object reference.
Step 7: Delegate request to Enterprise Bean.
Q.What is Remote Procedure Calls, RPC? A.A request from one program that is located in one computer can be used by another computer in a network environment without understanding the underlying network details. This is done by a protocol called Remote Procedure Calls. In this client / server environment (network environment), the request is from a client to the server that provides the service from a server.RPC is also called as inter-process communication. RPC extends the normal procedure calls across the network which is necessary in distributed computing models and for harnessing the power of the multiple processors.In distributed systems, a client calls a procedure stored on a server. This is called calling a remote procedure stored on a server. Though, the call is made as if the procedure was stored on the local machine.
The steps in which a RPC is made are:
1.The client calls the procedure
2.The client stub builds the message.
3.The message is sent over the network.
4.The Server OS gives the message to the server stub.
5.The server stub unpacks the message.
6.The stub makes a local call to the procedure.
7.The server does the work and returns the result to the server stub.
8.The stub packs the message and traps to the kernel.
9.The remote kernel sends the message the client kernel.
10.The client kernel gives the message to the client stub.
11.The client stub unpacks the result and gives to the client.

No comments:

Post a Comment