You are on page 1of 37

www.moreacademy.

online

More Academy

ENTERPRISE JAVA
SEM: V
SEM V: UNIT 1

607A, 6th floor, Ecstasy business park, city of joy, JSD


road, mulund (W) | 8591065589/022-25600622

Abhay More abhay_more


MORE ACADEMY BSC IT: SEM – V JAVA: U1

Page 1 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

1. What are the various factors important before deciding on the number of tiers in
application architecture?

Deciding on the number of tiers in an application architecture is a critical design decision that can
impact the scalability, maintainability, and performance of your application. Several important factors
should be considered before determining the appropriate number of tiers:

1. Application Complexity: The complexity of your application plays a significant role. Simple
applications may only require a two-tier architecture (e.g., client-server), while complex enterprise-level
applications might benefit from a multi-tier architecture (e.g., three-tier or n-tier) to manage complexity.

2. Scalability Requirements: Consider whether your application needs to scale horizontally or


vertically. A multi-tier architecture can provide better scalability options, particularly if you expect
variable workloads.

3. Performance: Performance goals and requirements are essential. Multi-tier architectures can
distribute the load and enhance performance by separating concerns, but they may also introduce
latency due to communication between tiers.

4. Security: Security is a paramount concern. Multi-tier architectures allow for better security by
isolating sensitive components or data in separate tiers, which can be independently secured.

5. Maintainability: Think about long-term maintainability. A well-structured multi-tier architecture can


make it easier to update or replace individual tiers without affecting the entire application.

6. Cost: Consider the budget constraints. Implementing and maintaining a multi-tier architecture can
be more expensive than a simpler architecture due to the need for additional infrastructure and
expertise.

7. Development Team Skills: Assess the skills and expertise of your development team. Building and
maintaining a multi-tier architecture may require a team with experience in distributed systems,
whereas a two-tier architecture might be more accessible for a smaller or less experienced team.

8. Integration Requirements: If your application needs to integrate with external systems or services,
a multi-tier architecture can provide better isolation and modularity, making integration easier.

9. Load Distribution: Think about how you want to distribute the load across different tiers. If you
anticipate heavy database usage, a three-tier architecture with a dedicated data tier might be
beneficial.

10. Latency Tolerance: Consider whether your application can tolerate some latency between tiers.
For real-time applications, minimizing latency might be critical, while batch processing systems might
tolerate higher latency.

11. Flexibility and Extensibility: Evaluate how easy it is to extend or modify your architecture. Multi-
tier architectures often offer more flexibility for future enhancements and changes.
.

Ultimately, the choice of the number of tiers in your application architecture should align with your
specific project requirements and constraints. It's often beneficial to perform a thorough analysis and
consider the trade-offs to determine the most suitable architecture for your application.

Page 2 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

2. Write a short note on Single tier architecture.


All the services provided by the application i.e. the user interface, persistent data access and the
logic that processes the data input by the user and read and displayed to the user from a data store, all
exist on the same physical machine
Hence in a Single-tier architecture:
The user interface of a Web application i.e. the presentation layer
The middle ware i.e. the business rules
The data access layer are all contained in one single computer.
Advantages:
 The simplest and least expensive alternative

 Less equipment to purchase and maintain

Disadvantages:
• This type of implementation is lower security and the lack of scalability. An architecture is
scalable when it can be easily expanded or augmented to meet increasing performance needs.

• Having all of the site's major components and data on a single computer behind the domain
firewall leaves the site more vulnerable to malicious attacks.

• Running all of the site's components on a single computer also limits expansion and optimization
possibilities

Page 3 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

3. Explain two tier architecture with its advantages and disadvantages.


In Two Tier architecture, an application is divided into two components:
• Client
• Implements the user interface
• Contains business logic
• Server
• Used to store and access business data, captured by the user interface run on the Client in a
data store at the Server

Hence in a two-tier architecture:


• The User Interface is always physically located in the user's desktop [i.e. the Client].
• The database management services are always physically located on a Server

Advantages:
• Adds additional security by removing sensitive customer data from the single computer
• Having the database on a separate computer improves the overall performance of the site
• Allows optimizing each machine for more specific performance requirements

Disadvantages:
• The increased cost and complexity of the architecture
• While this is the recommended architecture for an initial electronic commerce site, provide a cost
benefit analysis to the customer to help them make the decision.

Page 4 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

4. Write a short note on three tier architecture.


Three Tier architecture is the evolution of two tier applications. Logically the application is
divide into three constituent layers:
User Services - Presentation Layer: Provides service such as the Graphical User Interface and
other automation tasks that the application has to perform.
Business Services - Business Layer: Implements business rules. This layer encapsulates the
business logic from users such that they need not know how business logic is applied. When
business is upgraded, only the business layer is affected and must be upgraded, the rest of the
application services can remain untouched
Data Services - Data Layer: Provides data availability and integrity. It is responsible for adding,
modifying and deleting data from the data store.
This architecture, while it is the most expensive, is the most secure and scalable of the three
options.
Since, the Business Layer has been moved from the Presentation Layer, it reduces the security risk.
As usage on the site grows, additional Business Layer can be added and the application can be
cloned across multiple computers.
Each of the three layers can now be optimized for peak operating efficiencies. The main functions
of:
• The Presentation Layer is network I/O
• The Business Layer is CPU-intensive
• The Data Layer is disk I/O intensive

Page 5 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

5. What is need of multi‐tier architecture and explain its functionality. (NOV 19)
1. Client Tier: This tier represents all device or system clients accessing the system or the
application. A client can be a Web browser, a Java or other application, a Java applet, a WAP
phone, a network application, or some device introduced in the future. It could even be a batch
process.

2. Presentation Tier: This tier encapsulates all presentation logic required to service the clients that
access the system. The presentation tier intercepts the client requests, provides single sign-on,
conducts session management, controls access to business services, constructs the responses,
and delivers the responses to the client. Servlets and JSP reside in this tier. Note that servlets and
JSP are not themselves UI elements, but they produce UI elements

3. Business Tier: This tier provides the business services required by the application clients. The tier
contains the business data and business logic. Typically, most business processing for the
application is centralized into this tier It is possible that, due to legacy systems, some business
processing may occur in the resource tier. Enterprise bean components are the usual and preferred
solution for implementing the business objects in the business tier.

