Server time: <%= new [Link]()
Q, How it's compiled
The expression becomes:
java O Copy code
[Link](new [Link]());
v Benefit:
¢ Clean way to output variables
Vv
! Drawback:
+ Add Ask anything a
ChatGPT can make mistakes. Check important info. See Cookie
Prefer845 BEES:
ChatGPT
[Link]
x Vv
G@ ChatGPT ~
V 2.3 Declaration Element — <%!
%>
Declares methods or fields that become part of
the Servlet class, outside the service method.
isp © Copy code
<%!
int counter = 0;
int increment() {
return ++counter;
‘%>
Hello <%= name %>
Last visit: <%= [Link]("
Application started: <%= application.g
Q. Critical Analysis
¢ Implicit objects simplify interaction with
servlet API
¢ They encourage logic in the view, which
modern architectures avoid
¢ session and application can cause
memory issues if misused
* out can cause bu,“ overflow if used
incorrectly
+ Add Ask anything 8
ChatGPT can make mistakes. Check important info. See Cookie
Preferences846 BEES:
ChatGPT :
a oa
G@ ChatGPT ~ qd ©
Servlet.
There are 3 directive types:
Directive Usage Purpose
page <%#@ page ... Defines page-level
e settings
include
+ Add Ask anything 36
ChatGPT can make mistakes. Check important info. See Cookie
Preferences.846 BEES:
ChatGPT
[Link]
x Vv
G@ ChatGPT ~
v 4.1 page directive
Used for configuration.
isp © Copy code
<%@ page import="[Link]" %>
<%@ page contentType="text/html; charset=U
<%@ page errorPage="[Link]" %>
Q Critical Analysis
© Powerful but can make JSP heavy
« Excessive imports slow down translation
¢ Often replaced by tag libraries (JSTL)
v 4.2 include directive — Static include
isp © Copy code
<#@ include file="[Link]" %>
This is inserted before « J) pilation — fast but not
dynamic.
+ Add Ask anything
ChatGPT can make mistakes. Check important info. See Cookie
PreferWRF ll 832%
xv ChatGPT < Qa :
[Link]
@ ChatGPT v qd @
v 4.3 taglib directive
Used to load JSTL or custom tag libraries.
jsp © Copy code
<%@ taglib uri="[Link]
Welcome ${user}
Q Critical Analysis
¢ Best approach: encourages separation of
concerns
¢ Uses EL (Expression Language), replacing
scriptlets
¢ Safe, readable, MVC-friendly
¢ Modern JSP relies heavily on taglibs
v .
yy 5. Integratea Comprehensive
FE :
+ Add Ask anything
ChatGPT can make mistakes. Check important info. See Cookie
Prefers846 BEES:
xv ChatGPT < Qa :
[Link]
@ ChatGPT v qd @
JSP Example: [Link]
isp © Copy code
<%@ page import="[Link]" %>
<%@ include file="[Link]" %>
<%@ taglib uri="[Link]
User Dashboard
<%
String user = (String) [Link]
if (user == null) {
response. sendRedirect("login. jsp"
return;
>
Welcome: <%= user %>
Server Time: ae Date() %>
trang 1airsuvame
Due
: Ce di
[Link] = firs © Cory code
[Link] = lastName;
[Link] = email;
ye How Hibernate Maps This
Entity Internally
Hibernate generates SQL like:
sql © Copy code
Get smarter responses, upload files and images,
and more.
Sign up for free
++ Add
< anything
ChatGPT can make mistakes. Check important info. See Cookie
Preferences.855 &
ChatGPT .
a [Link] < Q ia
@ ChatGPT v q@ @
sql © Copy code
create table students (
id bigint not null,
first_name varchar(60) not null,
last_name varchar(60) not null,
email varchar(255),
primary key (id)
oF
create sequence hibernate_sequence start
Hibernate converts objects —. SQL via metadata
from these annotations.
a~* cA 8
Get smarter responses, upload files and images,
and more.
Sign up for free
Vv
+ Add Ask anything
ChatGPT can make mistakes. Check important info. See Cookie
Preferences.xv ChatGPT < Qa :
[Link]
@ ChatGPT v qd @
* database-specific optimizations
« bulk operations
©, 6. Features Comparison Table
Feature HQL. sQL o
Uses entities v Yes x No
Uses x No v Yes
tables/columns
Database- v Yes x No
independent
Object-oriented v Yes x No
Supports Hibernate ——- Yes Limited
caching
Supports native DB Limited v Full
functions
Complex queries Meum Strong
+ Add Ask anything
ChatGPT can make mistakes. Check important info. See Cookie
Prefer859 BEES:
xv ChatGPT < Qa :
[Link]
@ ChatGPT v qd @
Q. 1. Definition
HQL (Hibernate Query Language)
¢ An object-oriented query language.
* Queries operate on entities, their fields, and
relationships, not directly on tables.
¢ Database-independent (portable across DB
vendors).
SQL (Structured Query Language)
« Arelational query language.
* Queries operate on tables, columns, rows, and
joins.
¢ Database-specific (different SQL dialects per
DB).
©, 2. Syntax Differences
HQL Example
Java © Copy code
+ Add Ask anything
ChatGPT can make mistakes. Check important info. See Cookie
Prefers8:59
xv ChatGPT <<:
[Link]
@ ChatGPt v qd é
Q. 2. Syntax Differences
HQL Example
java © Copy code
String hql = "FROM Employee e WHERE [Link]
List list = [Link]
.setParamete
ceeeet ye
« Uses class names ( Employee )
« Uses property names ( department .name )
¢ No need to write joins manually—Hibernate
resolves them using mappings.
SQL Example
Java © Copy code
String sql = "SELECT * FROM employee e "
"JOIN department d ON [Link]
"WHERE [Link] = 2";
List row [Link]
.setParamete
Victey-
+ Add ) Ask anything @
ChatGPT can make mistakes. Check important info. See Cookie
Preferences,8:59 @-
xv ChatGPT
[Link]
G@ ChatGPT ~
©. 3. Return Types
Hau
Returns mapped Java entities:
java © Copy code
List employees = [Link]();
SQL
Returns:
* raw Object[] rows
* or scalar values
* or entities with extra configuration
java © Copy code
List data = [Link]();
Vv
OA Daetahilinn
+ Add Ask anything
ChatGPT can make mistakes. Check important info. See Cookie
Prefer8:59 ° Wk F all 8 30%
ChatGPT :
arene [Link] < A:
G@ ChatGPT ~ ©
¢ Database-agnostic
¢ Hibernate translates HQL — SQL for the
specific DB dialect
¢ Easier for multi-DB applications
SQL
* Database-dependent
¢ Must adjust queries if switching from MySQL
~ Oracle -. PostgreSQL
Q. 5. Performance
HQL
« Uses Hibernate caching
¢ Supports lazy loading
* Typically better for object-centric operations
SQL
* Can be faster for:
* complex joins J
* database-specific optimizations
+ Add Ask anything
ChatGPT can make mistakes. Check important info. See Cookie
Prefers9:03 BSE: 29%
4 Google 6
Q > whatis the spring framew.. GY @
Ml Videos Images Shopping Short videos
+> AlOverview eet
fé 6 4) Listen
The Spring Framework is an open-source,
somprehensive framework for building
anterprise-level Java applications. It aims to
simplify the development process by providing a
nodular and flexible architecture that addresses
sommon challenges in enterprise Java
Show more V
Spring Framework
Software1, Introduction to Spring cP
Framework
Images may be subject to copyright. Learn More
« Share
DQ Save
j Spring
— 1. Introduction to Spring ...
So
8 BMC Software
The Spring Framework B...Bi Overview of Spring Framework
ZA comprehensive framework or enterise Jove applications
Provides support for developing Java-based applications with
features like Dependency Injection, Aspect-Oriented
Programming (AOP), et.
¥ Keymodules: Spring Core, Spring MVC, Spring Boot, Spring
Cato spring
Bi Benefits of Spring Framework
ieee
(2) eer
Advantages of
Spring Framework Lies
etter)
A Disadvantages of Spring Framework
ra)
ea)
o eee
CeriWriting a Basic Spring App
Let's create a simple Spring application
+ Create a configuration file applicationContextxmi)
+ Define a simple java bean,
+ Load the Bean using spring container
+ Runthe application
Sample Spring Application Code
Java Bean (HelloWorld java) SpringConfiguration([Link])
Running Spring Application Code
Create a Main java file
Run Main java and see the output.
Output: * Hello Spring”ey loC(Inversion of Control)
‘What is loC?
7 IoCis a design principle that transfers the control of object creation to the
framework.
7 Instead of manually creating objects, Spring injects dependencies
automatically.
a loC Container features
Spring 1OC Container
A Types of loC Container
‘mor enterprise spec incon5 Dependency Injection
7 ttis a design pattem which removes the
dependency from the programming code,
that makes the application easy to
manage and tos.
Dependency Injection makes our
penn coe cnc ch
nena caren rleeraton =)
dosen't affect the use.
a Types of Dependency Injection
1. Constructor injection [Link]
Dependencies are injected through Dependencies ae injected using setter
constructor parameters methods.
1 Eneures immutebilty & final flelds ‘1 lows optional dependencies.
a Spring Bean Lifecycle and Scope
1 Understanding Spring Bean ifeeyele ean initialization Steps
Bean Instantiation ~ Objoctis created
Bean Initialization = @PostConstruct or
Intmethed executes.
Bean Ready to Use Object is used
Bean Destruction @PreDestroy or
destroy method executes.
| Spring Bean Lifecycle and Scope
2. Spring Bean Scopes
Singleton (Defaut) ~ One instance per Spring container
Prototype ~ New instance forever request
Request Oneinstance per HTTP request (fr web apps)
Session ~ One instance per session.
Global Session ~- One instance per gba
ASN88Spring Configuration
‘7 What is Spring Configuration?
7. Spring needs to be configured soit knows how to manage
objects and dependencies.
spring
Types of Configuration
Y XML-based Configuration
{ erseetencamet ey |
+ Prefered in legacy projects
7 Java-based Configuration
Uses @Configuration and @Bean,
‘Type safe and modem approach,
7 Annotation based Configuration
BComponent, @Service, and @Repository.
°s @ComponentScan inthe configuration
Spring Annotations
Commonly Used Spring Annotations
Spring simplifies configurations using annotations
instead of XML.
Core Annotations in Spring:
Annotation Purpose
@Component Generic Spring managed bean
oe Indicates a service layer component
@Repository ‘Specialized DAO (Data Access Object) component
@Autowived ‘Automatically injects dependencies,
Spring AnnotationsSpring Annotations
Example: Dependency Injection using @Autowired.
@Configuration ~ Defines a Spring configuration class.
@Componentscan ~ Specifies packages to scan for components
Best Practice: Use @ComponentScan(basePackages = “com example") to scan custom pa
Creating a Spring Application
Building a Simple Spring Application
Steps to Create a Spring Application:
Set up a Maven project in Eclipse/Intelid
Add dependencies in pom xl
ee eee ey
paler emer eet eran reer eet Ret
Creating a Spring Applicatio:
Implement Dependency Injection in a Real-World Example (Order Processing).
Cas erie Cat
eae accom
a ase aay
Ot
SOL toedKey Takeaways:
+ Use @Autowired for dependency injection
+ Maintaina clean separation of concerns,
Spring Transaction Management
What isa Transaction?
‘Atransaction ensures data consistency in the database by folowing the ACID
properties:
+ _Atomicity ~ All operations complete successfully or none at al
Consistency ~ Data remains valid before and after the transaction
+ Isolation ~ Concurrent transactions don’ interfere
Durability - Changes are permanent after the transaction commits.
+ Why Use Transaction Management?
Ensures data integrity
Prevents partial updates.
+ Manages rollback in case of failue.
: Spring Transaction Management
Using @Transactional for Transaction Management
+ Without Transactions (Risky Behavior)
If anerror occursin credit) the money is stil debited!
Cort a erent
Cet
ee ee ene eee a
A Spring Transaction Management
Using @Transactional for Transaction Management
With @Transactional (Safe Approach)
Han error occurs, changes rollback automatically.
eee