0% found this document useful (0 votes)
3 views14 pages

Ajava W24

The document covers various Java technologies including the URL class, HttpServletResponse methods, JSP action tags, Hibernate advantages, JDBC drivers, TCP vs UDP sockets, session management techniques, PreparedStatement usage, filters, JavaBeans, JSF framework benefits, validator tags, cookies for session management, Spring Framework advantages, Dependency Injection, and Hibernate interfaces. It provides detailed explanations and comparisons of these concepts, highlighting their purposes and functionalities. The content serves as a comprehensive guide for understanding key Java web development components.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views14 pages

Ajava W24

The document covers various Java technologies including the URL class, HttpServletResponse methods, JSP action tags, Hibernate advantages, JDBC drivers, TCP vs UDP sockets, session management techniques, PreparedStatement usage, filters, JavaBeans, JSF framework benefits, validator tags, cookies for session management, Spring Framework advantages, Dependency Injection, and Hibernate interfaces. It provides detailed explanations and comparisons of these concepts, highlighting their purposes and functionalities. The content serves as a comprehensive guide for understanding key Java web development components.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Q.1 (a) 1) What is the purpose of the URL class in Java?

Purpose of URL class in Java:


The URL class in Java is used to represent Uniform Resource Locators, which are pointers to
resources on the internet. It provides methods to access various parts of a URL like protocol,
host, file, etc., and to open a connection to the resource.

2) List out the important methods of HttpServletResponse.

Important methods of HttpServletResponse:

addCookie(Cookie cookie)

sendRedirect(String location)

setContentType(String type)

setHeader(String name, String value)

getWriter()

3) What are the JSP action tags?

JSP Action Tags:

• <jsp:useBean>

• <jsp:setProperty>

• <jsp:getProperty>

• <jsp:include>

• <jsp:forward>

• <jsp:param>
(b) 1) What are the advantages of Hibernate over JDBC?

Advantages of Hibernate over JDBC:

• No need to write SQL queries for CRUD

• Automatic table mapping using annotations/XML

• HQL for database-independent queries

• Caching for performance

• Built-in transaction management

2) What are the three types of text field’s tags provided by JSF?

Three types of text field tags in JSF:

• <h:inputText>

• <h:inputSecret>

• <h:inputTextarea>

(c) What is JDBC driver? Explain its role and compare various JDBC drivers.

JDBC Driver: A JDBC driver enables Java applications to connect and interact with databases.
Types:

• Type 1: JDBC-ODBC Bridge

• Type 2: Native-API driver

• Type 3: Network Protocol driver

• Type 4: Thin driver (Pure Java)

Comparison:

• Type 1 is slow and platform-dependent

• Type 4 is the fastest and platform-independent

• Type 3 supports multiple databases

• Type 2 is better than Type 1 but still platform-dependent


Q.2 (a) What are the differences between a TCP socket and UDP socket? How are
they created in Java?

Differences between TCP and UDP Sockets & Their Creation in Java:

Feature TCP Socket UDP Socket

Type Connection-oriented Connectionless

Reliability Reliable (ensures data delivery) Unreliable

Protocol Class Socket, ServerSocket DatagramSocket

Use case File transfer, web browsing Streaming, DNS

(b) Demonstrate the use of ServletConfig and ServletContext.

1. ServletConfig

• Purpose: Used to pass configuration information to a particular servlet.

• Scope: Per servlet.

• Defined in: web.xml


2. ServletContext

• Purpose: Provides information about the web application.

• Scope: Shared by all servlets in the application.

• Used for: Reading global parameters, resource paths, and for inter-servlet
communication.
Summary:

Feature ServletConfig ServletContext

Scope Per servlet Whole application

Access getServletConfig() getServletContext()

Defined in Inside <servlet> Inside <context-param>

Use Servlet-specific config Application-wide config


(c) What is Session? Compare different session management techniques.

What is a Session?

A session is a mechanism to maintain state (data) about a user across multiple requests to a
web application.
HTTP is a stateless protocol, so sessions allow you to remember information (like user login)
during a user's interaction with the server.

Session Management Techniques

Storage
Technique Description Pros Cons
Location

Small text files stored on the Size limit (~4KB),


Cookies Client-side Easy to use
client’s browser less secure

Works even if
URL Session ID is appended to the Client-side Exposes session ID
cookies
Rewriting URL (?sessionid=123) (URL) in URL
disabled

Data is stored in hidden form


Hidden Client-side Simple for Only works with
fields and passed on form
Fields (Form) small data forms
submit

Memory
HttpSession Java-provided API that stores Most secure &
Server-side consumption on
API session data on the server flexible
server

• Use HttpSession for secure and scalable server-side session tracking.

• Use cookies or URL rewriting when session IDs need to be tracked across stateless
requests.