4. Integration Tier: This tier is responsible for communicating with external resources and systems
such as data stores and legacy applications. The business tier is coupled with the integration tier
whenever the business objects require data or services that reside in the resource tier. The
components in this tier can use JDBC, J2EE connector technology, or some proprietary middleware
to work with the resource tier.

5. Resource Tier: This is the tier that contains the business data and external resources such as
mainframes and legacy systems, business-to-business (B2B) Integration systems, and services
such as credit card authorization.

The layered architecture provides following benefits:


• Easier to understand and Traceable Code for developers.
• Easier to write the applications.
• Easier to test the applications.
• Easier to extend the business rules on a particular domain object.

Page 6 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

6. What are Java EE containers? (NOV 18, APR 19, NOV 22, APR 23)

Java EE containers are the interface between the component and the lower-level
functionality of the application server provided by the platform to support that component and API .
The functionality of the container is defined by the platform to provide more productivity, and is
different for each component type. The server allows the different component types to work together
to provide the enhancement of functionality in an enterprise application.

The Web Container: The web container is the interface between web components or API and the
web server. A web component can be a JSP page, or a JavaServer Faces Facelets page, and
servlet. The web container manages the processes of Request & Response in the component’s
lifecycle, dispatches requests to application components, and provides interfaces to context data,
such as information about the current request.

The Application Client Container: The application client container is the interface between Java EE
applications and clients/browsers, which are special Java SE applications that use Java EE server
components with more API’s, and the Java EE server. The application client container runs on the
client machine, and is the gateway between the client application and the Java EE server
components that the client/browsers uses

Key points of Container:


In Java EE security models configure a web component or EJB so that system resources are
accessed at client side/browsers only by authorized users.
The Java EE transaction model provides relationships among methods/functions that communicate
a single transaction so that all methods/functions in single transaction are treated as a single unit.
The Java EE can be remotely connectivity model manages low-level communications between
clients and EJB.

Page 7 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

7. Explain CGI technology and what are its disadvantages?


• CGI technology enables the web server to call an external program and pass HTTP request
information to the external program to process the request. For each & every request, it starts a new
process or creates a new Thread for every request. i.e. Number request coming to CGI, a number of
newly processes or threads to create. CGI will get more load & responses are slow or its processing
task may be heavy.
• The Common Gateway Interface (CGI) provides the middleware between WWW servers and
external databases and information sources. The World Wide Web Consortium (W3C) defined the
Common Gateway Interface (CGI) and also defined how a program interacts with a Hyper Text
Transfer Protocol (HTTP) server.
• The Web server typically passes the form information to a small application program that processes
the data and may send back a confirmation message. This process or convention for passing data
back and forth between the server and the application is called the common gateway interface
(CGI).
CGI (Common Gateway Interface) is a technology and protocol that enables web servers to interact with
external programs or scripts to generate dynamic web content. It played a significant role in the early days
of the World Wide Web and is still in use today, although its usage has declined in favor of more modern
server-side technologies like PHP, Python, Ruby, and Java servlets. Here's an explanation of CGI
technology and its disadvantages:

Disadvantages of CGI:

1. Performance Overhead: One of the primary disadvantages of CGI is its performance overhead. Each
CGI request spawns a new process, which consumes system resources (memory and CPU). This process
creation and termination for each request can be slow and inefficient, especially for high-traffic websites.

2. Resource Intensive: CGI can be resource-intensive, leading to slow response times and decreased
server scalability under heavy loads. This makes it less suitable for serving large-scale websites.

3. Security Concerns: CGI scripts need to be carefully written to avoid security vulnerabilities, such as
code injection and unauthorized access. Proper input validation and security practices are essential, which
can be error-prone.

4. Lack of State Management: CGI scripts are generally stateless, meaning they don't inherently maintain
session or application state. Developers need to implement their own mechanisms for session
management, which can be complex and error-prone.

5. Maintenance Challenges: Managing and maintaining a large number of CGI scripts can be challenging,
as each script is separate and may have its own dependencies. Updating or maintaining these scripts can
be time-consuming.

Page 8 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

6. Limited Language Options: CGI scripts can be written in various programming languages, but not all
languages are well-suited for web development. Developers may need to work with languages that are not
optimized for web applications.

7. Scalability Issues: Due to its resource-intensive nature and lack of built-in scalability features, CGI is
not ideal for building highly scalable web applications. Modern web technologies offer better scalability
options.

8. Complex URL Mapping: CGI URLs often include the path to the script, making them less user-friendly
and harder to manage than more modern web frameworks that offer cleaner URL routing.

Due to these disadvantages and the availability of more efficient and developer-friendly web technologies,
CGI has become less common for web development. Developers now prefer using frameworks and
platforms that offer better performance, security, and scalability.

Page 9 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

8. Write a short note on Servlet interface and explain its methods.


Servlet interface is a collection of empty method signatures.
A servlet must directly or indirectly [by subclassing the GenericServlet or HttpServlet class]
implement the servlet interface.
This interface holds method signatures that bring the following basic Servlet functionalities:
• Initializing a Servlet
• Handling a client request
• Destroying a Servlet

Following are the methods in this interface:


init() Is used for initializing the servlet parameters provided by the ServletConfig object.
Is called only once when the Servlet is first loaded. It is commonly used to initialize resources to be used by
a Servlet when requests are received.

The `init()` method is a commonly used method in programming, and its specific functionality and usage
can vary depending on the context and programming language. Here are a few common uses of the `init()`
method in different contexts:

In Java Servlets, the `init()` method is part of the Servlet lifecycle and is called by the Servlet container
(e.g., Tomcat) when the Servlet is first initialized. It's typically used for one-time initialization tasks, such as
setting up resources, establishing database connections, or loading configuration data. The `init()` method
is invoked before any client requests are handled by the Servlet. Here's an example of a Servlet `init()`
method:
```

destroy(): destroy() is also called only once immediately before the Servlet is unloaded.
Is used to clear all retained resources such as database connection, threads, file handles and so on.
This method is overridden in order to free up any resources being used by the Servlet.

The `destroy()` method is a part of the lifecycle methods in various programming contexts, including Java
Servlets and Java Applets. Its purpose and usage can vary depending on the context, but generally, it is
used to perform cleanup or resource release tasks when an object or component is being removed or
destroyed. Here's how the `destroy()` method is used in different contexts:

In Java Servlets, the `destroy()` method is called by the Servlet container (e.g., Tomcat) when the Servlet
is being removed from service or is being shut down

service(): Is the actual heart of the HTTP Request-Response model.


Is called to handle a single client request.
A Servlet receives request information through the ServletRequest object and sends data back to the
client through the ServletResponse object.

getServletConfig() : Provides the ServletConfig object for initializing the Servlet’s parameters.

getServletInfo() : Provides the Servlet metadata such as author, servlet version and other copyright
information.

This method needs to be overridden inside the Servlet for it to return the required information.

Page 10 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

9. Explain the life cycle of a servlet. (NOV 18 , NOV 19, NOV 22, APR 23)
In Java Servlet, The web container maintains the life cycle of a servlet instance/Object. Following
are the Stages of life cycle of the servlet:
1. Servlet class is loaded.
2. Servlet instance is created.
3. init method is invoked.
4. service method is invoked.
5. destroy method is invoked.

Stages of servlet life cycle

The servlet is in a new state if the servlet instance is created.


After invoking the init() method, Servlet comes in the ready state. In the ready state, servlet performs
all the tasks.

When the web container invokes the destroy() method, it shifts to the end state.
1) Servlet class is loaded: In servlet while executing the servlet class first stage is i.e classloader is
responsible for loading the servlet class into RAM. servlet class is loaded when the first request
comes from the web container.

2) Servlet instance is created: After loading the servlet class web container creates the instance of a
servlet t class. The servlet instance/object is created only once in the servlet life cycle; the second
time request is not created.

3) init method is invoked: The web container/web server calls the init() method only once after
creating the servlet instance. Basically the init() method is used to initialize the servlet. init() method
is the content of the life cycle of the javax.servlet.Servlet interface. Syntax: public void
init(ServletConfig config)

4) service method is invoked: The web container/web server calls the service method each time
when a request for the servlet is received. If the servlet class or object is not initialized, again it
follows the first three steps as described above then calls the service method. If the servlet is
initialized, it calls the service method. Syntax: public void service(ServletRequest request,
ServletResponse response)

5) destroy method is invoked: The web container/web server calls the destroy method before
removing the servlet instance from the RAM. destroy() method gives the servlet an opportunity to
clean up any resource for example memory, thread etc.

Page 11 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

10. Explain various types of JDBC Drivers. (NOV 18 , NOV 19, APR 23)
JDBC (Java Database Connectivity) drivers are platform-specific implementations that allow
Java applications to connect to and interact with relational databases. These drivers act as a bridge
between the Java application's code and the database management system (DBMS) to facilitate
communication and data exchange.

1. Type 1-JDBC-ODBC Bridge plus ODBC driver


This driver converts JDBC API calls into Microsoft Open Database Connectivity (ODBC) calls that
are then passed to the ODBC driver. The ODBC binary code must be loaded on every client
computer that uses this type of driver.
Advantage:
The JDBC-ODBC Bridge allows access to almost any database, since the
database's ODBC drivers are already available.
Disadvantages:
The Bridge driver is not coded completely in Java: So Type 1 portable. It is not good for the Web
Application because it is not portable.

It is comparatively slowest than the other driver types. The client system requires the ODBC
Installation to use the driver.

2. Type 2-Native-APV Partly Java driver: The driver converts JDBC API calls into DBMS precise
client API calls Similar to the bridge driver, this type of driver requires that some binary code be
loaded on each client computer.

Advantage:
This type of divers are normally offer better performance than the JDBC-ODBC Bridge as the layers
of communication are less than that it and also it uses Resident/Native API which is Database
specific.
Disadvantage:
Mostly out of date now.
It is usually not thread safe.
This API must be installed in the Client System therefore this type of drivers cannot be used for the
Internet Applications Like JDBC-ODBC Bridge drivers, it is not coded in Java which cause to
portability issue.
If we modify the Database then we also have to change the Native API as it specific to a database.

Page 12 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

3. Type 3-JDBC-NA/Pure Java Driver


This driver sends JDBC API calls to a middle tier Net Server that translates the calls into DBMS
precise Network protocol. The translated calls are then sent to a particular DBMS.

Advantages:
• This type of drivers is the most efficient amongst all driver types.
• This driver is totally coded in Java and hence Portable. It is suitable for the web Applications.
• This driver is server based, so there is no need for any vendor, database library to be
present on client machines.

• With this type of driver there are many opportunities to optimize portability, performance, and
scalability.
• The Net protocol can be designed to make the client JDBC driver very small and fast to
load.
• This normally provides support for features such as caching, load balancing etc.
• Provides facilities for System administration such as logging and auditing.
• This driver is very flexible allows access to multiple databases using one driver.

Disadvantages:
• This driver requires another server application to install and maintain. Traversing the
recordset may take longer, since the data comes through the back-end server.

Page 13 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

4. Type 4 - Native-protocol/Pure Java driver

This driver converts JDBC API calls directly into the DBMS precise network protocol without a
middle tier. This allows the client applications to connect directly to the database server.

Advantages:
• The Performance of this type of driver is normally quite good.

• This driver is completely written in Java to achieve platform independence and eliminate
deployment administration issues. It is most suitable for the web.

• In this driver number of translation layers are very less i.e. type 4 JDBC drivers don't need to
translate database requests to ODBC or a native connectivity interface or to pass the
request on to another server.

• We don't need to install special software on the client or server.

• These drivers can be downloaded dynamically.

Disadvantages:
With this type of drivers, the user needs a different driver for each database.

Page 14 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

11. Explain following interfaces:


• Connection

In JDBC API a Connection interface is the session between a Java application and database. The
Connection interface is a factory of PreparedStatement, Statement, and DatabaseMetaData, that
means objects of Connection can be used to get the object of Statement and DatabaseMetaData.
Commonly used methods of Connection interface:
• public Statement createStatement(): In Java creates a statement object that can be used to
execute SQL queries.
B) public Statement createStatement(int resultSetType,int resultSetConcurrency): Creates a
Statement object that will generate ResultSet objects with the given type.
C) public void close(): closes the connection and Releases a JDBC resources immediately.

. Statement

The Statement interface provides methods to execute queries with the database.
The statement interface is a factory of ResultSet i.e. it provides a factory method to get the object
of ResultSet.
Following are the important methods of Statement interface:
• public ResultSet executeQuery(String sql): In Java is used to execute SELECT query.
It returns the object of ResultSet when executing the query.
B) public int executeUpdate(String sql): In Java is used to execute specified query, it may
be create, drop, insert, update, delete.
C) public boolean execute(String sql): is used to execute queries that may return multiple
results from a database.

. PreparedStatement

The PreparedStatement interface is a subinterface of Statement.


It is used to execute parameterized queries. example of parameterized query:
String sql="insert into emp values(?,?,?)";
In the above example parameters (?) are passed for the values. Its value will be set by calling
the setter methods of PreparedStatement.
The performance of the application will be faster if you use PreparedStatement interface
because the query is compiled only once.
Methods of PreparedStatement interface are:

Page 15 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

. ResultSet

The object of ResultSet maintains a cursor pointing to a row of a table. Initially, the cursor
points to the first row.
Following are the Commonly used methods of ResultSet interface:

Srno Methods Description


1) public boolean next(): This method is used to move the cursor to the one row next from
the current position.
2) public boolean previous(): This method is used to move the cursor to the one row previous
from the current position.
3) public boolean first(): This method is used to move the cursor to the first row in the
result set object.
4) public boolean last(): This method is used to move the cursor to the last row in the result
set object.
5) public boolean absolute(int row): This method is used to move the cursor to the specified row
number in the ResultSet object.
6) public boolean relative(int row): This method is used to move the cursor to the relative row number
in the ResultSet object, it may be positive or negative.
7) public int getInt(int columnIndex): This method is used to return the data of specified column index of
the current row as int.
8) public int getInt(String columnName): This method is used to return the data of the specified column
name of the current row as int.
9) public String getString(int columnIndex): This method is used to return the data of the specified
column index of the current row as String.
10) public String getString(String columnName): This method is used to return the data of the specified
column name of the current row as String

e. ResultSetMetaData

The metadata refers to the data about data. The ResultSetMetaData interface provides the
facility to get the information like table name, total number of column, column name and column
type etc. We can get the object of ResultSetMetaData by calling getMetaData() method of
ResultSet interface.
1. getTableName(int index): It returns the name of the table of the specified column index.
Syntax:
public String getTableName(int index) throws SQLException

2. getColumnCount(): It returns the no. of columns in the result set.


Syntax:

public int getColumnCount() throws SQLException

3. getColumnName(int index): It returns the name of the column at the specified column
index.
Syntax:
public String getColumnName(int index) throws SQLException

4. getColumnTypeName(int index): It returns the type of the column at the specified column
index.
Syntax:
public String getColumnTypeName(int index) throws SQLException

Page 16 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

12. Write a servlet code to display Square and Square root of numbers between 25 and
365 intabular form. (NOV 19)

import java.io.*;

import javax.servlet.*;

import javax.servelt.http.*;

public class Test extends HttpServlet{

public void doGet(HttpServletRequest hreq, HttpServletResponse hres) throws

ServletException, IOException{

PrintWriter pw = hres.getWriter();

out.println("<table border=1>");

for(int i=25; i<=365; i++){

out.println("<tr><td>"+(i*i)+"</td><td>"+Math.sqrt(i)+"</td></tr>");

out.println("</table>");

Page 17 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

13. List the tasks that Servlet can do? (NOV 19)
Servlets are Java-based server-side components that extend the functionality of a web server
to generate dynamic web content and handle client requests. Servlets can perform a wide range of
tasks in web applications, including:

1. Handling HTTP Requests: Servlets can process HTTP requests (GET, POST, PUT, DELETE,
etc.) from clients (usually web browsers) and generate appropriate responses.

2. Dynamic Content Generation: Servlets are commonly used to generate dynamic web content
such as HTML, XML, JSON, or other formats based on data from databases, external services, or
other sources.

3. Form Processing: Servlets can handle and process data submitted through HTML forms. They
can extract form parameters and perform validation, data manipulation, or storage operations.

4. Session Management: Servlets can manage user sessions by creating, tracking, and destroying
session objects, allowing web applications to maintain stateful interactions with clients.

5. Authentication and Authorization: Servlets can implement user authentication and authorization
mechanisms, ensuring that only authorized users can access certain parts of a web application.

6. URL Mapping and Routing: Servlets can be configured to map specific URLs to their
corresponding servlets, enabling routing of requests to appropriate handlers.

7. Database Access: Servlets can connect to databases, execute SQL queries, and process data
retrieved from databases to dynamically generate web content.

8. File Upload and Download: Servlets can handle file uploads from clients and provide mechanisms
for clients to download files from the server.

9. Request and Session Attributes: Servlets can set, retrieve, and manipulate request and session
attributes to pass data between different parts of a web application or between requests and
responses.

10. Cookie Handling: Servlets can work with HTTP cookies to store and retrieve client-specific
information on the client side.
Servlets are a fundamental part of Java-based web applications and provide the backbone for
processing client requests and generating dynamic responses in a server-side environment.

Page 18 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

14. Write a short note on javax.servlet package. (NOV 18, NOV 22)
• In Java Servlet Containing API i.e the javax.servlet and javax.servlet.http packages
represent interfaces and classes for servlet API where to design java web applications.
• The javax.servlet package contains so many interfaces and classes that are used by the servlet or
web container programming.
• In the Javax.servlet package, the ServletRequest Interface is used to handle client requests to
access a servlet. It provides the information of a servlet like, parameter names, content type,
content length and values.
• In the Javax.servlet package, the ServletResponse interface defines an object to help a Servlet in
sending a response to the client/browser. It has various methods that help communicate a servlet to
respond to the client requests.
• In the Javax.servlet package, the RequestDispatcher interface provides the facility of dispatching
the request to another resource , be it html, servlet or jsp. This interface can also be used to include
the content of another resource.
• Following are the interfaces of javax.servlet package:
There are many interfaces in the javax.servlet package. They are as follows:
1. Servlet Interface.
2. ServletRequest.
3. ServletResponse.
4. RequestDispatcher.
5. ServletConfig
6. ServletContext
7. ServletRequestListener
8. ServletRequestAttributeListener
9. ServletContextListener
10.ServletContextAttributeListener

7) Following are the List of Classes in javax.servlet package


1. GenericServlet.
2. ServletInputStream.
3. ServletOutputStream.
4. ServletRequestWrapper.
5. ServletResponseWrapper.
6. ServletRequestEvent.
7. ServletContextEvent.
8. ServletRequestAttributeEvent.
9. ServletContextAttributeEvent.
10. ServletException.
11. UnavailableException.

Page 19 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

15. Explain the architecture of JDBC. / Explain the architecture of Java Enterprise
Application. (NOV 18)
The JDBC API supports both two-tier and three-tier architecture of sql processing models for
database access data.
• Two-tier Architecture:
• In the JDBC two-tier architecture model, a Java applet or application talks directly to the data
source.
• This requires a JDBC driver that can communicate with the particular data source/database being
accessed.
• A client sends a request to execute the database or other data source, and the results of those
statements are sent back to the user.
• The data source may be located on another machine to which the user is connected via a network.
This is referred to as a client/server configuration where they can communicate to each other .

• Three-tier Architecture:
• Three Tier architecture is the evolution of two tier applications.
• Logically the application is divide into three constituent layers:
• User Services - Presentation Layer: Provides service such as the Graphical User Interface
and other automation tasks that the application has to perform.
• Business Services - Business Layer: Implements business rules. This layer encapsulates the
business logic from users such that they need not know how business logic is applied. When
business is upgraded, only the business layer is affected and must be upgraded, the rest of
the application services can remain untouched
• Data Services - Data Layer: Provides data availability and integrity. It is responsible for
adding, modifying and deleting data from the data store.
• This architecture, while it is the most expensive, is the most secure and scalable of the three
options.
• Since, the Business Layer has been moved from the Presentation Layer, it reduces the security
risk.
Page 20 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

• As usage on the site grows, additional Business Layer can be added and the application can be
cloned across multiple computers.
• Each of the three layers can now be optimized for peak operating efficiencies. The main
functions of:
• The Presentation Layer is network I/O
• The Business Layer is CPU-intensive
• The Data Layer is disk I/O intensive

Page 21 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

16. What are the alternatives to CGI? Explain in detail.


Alternatives for CGI:
Several alternatives to CGI have appeared in recent years. They all build upon CGI's legacy and
provide their own approaches to the same underlying goal: responding to queries and presenting
dynamic content via HTTP. Most of them also attempt to avoid the main drawback to CGI scripts:
creating a separate process to execute the script every time it is requested.
1. ASP: Active Server Pages, or ASP, was created by Microsoft for its web server, but it is now
available for many servers. The ASP engine is integrated into the web server so it does not require
an additional process. It allows programmers to mix code within HTML pages instead of writing
separate programs.
2. PHP: PHP is a programming language that is similar to Perl, and its interpreter is embedded
within the web server. PHP supports embedded code within HTML pages. PHP is supported by the
Apache web server.
3. ColdFusion: Allaire's ColdFusion creates more of a distinction than PHP between code pages
and HTML pages. HTML pages can include additional tags that call ColdFusion functions. A number
of standard functions are available with ColdFusion, and developers can create their own controls
as extensions. ColdFusion was originally written for Windows, but versions for various Unix
platforms are now available as well.
4. Java servlets: Java servlets were created by Sun. Servlets are similar to CGI scripts in that they
are code that creates documents. However, servlets, because they use Java, must be compiled as
classes before they are run, and servlets are dynamically loaded as classes by the web server when
they are run. JSP is another technology that allows developers to embed Java in web pages, much
like ASP.
5. FastCGI: FastCGI maintains one or more instances of PERL that it runs continuously along with
an interface that allows dynamic requests to be passed from the web server to these instances. It
avoids the biggest drawback to CGI, which is creating a new process for each request, while still
remaining largely compatible with CGI, FastCGI is available for a variety of web servers.

6. mod_perl: mod perl is a module for the Apache web server that also avoids creating separate
instances of perl for each CGI. Instead of maintaining a separate instance of perl like FastCGI,
mod_perl embeds the perl interpreter inside the web server.

Page 22 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

17. Write short note on Part and WebConnection interfaces. (APR 19)

The `Part` and `WebConnection` interfaces are components of the Java Servlet API used for handling
multipart/form-data requests, typically used for file uploads in web applications.

1. Part Interface:

- The `Part` interface is introduced in Servlet 3.0 as part of the Java Servlet API for handling HTTP
multipart requests, commonly used for file uploads.

- It represents a part or piece of the multipart/form-data request, which may contain uploaded files
or other form data fields.

- The `Part` interface provides methods to retrieve information about the part, such as its name,
content type, size, and input stream for reading its content.

- The `Part` interface simplifies the handling of multipart requests compared to previous versions of
the Servlet API, making it easier to work with uploaded files and form data.

This interface represents a part or form item that was received within a multipart/form-data POST
request.
Methods:
1. void delete(): Deletes the underlying storage for a file item, including deleting any associated
temporary disk file.
2. java.lang.String getContentType(): Gets the content type of this part.
3. java.lang.String getHeader(java.lang.String name): Returns the value of the specified mime header
as a String.
4. java.util.Collection<java.lang.String> getHeaderNames(): Gets the header names of this Part.
5. java.util.Collection<java.lang.String> getHeaders(java.lang.String name): Gets the values of the
Part header with the given name.
6. java.io.InputStream getInputStream(): Gets the content of this part as an InputStream.
7. java.lang.String getName(): Gets the name of this part.
8. long getSize(): Returns the size of this fille.
9. void write(java.lang.String fileName): A convenience method to write this uploaded item to disk.

B. WebConnection Interface (javax.servlet.http.WebConnection):

The `WebConnection` interface is part of the Java WebSocket API, introduced in Java EE 7, and it
represents a client-side WebSocket connection to a remote WebSocket endpoint.

- It allows a Java client to establish a WebSocket connection to a remote WebSocket server and
exchange messages with it.

- The `WebConnection` interface provides methods for sending and receiving WebSocket
messages, such as text and binary messages.
Page 23 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

- The `WebConnection` interface is part of the Java WebSocket API and facilitates the creation of
WebSocket clients in Java EE applications.

Both the `Part` and `WebConnection` interfaces are essential components of the Java Servlet and
WebSocket APIs, respectively, and they simplify the handling of multipart requests and WebSocket
connections in Java web applications.

This interface encapsulates the connection for an upgrade request. It allows the protocol handler to
send service requests and status queries to the container.
Methods:
1. ServletInputStream getInputStream(): Returns an input stream for this web connection.
2. ServletOutputStream getOutputStream(): Returns an output stream for this web connection.

Page 24 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

18. Explain Deployment descriptor file with its elements. (APR 19 , APR 23)

Deployment Descriptor:
The deployment descriptor overrides configuration information specified through the annotation
mechanism.
Version 3.0 of the web deployment descriptor contains new attribute called metadata-complete on
the <web-app> element.
This attribute defines whether the descriptor is complete or whether the class files of the web
application should be examined for annotations that specify deployment information.
The element are as follows:
• <web-app> represents the whole application.

• <servlet> is sub element of <web-app> and represents the servlet.

• <servlet-name> is sub element of <servlet> represents the name of the servlet.

• <servlet-class> is sub element of <servlet> represents the class of the servlet.

• <servlet-mapping> is sub element of <web-app>.It is used to map the servlet.

• <url-pattern> is sub element of <servlet-mapping>. This pattern is used at client side to invoke the
servlet.

Example:
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0"
xmlns=http://java.sun.com/xml/ns/javaee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-
app_3_0.xsd">
<servlet>
<servlet-name>TWelcomeServlet</servlet-name> <servletclass>Servlet.TWelcomeServlet</servlet-
class>

</servlet>
<servlet-mapping>
<servlet-name>TWelcomeServlet</servlet-name>
<url-pattern>/TWelcomeServlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>

Page 25 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

19. Explain RowSet and its type in JDBC. (APR 19)

RowSet
A RowSet object is a java class element and extends the ResultSet interface. The RowSet is majorly
classified into two types:
• Connected Rowset : It is connected to the database connection object like the resultset. The
JDBCRow Set is the example of the connected RowSet.
• Disconnected RowSet: It only connects to the database whenever required and after finishing the
interaction they close the database connection.
There are three types of RowSet:
• CachedRowset class: It is a disconnected rowset that caches its data in memory; not suitable for
very large data sets, but an ideal way to provide thin Java clients.
Example:
CachedRowSet tCachRs = new Cached RowSetImpl();
tCachRs.setUsername("tushar");
tCachRs.setPassword("sambare");
tCachRs.setUrl("jdbc:oracle://localhost:3306/test"); tCachRs.setCommand("select * from
Registration");
tCachRs.setPageSize(4);
tCachRs.execute();
while (tCachRs.nextPage()) {
while (tCachRs.next()) {
System.out.println(tCachRs.getString("username"));
}
}
• JDBCRowSet class : It is a connected rowset that serves mainly as a thin wrapper around a
ResultSet object to make a JDBC driver look like a JavaBeans component.

Example:
JdbcRowSet jdbcRs = new JdbcRowSetImpl();
tJdbcRs.setUsername("tushar");
tJdbcRs.setPassword("sambare");
tJdbcRs.setUrl("jdbc:oracle://localhost:3306/test");
tJdbcRs.setCommand("select * from Registration");
tJdbcRs.execute();
while(tJdbcRs.next()) {
System.out.println(tJdbcRs.getString("username"));
}
C. WebRowSet class: It is a connected rowset that uses the HTTP protocol internally to talk to a Java
servlet that provides data access; used to make it possible for thin web clients to retrieve and possibly
update a set of rows.

Page 26 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

20. Explain the architecture of JDBC.

JDBC (Java Database Connectivity) is a Java-based API (Application Programming Interface) that allows
Java applications to interact with relational databases. JDBC provides a standardized way for Java
programs to connect to, query, and update databases, regardless of the underlying database management
system (DBMS) being used. It is part of the Java Standard Edition (Java SE) and is a crucial technology for
database connectivity in Java applications.

• The main function of the JDBC API is to provide a means for the developer to issue SQL statements
and process the results in a consistent, database independently.
• JDBC provides wealthy object-oriented access to databases by defining classes and interfaces that
represent objects such as:
• Database connections, (2) SQL statements, (3) Result Set, (4) Database metadata, (5) Prepared
statements, (6) Binary Large Objects (BLOBs), (7) Character Large Objects (CLOBS). (8) Callable
statements, (9) Database drivers, (10) Driver manager.

Layers of the JDBC Architecture

• The JDBC API uses a Driver Manager and database precise drivers to provide clear connectivity to
heterogeneous databases.
• The JDBC driver manager ensures that the correct driver is used to access each data source.
• The Driver Manager is capable of supporting multiple concurrent drivers connected to multiple
heterogeneous databases.
• The location of the driver manager with respect to the JDBC drivers and the Servlet is shown in
above figure.

Page 27 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

21. Enlist and explain the steps of database connectivity using JDBC API.
(NOV 22)
Steps of database connectivity using JDBC API:
To start with a java JDBC connection to the database, we must first import the "java.sql package" in
to our code. Like follows: import java.sql.*; the star (*) indicates that all of the classes in the
package java.sql are to be imported.
• Loading a database driver: We load the driver class by calling Class.forName() with the driver class
name as an argument. Once it is loaded, the Driver class creates an instance of itself. A client can
connect to Database Server through JDBC Driver. Most of the Database servers support ODBC
driver therefore JDBC-ODBC Bridge driver is commonly used. The return type of the Class.forName
(String ClassName) method is "Class". Class is a class in java.lang package.Ex.
try {
Class.forName("sun.jdbc.odbc.Jdbc0dbcDriver"); //Or Other Driver Type
}
catch(Exception e){
System.out.println("Unable to load the driver class!");
}
• Creating an oracle JDBC Connection: The JDBC DriverManager class defines objects which can
connect Java applications to a JDBC driver. DriverManager is considered the backbone of JDBC
architecture. DriverManager class manages the JDBC drivers that are installed on the system. Its
getConnection() method is used to establish a connection to a database. It uses a username,
password, and a jdbc url to establish a connection to the database and returns a connection object.
An application can have one or more connections with a single database, or it can have many
connections with different databases. A Connection object provides information about the database
tables, and fields. It also contains methods to deal with transactions.
JDBC URL Syntax:: jdbc: <subprotocol>: <subname>
Each driver has its own subprotocol & each subprotocol has its own syntax for the source.
Example: sun.jdbc.odbc.JdbcOdbcDriver

try{
Connection
tDbConn=DriverManager.getConnection(url,"loginName","Password")
}
catch(SQLException x ){
System.out.println( "Not able to find connection!");
}
• Creating a JDBC Statement object : Once a connection is obtained we can interact with the
database. Connection interface defines methods for interacting with the database through the
established connection. To execute SQL statements, we need to instantiate a Statement object from
our connection object by using the createStatement() method. As shown below.
Statement tStmt = tDbConn.createStatement();
A statement object is used to send and execute SQL statements to a database.
There are 3 kinds of Statements:
I. Standard Statement: It executes simple SQL queries without parameters. This statement creates
an SQL Statement object. A query that return the data can be executed using executeQuery()
Statement.
Syntax: Statement tStmt=tDbConn.createStatement();
Example: ResultSet trs=tStmt.executeQuery("Select * from Registration");
II. Prepared Statement: It execute a precompiled SQL queries with or without parameters. IT returns
a new PreparedStatement object. PreparedStatement objects are Precompiled SQL statements.
Syntax: PreparedStatement tPStmt=tDbConn.prepareStatement("Insert in to -");
Page 28 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

III. Callable Statement: It executes a call to a database stored procedure. It returns a new
CallableStatement object. CallableStatement objects are SQL stored procedure call statements.
Syntax: CallableStatement tCStmt-tDbcon.prepareCall("(call getEmployee(?,?)}")
• Executing a SQL statement with the Statement object & returning a JDBC resultSet: Statement
interface defines methods that are used to interact with database through the execution of SQL
statements. The Statement class has three methods for executing statements: executeQuery(),
executeUpdate(), and execute(). For a SELECT statement we use executeQuery method. For
creating or modifying tables we use executeUpdate method. The execute method executes an SQL
statement that is written as String object.
ResultSet provides access to a table of data generated by executing a Statement. The table rows are
retrieved in sequence. A ResultSet maintains a cursor pointing to its current row of data. The next()
method is used to successively step through the rows of the tabular results. ResultSetMetaData
Interface holds information on the types and properties of the columns in a ResultSet. It is
constructed from the Connection object.
• Closing the Database connection: Since database is valuable application resource and also
consumes lots of memory for creation and execution, it necessary to close the connection. The
Syntax for closing connection in JDBC is as follows:
trs.close();
tstmt.close()
con.close();

Page 29 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

22. What are the challenges of Enterprise Application Development? (APR 19)

Enterprise application development, which involves creating software systems to support the operations of
large organizations, comes with its own set of challenges due to the scale, complexity, and critical nature of
these applications. Some of the common challenges in enterprise application development include:

1. Complex Business Logic: Enterprises often have intricate and unique business processes that need to
be modeled and implemented in the software. This complexity can make requirements gathering and
software design challenging.

2. Scalability: Enterprise applications must be able to handle large volumes of data and users. Ensuring
that the software can scale horizontally or vertically to accommodate growth can be a significant challenge.

3. Security: Enterprise applications typically deal with sensitive data and must adhere to strict security
standards and compliance regulations (e.g., GDPR, HIPAA). Implementing robust security measures to
protect data and ensure user authentication and authorization is vital.

4. Integration with Legacy Systems: Many enterprises have existing legacy systems that need to be
integrated with new applications. Bridging the gap between modern technologies and legacy systems can
be complex and time-consuming.

5. Data Management: Managing and maintaining large databases with complex data structures can be
challenging. Issues such as data consistency, data integrity, and data migration need careful consideration.

6. Performance Optimization: Enterprise applications must deliver optimal performance to meet user
expectations. Tuning and optimizing the software, database queries, and network communication are
ongoing tasks.

7. User Experience (UX): Creating a user-friendly interface for complex enterprise software can be a
significant challenge. Balancing functionality with usability is essential to ensure that users can effectively
use the application.

8. Compliance and Regulations: Enterprises often operate in regulated industries (e.g., finance,
healthcare), and compliance with industry-specific regulations is a critical concern. Developing software
that meets these compliance requirements can be demanding.

9. Change Management: Enterprises frequently undergo organizational changes, process revisions, or


technology updates. Managing these changes while ensuring the software remains aligned with evolving
business needs is a constant challenge.

10. Testing and Quality Assurance: Ensuring the quality and reliability of enterprise software is vital.
Comprehensive testing, including functional, regression, performance, and security testing, can be
resource-intensive.

11. Project Management: Large-scale enterprise projects require effective project management to handle
scope, timelines, budgets, and resources. Coordinating cross-functional teams and stakeholders can be
complex.

Enterprise application development requires a holistic approach that considers not only the technical
aspects but also the organizational, regulatory, and user-related challenges. Successful enterprise
application development teams must navigate these challenges effectively to deliver solutions that meet the
evolving needs of the organizatio

Page 30 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

23. What are the alternatives to CGI? Explain in detail. (APR 19)

The term "CGI" stands for Common Gateway Interface. It refers to a standard protocol or interface
that allows web servers to communicate with and execute external programs or scripts to generate dynamic
web content in response to client requests.

In simpler terms, CGI is a set of rules and conventions that enable web servers to run programs or scripts
on the server-side, process data, and generate dynamic web pages or responses to be sent back to users'
web browsers.

The alternatives of CGI are:

FastCGI: FastCGI maintains one or more instances of perl that it runs continuously along with an interface
that allows dynamic requests to be passed from the web server to these instances. It avoids the biggest
drawback to CGI, which is creating a new process for each request, while still remaining largely compatible
with CGI. FastCGI is available for a variety of web servers.

mod_perl: mod_perl is a module for the Apache web server that also avoids creating separate instances of
perl for each CGI. Instead of maintaining a separate instance of perl like FastCGI, mod_perl embeds the
perl interpreter inside the web server. This gives it a performance advantage and also gives Perl code
written for mod_perl access to Apache's internals.

Java servlets: Java servlets were created by Sun. Servlets are similar to CGI scripts in that they are code
that creates documents. However, servlets, because they use Java, must be compiled as classes before
they are run, and servlets are dynamically loaded as classes by the web server when they are run. The
interface is quite different than CGI. JavaServer Pages, or JSP, is another technology that allows
developers to embed Java in web pages, much like ASP.

PHP PHP is a programming language that is similar to Perl, and its interpreter is embedded within the web
server. PHP supports embedded code within HTML pages. PHP is supported by the Apache web server.

ColdFusion Allaire's ColdFusion creates more of a distinction than PHP between code pages and HTML
pages. HTML pages can include additional tags that call ColdFusion functions. A number of standard
functions are available with ColdFusion, and developers can create their own controls as extensions.
ColdFusion was originally written for Windows, but versions for various Unix platforms are now available as
well. The ColdFusion interpreter is integrated into the web server.

Page 31 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

24. What is Java Enterprise Edition (Java EE)? Explain. (NOV 19)

Java EE is a set of coordinated technologies and practices that enable developing, deploying and
managing multi-tier server centric enterprise applications. It is a collection of standardized components,
containers and services for creating and deploying distributed applications within a well-defined distributed
computing architecture.
The Java Platform, Enterprise Edition (Java EE) is a collection of Java APIs owned by Oracle that software
developers can use to write server-side applications. It was formerly known as Java 2 Platform, Enterprise
Edition, or J2EE. Here are some key aspects of Java EE:

1. Component-Based Architecture: Java EE promotes a component-based architecture where software


is organized into reusable components that can be assembled to create enterprise applications. The
primary components include Servlets, Java Server Pages (JSP), Enterprise JavaBeans (EJB), and Java
Persistence API (JPA) entities.

2. Multi-Tiered Architecture: Java EE supports multi-tiered application development, with distinct layers
for presentation (web), business logic, and data persistence. This separation of concerns enhances
maintainability and scalability.

3. Standardized APIs: Java EE defines a set of standardized APIs that developers can use to access
various enterprise services. These include APIs for database connectivity (JDBC), messaging (Java
Message Service or JMS), naming and directory services (Java Naming and Directory Interface or JNDI),
and more.

4. Security: Java EE includes comprehensive security mechanisms for authentication, authorization, and
data encryption. It supports role-based access control and integrates with various authentication
mechanisms, including LDAP, database-based authentication, and single sign-on (SSO) solutions.

5. Transaction Management: It provides built-in support for managing distributed transactions, ensuring
data consistency and reliability across multiple data sources. Java EE applications can participate in
distributed transactions using the Java Transaction API (JTA).

6. Concurrency and Resource Management: Java EE offers tools for managing concurrency and
resource pooling, optimizing performance and resource utilization. Enterprise beans can take advantage of
container-managed concurrency and resource management.

7. Messaging: Java EE includes JMS for building messaging-based applications. It allows for
asynchronous communication between components, facilitating scalability and decoupling of services.

8. Enterprise Integration: Java EE supports integration with existing enterprise systems and web services
through standardized protocols and APIs. This enables enterprises to connect their Java EE applications to
other platforms and services seamlessly.

9. Persistence: Java EE provides JPA for object-relational mapping, allowing developers to work with
relational databases using Java objects. This simplifies database operations and enhances portability
across different database systems.

Page 32 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

25. How servlet is better than CGI? (APR 23)

Servlets are server side components that provides a powerful mechanism for developing server web
applications for server side. Earlier CGI was developed to provide server side capabilities to the web
applications. Although CGI played a major role in the explosion of the Internet, its performance, scalability
and reusability issues make it less than optimal solutions. Java Servlets changes all that. Built from ground
up using Sun’s write once run anywhere technology java servlets provide excellent framework for server
side processing.

Using servlets web developers can create fast and efficient server side applications and can run it on any
servlet enabled web server. Servlet runs entirely inside the Java Virtual Machine. Since the servlet runs on
server side so it does not depend on browser compatibility.

There are many advantages of Servlet over CGI. The web container creates threads for handling the
multiple requests to the Servlet. Threads have many benefits over the Processes such as they share a
common memory area, lightweight, cost of communication between the threads are low. The advantages of
Servlet are as follows:

Servlets are generally considered better than CGI (Common Gateway Interface) for several reasons:

1. Performance: Servlets are more efficient than CGI scripts. Servlets run within the web server's process,
eliminating the overhead of creating a new process for each request, as is the case with CGI. This results
in faster response times and reduced resource consumption.

2. Resource Efficiency: Servlets reuse threads from a thread pool, reducing the need to create and
destroy processes, which is common in CGI. This efficient use of resources makes servlets suitable for
handling a large number of concurrent requests.

3. Scalability: Servlets can handle a high volume of requests and are well-suited for building scalable web
applications. CGI, on the other hand, may struggle to scale efficiently due to its process-per-request model.

4. State Management: Servlets provide built-in support for session management and can maintain user
sessions across multiple requests, making it easier to manage user state. CGI scripts are typically stateless
and require developers to implement session management manually.

5. Portability: Servlets are written in Java and follow platform-independent Java EE standards, allowing
them to run on any Java-enabled server. CGI scripts, in contrast, are typically written in languages like Perl
or C and may not be as portable across different server environments.

Page 33 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

26. Write a servlet program in java using jdbc to accept the customer details such as
customer id, customer name and contact no. from the user via html form and store
the same in the database. (APR 23)

HTML CODE:

<!DOCTYPE html>
<html>
<head>
<title>Customer Details Form</title>
</head>
<body>
<h1>Customer Details</h1>
<form action="/CustomerServlet" method="post">
Customer ID: <input type="text" name="customer_id"><br>
Customer Name: <input type="text" name="customer_name"><br>
Contact No: <input type="text" name="contact_no"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

JAVA CODE:

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/CustomerServlet")
public class CustomerServlet extends HttpServlet {
private static final String DB_URL = "jdbc:mysql://localhost:3306/your_database";
private static final String DB_USER = "your_username";
private static final String DB_PASSWORD = "your_password";

protected void doPost(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();

String customerId = request.getParameter("customer_id");


String customerName = request.getParameter("customer_name");
String contactNo = request.getParameter("contact_no");

try {
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);

Page 34 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

String sql = "INSERT INTO customers (customer_id, customer_name, contact_no) VALUES (?, ?,
?)";
PreparedStatement preparedStatement = connection.prepareStatement(sql);

preparedStatement.setString(1, customerId);
preparedStatement.setString(2, customerName);
preparedStatement.setString(3, contactNo);

int rowsInserted = preparedStatement.executeUpdate();


if (rowsInserted > 0) {
out.println("Customer details inserted successfully.");
} else {
out.println("Failed to insert customer details.");
}

preparedStatement.close();
connection.close();
} catch (Exception e) {
out.println("Error: " + e.getMessage());
}
}

Page 35 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
MORE ACADEMY BSC IT: SEM – V JAVA: U1

Page 36 of 36
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622

You might also like