0% found this document useful (0 votes)
2 views12 pages

Advanced Java IA3 Scheme (1)

The document outlines the evaluation scheme for the Advanced Java course at Brindavan College of Engineering for the academic year 2025-26. It covers various topics including HTTP request and response handling, servlet life cycle, JSP tags, cookies, JDBC drivers, and transaction processing in JDBC. Additionally, it includes example programs and explanations of key concepts related to these topics.

Uploaded by

HoD ISE
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views12 pages

Advanced Java IA3 Scheme (1)

The document outlines the evaluation scheme for the Advanced Java course at Brindavan College of Engineering for the academic year 2025-26. It covers various topics including HTTP request and response handling, servlet life cycle, JSP tags, cookies, JDBC drivers, and transaction processing in JDBC. Additionally, it includes example programs and explanations of key concepts related to these topics.

Uploaded by

HoD ISE
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Brindavan College of Engineering

Department of Information Science & Engineering


Academic Year 2025-26
Scheme of Evaluation

Semester: IV Course code: BIS402 Course Name: ADVANCED JAVA


Internal Assessment Date: 08-06-2026 Faculty In charge: Bharathi v
Test –III

MODULE 4

1 a) Explain how to handle HTTP request and response with an example. 7


HTTP (HyperText Transfer Protocol) is used for communication between a client (browser, mobile app) and a
server.
HTTP Request: Sent by the client to the server asking for data or requesting an action.
HTTP Response: Sent by the server back to the client containing the requested data or status information.

Components of an HTTP Request


Request Method – GET, POST, PUT, DELETE, etc.
 URL – Resource being requested.
 Headers – Additional information (Content-Type, Authorization, etc.).
 Body – Data sent to the server (mainly in POST/PUT requests).
Example Request:
POST /users HTTP/1.1
Host: [Link]
Content-Type: application/json

{
"name": "John",
"age": 25
}
Components of an HTTP Response
 Status Code – Indicates success or failure.
 Headers – Information about the response.
 Body – Actual data returned by the server.
Example Response:
HTTP/1.1 201 Created
Content-Type: application/json

{
"message": "User created successfully"
}
Example: Handling HTTP Request and Response
const express = require('express');
const app = express();
[Link]('/student', (req, res) => {
const student = {
id: 101,
name: "Deepthi",
course: "MCA"
};

[Link](student);
});

[Link](3000, () => {
[Link]("Server running on port 3000");
});
b) Explain the Servlet life cycle with neat diagram. 6
Servlet Life Cycle
The Servlet Life Cycle describes the stages through which a servlet passes from its creation to its destruction.
The life cycle is managed by the web container (such as Apache Tomcat).
There are three main life cycle methods:
 init() – Initializes the servlet.
 service() – Processes client requests.
 destroy() – Cleans up resources before the servlet is removed.
Neat Diagram of Servlet Life Cycle
Client Request
|
v
+----------------+
| Servlet Loaded |
+----------------+
|
v
+----------------+
| init() |
| Initialization |
+----------------+
|
v
+----------------+
| service() |
| Handle Request |
+----------------+
|
Multiple Requests
|
v
+----------------+
| destroy() |
| Cleanup Tasks |
+----------------+
|
v
Servlet Removed
Example Program
import [Link].*;
import [Link].*;
import [Link].*;

public class LifeCycleServlet extends HttpServlet {

public void init() {


[Link]("Servlet Initialized");
}

public void doGet(HttpServletRequest req,


HttpServletResponse res)
throws IOException {
[Link]().println("Hello Servlet");
}

public void destroy() {


[Link]("Servlet Destroyed");
}
}
OR
2 a) Explain different JSP tags with a program to demonstrate all tags. 7
JSP Tags and Their Types
JSP (Java Server Pages) Tags are special tags used to insert Java code, declare variables, and display output
within a JSP page.
There are three main JSP scripting tags:
 Declaration Tag (<%! ... %>)
 Scriptlet Tag (<% ... %>)
 Expression Tag (<%= ... %>)
1. Declaration Tag (<%! ... %>)
Used to declare variables and methods.
Variables declared here become instance variables of the generated servlet.
Syntax
<%! declaration; %>
Example
<%! int count = 0; %>
2. Scriptlet Tag (<% ... %>)
Used to write Java code inside a JSP page.
Executed whenever the page is requested.
Syntax
<% Java Code %>
Example
<%
count++;
%>
3. Expression Tag (<%= ... %>)
Used to display the value of a variable or expression.
The result is automatically printed to the browser.
Syntax
<%= expression %>
Example
<%= count %>
<%@ page language="java" contentType="text/html" %>

