Unit 4
Unit 4
TECH
COMPUTER SCIENCE ENGINEERING
(AKTU)
By Vishal Dhiman
Q. 1. What is EJB? Write the advantages and disadvantages of EJB. Explain EJB architecture. What are its
various types?
Ans.
1. An Enterprise Java Bean is a server-side component which encapsulates business logic.
2. EJB (Enterprise Java Bean) is used to develop scalable, robust and secured enterprise applications in Java.
3. Middleware services such as security, transaction management etc. are provided by EJB container to all EJB
applications.
4. To run EJB application, we need an application server (EJB Container) such as Jboss, Glassfish, Weblogic,
Websphere etc.
5. EJB application is deployed on the server, so it is also called server-side component.
Advantages of EJB :
1. It can run in multithreaded environment.
2. It contains only business logic.
3. EJB provides distributed transaction support.
4. It provides portable and scalable solutions of the problem.
5. It provides a mechanism to store and retrieve data in a persistent way.
Disadvantages of EJB :
1. It requires application server.
2. It requires only Java client. For other language client, we need to go for web service.
3. It is complex to understand and develop EJB applications.
EJB architecture :
Q. 2. What is Java Bean exactly ? Why they are used ? Discuss setter and getter method with Java code.
Ans. Java Beans :
1. Java Beans are classes which encapsulate several objects into a single object.
2. It helps in accessing the objects from multiple places.
3. It is a portable, platform independent model written in Java.
Getter and setter method : In Java, getter and setter are two conventional methods that are used for
retrieving and updating value of a variable.
Q. 4. Explain session beans with its types.
Ans. Session bean :
1. Session bean encapsulates business logic only, it can be invoked by local, remote and web service client.
2. It can be used for managing activities like database access, calculation etc.
3. The life cycle of session bean is maintained by the application server (EJB container).
4. Session bean is created by a customer and its duration is only for the signal client server session.
Q. 7. Write steps to connect database with the web application using JDBC.
Ans. Steps to connect database with web application using JDBC :
Step 1 : Create a database using some suitable database management package.
Step 2 : Initiate object for JDBC driver using following statement : Class.forName (“com.mysql.jdbc.Driver”).
newInstance ( );
Step 3 : Using DriverManager class and getConnection method we get connected to the database. To get
connected with MySQL database we use following statement :
DriverManager.getConnection (“jdbc:mysql://localhost
(“jdbc:mysql://localhost; 3306/students”, “root”, “system”);