• Hidden fields are suitable for form-based applications with minimal session data.
Q.3 (a) What is the use of PreparedStatement? How will you use it?

PreparedStatement is used to execute parameterized SQL queries in Java. It helps prevent


SQL injection attacks, improves performance for repeated queries, and supports dynamic
inputs.

Advantages:

• Prevents SQL injection

• Increases performance with precompiled queries

• Supports input parameters (?)

(b) What is filter? How will you configure filter using deployment descriptor?

A Filter in Java EE is an object that performs filtering tasks on either the request to a
resource or on the response from a resource, or both.

Common Uses:

• Authentication and Authorization

• Logging and auditing

• Compression

• Input validation
(c) What is Java Bean? Demonstrate the use of JSP bean in web application.

A JavaBean is a reusable, serializable Java class that follows specific conventions. It is


commonly used in web applications to store, retrieve, and share data between components
like JSP and Servlets.

Key Features of JavaBean:

• Must have a public no-argument constructor

• Private properties (fields)

• Public getter and setter methods for accessing properties

• Implements Serializable (optional, but recommended)

A JavaBean is a simple Java class used to encapsulate data. In JSP, <jsp:useBean>,


<jsp:setProperty>, and <jsp:getProperty> tags are used to access and manipulate bean
properties.
JavaBeans provide a clean way to separate business logic from presentation logic in JSP-
based web apps. They are easy to use, promote reusability, and are ideal for managing user
data and form inputs.

Q.4 (a) What are the benefits of using JSF Framework?

1. Component-Based UI:
JSF provides a rich set of reusable UI components like forms, tables, and inputs that
simplify web development.

2. Event-Driven Programming:
Supports server-side event handling, similar to desktop applications (e.g., button click
events).

3. Integration with Tools & Frameworks:


Easily integrates with IDEs (like Eclipse), libraries (like PrimeFaces), and frameworks
(like Spring and Hibernate).

JSF helps build maintainable, scalable web applications with clean separation between UI
and logic.

(b) How will you use validator tags in JSF?

Validator Tags in JSF:

JSF provides built-in validator tags to validate user input on UI components.

Common Validator Tags:

• <f:validateLength> — Validates input length

• <f:validateLongRange> — Validates numeric range

• <f:validateDoubleRange> — Validates decimal range

• <f:validateRegex> — Validates input against a regular expression


Example

Validator tags are nested inside input components.

If input is invalid, JSF prevents form submission and shows error messages.

(c) What are the cookies? Demonstrate the use of cookies in servlet for session
management.

Cookies are small pieces of data sent by the server to the client’s browser and stored there
to maintain user state across multiple requests.

• Cookies are created using new Cookie(name, value) and added via
response.addCookie().

• Cookies are read from the request using request.getCookies().


• They help track sessions by storing session IDs or user info on the client side.

Q5 (a) What is the advantage of using Spring Framework?

Advantages of Spring Framework:

1. Dependency Injection (DI):


Simplifies object creation and wiring, making code loosely coupled and easier to test.

2. Modular and Lightweight:


Spring is modular; you can use only the parts you need without heavy overhead.

3. Comprehensive Infrastructure:
Provides support for transaction management, security, data access, MVC, and more,
reducing development effort.

(b) What do you understand by Dependency Injection? How do we implement it using

Spring Framework?

Dependency Injection is a design pattern where an object’s dependencies (other objects it


needs) are provided (injected) by an external entity rather than the object creating them
itself. This promotes loose coupling and easier testing.

2. Using Annotations:
Spring provides flexible ways to inject dependencies, reducing manual object creation and
improving maintainability.

(c) What are the different Hibernate interfaces? Explain their role in brief.

Hibernate provides several key interfaces that help in managing the persistence of Java
objects to the database:

1. SessionFactory

• Acts as a factory for Session objects.


• Created once per application and is thread-safe.

• Holds cached data and configuration information.

• Used to open new Session objects.

2. Session

• Represents a single unit of work with the database (a single connection).

• Used to create, read, update, and delete persistent objects.

• Not thread-safe; used by a single thread at a time.

• Implements PersistenceContext for caching entities during a transaction.

3. Transaction

• Used to manage database transactions in a consistent way.

• Allows commit and rollback of transactions to maintain data integrity.

4. Query

• Used to execute HQL (Hibernate Query Language) or native SQL queries.

• Provides methods to set parameters and get result lists.

5. Criteria (deprecated in latest versions, replaced by CriteriaQuery)

• Used for creating programmatic and typesafe queries.

• Allows dynamic query creation without HQL.

6. Interceptor

• Provides callback methods to intercept and customize certain Hibernate operations


(e.g., on save, update).
Session: Handles CRUD operations & database interaction

Transaction: Controls transaction boundaries

Query: Executes queries and retrieves results

Interceptor: Customizes Hibernate operations

You might also like