<html>
<head>
<title>JSP Tags Demo</title>
</head>
<body>
<!-- Declaration Tag -->
<%!
int count = 0;
String greet() {
return "Welcome to JSP";
}
%>

<!-- Scriptlet Tag -->


<%
count++;
String name = "Deepthi";
%>

<h2>JSP Tags Demonstration</h2>


<!-- Expression Tags -->
<p>Message: <%= greet() %></p>
<p>User Name: <%= name %></p>
<p>Page Visit Count: <%= count %></p>
</body>
</html>
Output
JSP Tags Demonstration
Message: Welcome to JSP
User Name: Deepthi
Page Visit Count: 1
b) What are cookies? Write a program to create cookie with name “User name” and value: “xyz”. 6
Also display stored cookie in webpage.
Cookies in JSP
Cookies are small text files stored on the client's browser by a web server. They are used to store user-specific
information such as login details, preferences, session identifiers, etc.
Advantages of Cookies
 Maintain user sessions.
 Store user preferences.
 Reduce server load by storing data on the client side.
JSP Program
<%@ page import="[Link]" %>
<html>
<head>
<title>Cookie Example</title>
</head>
<body>
<%
// Create Cookie
Cookie ck = new Cookie("User name", "xyz");

// Add cookie to response


[Link](ck);
%>

<h2>Cookie Created Successfully!</h2>

<%
// Retrieve cookies
Cookie cookies[] = [Link]();

if(cookies != null)
{
for(Cookie c : cookies)
{
if([Link]().equals("User name"))
{
%>
<h3>Stored Cookie Details</h3>
Cookie Name: <%= [Link]() %><br>
Cookie Value: <%= [Link]() %>
<%
}
}
}
%>
</body>
</html>
Output
Cookie Created Successfully!
Stored Cookie Details
Cookie Name : User name
Cookie Value : xyz
MODULE 5
3 a) Explain the four types of JDBC drivers 7
JDBC (Java Database Connectivity) is an API that enables Java applications to connect and interact with
databases. JDBC drivers act as a bridge between a Java application and the database.
There are four types of JDBC drivers:
1. Type 1 Driver – JDBC-ODBC Bridge Driver
Architecture
Java Application

JDBC API

JDBC-ODBC Bridge

ODBC Driver

Database
Features
 Converts JDBC calls into ODBC calls.
 Requires ODBC driver installation on the client machine.
 Not platform-independent.
 Removed from Java 8 onwards.
Advantages
 Easy to use for small applications.
 Suitable for testing purposes.
Disadvantages
 Slow performance.
 Requires ODBC setup.
 Not recommended for production.
2. Type 2 Driver – Native API Driver
Architecture
Java Application

JDBC API

Native API Driver

Database
Features
 Uses database-specific native libraries.
 Converts JDBC calls into native database API calls.
Advantages
 Better performance than Type 1.
 Database-specific optimization.
Disadvantages
 Native libraries must be installed.
 Platform dependent.
Example
Oracle OCI Driver.
3. Type 3 Driver – Network Protocol Driver
Architecture
Java Application

JDBC API

Network Protocol Driver

Middleware Server

Database
Features
 Sends JDBC calls to a middleware server.
 Middleware converts requests into database-specific protocols.
Advantages
 No native libraries required.
 Supports multiple databases.
Disadvantages
 Requires middleware server.
 Network overhead may reduce performance.
4. Type 4 Driver – Thin Driver

Architecture
Java Application

JDBC API

Type 4 Driver

Database
Features
 Pure Java driver.
 Converts JDBC calls directly into database-specific protocol.
 Communicates directly with the database.
Advantages
 Best performance.
 Platform independent.
 No additional software required.
 Most widely used driver.
Disadvantages
 Database-specific driver required.
Examples
MySQL Connector/J
Oracle Thin Driver
PostgreSQL JDBC Driver
b) Explain transaction processing in JDBC 5
Transaction Processing in JDBC
A transaction is a group of one or more SQL statements that are executed as a single unit of work. Transaction
processing ensures that either all operations are completed successfully or none of them are performed,
maintaining database consistency.
JDBC provides transaction management through the Connection interface.
Key Concepts
Auto-Commit Mode
By default, JDBC operates in auto-commit mode.
Each SQL statement is treated as a separate transaction and is automatically committed after execution.
Connection con = [Link](url, user, password);
[Link]([Link]()); // true
Disabling Auto-Commit
To manage transactions manually, disable auto-commit.
[Link](false);
Commit
Saves all changes made during the transaction permanently.
[Link]();
Rollback
Undoes all changes made during the current transaction if an error occurs.
[Link]();
Example of Transaction Processing
import [Link].*;
public class TransactionDemo {
public static void main(String[] args) {
try {
Connection con = [Link](
"jdbc:mysql://localhost:3306/bank", "root", "root");

[Link](false);

Statement stmt = [Link]();

[Link](
"UPDATE accounts SET balance = balance - 1000 WHERE acc_no = 101");

[Link](
"UPDATE accounts SET balance = balance + 1000 WHERE acc_no = 102");

[Link]();
[Link]("Transaction Successful");

} catch (Exception e) {
try {
[Link]();
[Link]("Transaction Rolled Back");
} catch (SQLException ex) {
[Link]();
}
}
}
}

OR
Mention all steps to create association between database and JDBC-ODBC Bridge
4 a) 7
Steps to Create Association Between Database and JDBC–ODBC Bridge
JDBC–ODBC Bridge is a Type-1 JDBC driver that connects a Java application to a database through ODBC.
The following steps are used to create an association between a database and the JDBC–ODBC Bridge:

1. Create a Database
Open a database application such as MS Access.
Create a new database (e.g., [Link]).
Create the required tables and save the database.

2. Configure ODBC Data Source


Open Control Panel → Administrative Tools → ODBC Data Sources.
Select System DSN or User DSN.
Click Add.
Choose the appropriate ODBC driver (e.g., Microsoft Access Driver).
Click Finish
.
3. Create a Data Source Name (DSN)
Enter a Data Source Name (DSN) (e.g., StudentDSN).
Click Select and browse to the database file.
Save the DSN configuration.

4. Load JDBC–ODBC Bridge Driver


In the Java program, load the JDBC–ODBC Bridge driver:
[Link]("[Link]");

5. Establish Connection
Use the DSN name to establish a connection:
Connection con = [Link](
"jdbc:odbc:StudentDSN");

6. Create Statement Object


Create a statement to execute SQL queries:
Statement stmt = [Link]();

7. Execute SQL Queries


Execute SQL commands on the database:
ResultSet rs = [Link]("SELECT * FROM Student");

8. Process the Result


Retrieve and display data:
while([Link]()) {
[Link]([Link](1) + " " + [Link](2));
}

9. Close the Connection


Release database resources:
[Link]();
[Link]();
[Link]();
Flow Diagram
Database Creation

Configure ODBC Driver

Create DSN

Load JDBC-ODBC Driver

Establish Connection

Create Statement

Execute Queries

Process Results

Close Connection
Example Program:
import [Link].*;
public class JdbcOdbcDemo {
public static void main(String[] args) {
try {
// Load JDBC-ODBC Bridge Driver
[Link]("[Link]");

// Establish connection using DSN


Connection con = [Link]("jdbc:odbc:StudentDSN");

// Create Statement object


Statement stmt = [Link]();

// Execute SQL query


ResultSet rs = [Link]("SELECT * FROM Student");

// Display records
[Link]("Student Details");
[Link]("----------------");

while ([Link]()) {
int id = [Link]("id");
String name = [Link]("name");

[Link]("ID: " + id + " Name: " + name);


}

// Close resources
[Link]();
[Link]();
[Link]();

} catch (Exception e) {
[Link]("Error: " + e);
}
}
}
b) List and elaborate Database Metadata Object methods 5
The DatabaseMetaData interface provides information about the database, driver, tables, columns, and
supported features. It helps programmers obtain details about the database environment dynamically.

Obtaining DatabaseMetaData Object


Connection con = [Link](url, user, password);
DatabaseMetaData dbmd = [Link]();

Methods:
getDatabaseProductName() .
getDatabaseProductVersion() .
getDriverName()
getDriverVersion()
getUserName() .
getURL() .
getTables()
Example Program
import [Link].*;
public class DatabaseMetaDataDemo {
public static void main(String[] args) {
try {
Connection con = [Link](
"jdbc:mysql://localhost:3306/studentdb",
"root",
"root");

DatabaseMetaData dbmd = [Link]();

[Link]("Database Name: "


+ [Link]());

[Link]("Database Version: "


+ [Link]());

[Link]("Driver Name: "


+ [Link]());

[Link]("Driver Version: "


+ [Link]());

[Link]("User Name: "


+ [Link]());

[Link]("URL: "
+ [Link]());

[Link]("Supports Transactions: "


+ [Link]());

[Link]();

} catch (Exception e) {
[Link](e);
}
}
}

Bharathi v
Faculty name & Signature Reviewer name & Signature Signature of HOD

You might also like