Bitwise Learning Java Unit 5
Bitwise Learning Java Unit 5
I T S
E
OBJECT ORIENTED E
G
A R N
N I
T W I
PROGRAMMING WITH JAVA
I S
E
(BCS-403)
G
A R I N
CompleteN Notes
OOPS WITH JAVA (BCS-403)
UNIT 5 - SYLLABUS
T W I
I S
Spring Framework: Spring Core Basics-Spring Dependency Injection concepts, Spring
E
Inversion of Control, AOP, Bean Scopes- Singleton, Prototype, Request, Session, Application,
Web Socket, Auto wiring, Annotations, Life Cycle Call backs, Bean Configuration styles
Spring Boot: Spring Boot Build Systems, Spring Boot Code Structure, Spring Boot Runners,
Logger, BUILDING RESTFUL WEB SERVICES, Rest Controller, Request Mapping, Request
E
L
G
Body, Path Variable, Request Parameter,
A R GET, POST,N PUT, DELETE APIs, Build Web
N I
Applications
2
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
W Basics
T Core
Spring I S
I
What is Spring?: The Spring framework is an open-source, powerful, lightweight, and modular
E
Java platform that provides comprehensive infrastructure support for developing robust
enterprise-level Java applications easily and rapidly.
Why Spring?: Before Spring, developers used technologies like Hibernate and Enterprise Java
Beans (EJB) which had complex setup problems. Spring targets making J2EE development easier
and promotes good programming practices by enabling a POJO (Plain Old Java Object)-based
G
E of as a "framework of frameworks" because it seamlessly
programming model. It can be thought
A
provides support to various other frameworks N Hibernate, EJB, and JSF.
such asI Struts,
R N
3
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
TW Basics
Spring Core
I S
Core Architecture Modules: The SpringI Framework comprises several layers:
E
Core Container: Consists of the Core, Beans, Context, and Expression Language modules. The
Core and Beans modules provide the fundamental parts of the framework, including IoC and
Dependency Injection.
Data Access/Integration: Consists of JDBC (removes tedious JDBC coding), ORM
(Integration with Hibernate/JPA), OXM, JMS (Java Messaging Service), and Transaction
modules.
L
G
E
AOP and Test: Provides Aspect-Oriented
A N implementation and supports testing
Programming
I
R
Spring components with JUnit or TestNG. N
Web (MVC): Contains Web, Servlet, Portlet, and Struts modules for web applications.
4
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
TW Basics
Spring Core
I S
I
E
L
G
E
A N
R N I
5
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
W Framework
Advantages of Spring
T I S
The Spring Framework was fundamentallyI designed to resolve massive enterprise complexities. Its
E
profound advantages include:
Predefined Templates: Spring provides ready-made templates for technologies like JDBC,
Hibernate, and JPA. This eliminates the need to write tedious boilerplate code (like
opening/closing connections) and hides the basic steps of these technologies.
Loose Coupling: The Spring applications are exceptionally loosely coupled because of Dependency
Injection (DI). Components do not create their own dependencies.
L
G
E pattern makes it far easier to test the application. Legacy
Easy to Test: The Dependency Injection
A N I
R N
EJB or Struts applications strictly required a heavy server to run the application, but Spring
components (being simple POJOs) do not require a server for unit testing.
Declarative Support: It provides extensive declarative support for cross-cutting concerns like
caching, validation, transactions, and formatting. 6
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
E
program is "inverted". In traditional Java applications, the programmer explicitly controls the
execution flow and manually creates objects using the new keyword.
The IoC Container: In Spring, the control over the lifecycle, creation, configuration, and
management of these objects is handed over entirely to the Spring Framework (IoC Container).
Mechanism: The Container gets information about objects from XML files, Java annotations, or
Java code. It creates the objects, assembles their dependencies, and manages their entire life cycle.
L
G
E is not done by developers, it is called Inversion of Control.
Because the controlling of Java objects
A N
R N I
7
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
Spring InversionW
of Control
I (IoC)
T S
I
E
L
G
E
A N
R N I
8
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
W Injection (DI)
Spring Dependency
T I S
I
What is Dependency Injection?: Dependency Injection is the primary design pattern and
E
functionality provided by Spring IoC to implement Inversion of Control. Every Java-based
application has objects that collaborate and depend on each other (e.g., a Student class depends on
an Institute class).
The Problem it Solves: When writing complex applications, classes should be as independent as
possible to increase reusability and testability. DI acts as the "wiring" that glues these classes
together while simultaneously keeping them independent. The object does not look up its
L
G
dependencies and does not know theE location of the dependencies;
N everything is injected by the
A
Spring Framework. R N I
9
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
W Injection (DI)
Spring Dependency
T I S
Types of Dependency Injection: I
E
Constructor-Based DI: This is accomplished when the Spring container invokes a class
constructor with a number of arguments, each representing a dependency on another class.
Rule of thumb: Use constructor arguments for mandatory dependencies to ensure the object is
fully initialized upon creation.
Setter-Based DI: This is accomplished by the container calling setter methods on your beans
after invoking a no-argument constructor to instantiate the bean. Rule of thumb: Use setter
L
G
E allowing flexibility to change them later.
injection for optional dependencies,
A NI
R N
Field Injection (Auto-wiring): Dependencies are injected directly into the fields/attributes using
annotations like @Autowired, without needing explicit constructors or setters.
10
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
W I
T Programming
Aspect-Oriented
I S (AOP)
Theory: While the key unit of modularity in Object-Oriented Programming (OOP) is the Class, the
E
key unit of modularity in AOP is the Aspect.
Cross-Cutting Concerns: Applications have secondary functionalities (like Logging, Security,
and Transaction Management) that affect the whole application and span multiple modules.
AOP allows you to separate (decouple) these "cross-cutting concerns" from the core business
logic, preventing repetitive, cluttered code.
G
E
A N
R N I
11
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
W
Aspect-Oriented Programming
T
(AOP)
I S
Key AOP Terminologies: I
E
Aspect: The class which implements the cross-cutting concern (e.g., an authentication module).
Join Point: A specific point during the program's execution, such as the execution of a specific
method, where an aspect can be plugged in.
Advice: The actual action or code executed by an aspect at a particular Join Point (@Before,
@After, @Around).
Pointcut: An expression that strictly defines which Join Points the Advice should be applied to.
L
G
Weaving: The process of linkingEaspects with target objects
N to create the final advised object.
A
R N I
12
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
BeanW
Scopes
T I S
I form the backbone of your application and that are
What is a Bean? In Spring, the objects that
E
instantiated, assembled, and managed by the Spring IoC container are called Beans.
Bean Scopes: The scope defines the lifecycle and visibility of a bean. There are 6 types:
Singleton (Default): Only one single instance of that bean will be created per Spring container.
The same cached object is shared for each request.
Prototype: A completely new instance will be created every single time a request is made for
that bean.
L
G
E
Request (Web-aware): A new instance N HTTP request.
is created for every
A I
R N
Session (Web-aware): A single bean is tied to the lifecycle of an HTTP Session.
Global-Session / Application (Web-aware): Scopes a bean definition to the lifecycle of a
ServletContext.
WebSocket (Web-aware): Scoped to the lifecycle of a two-way WebSocket session. 13
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
Auto Wiring
T W I
I dependenciesSautomatically. The Spring container
Theory: Autowiring is a feature that injects
automatically detects the dependencies and the relationship between the beans, eliminating the need
E
for explicit manual bean wiring.
Implementation: We enable this by using the @Autowired annotation on a field, constructor, or setter.
Modes of Autowiring:
no : No autowiring is applied. Dependencies must be configured manually.
byName: ADependency is injected based on the name of the bean. The property name must match
G
the bean ID. E
N bean. If multiple beans of the same type
byType: Dependency is injected basedAon the type ofI the
R N
exist, it may cause ambiguity.
constructor: Dependencies are injected through the constructor. Useful for mandatory
dependencies.
Autodetect: Spring automatically decides whether to use constructor or byType autowiring 14
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
W in Spring
Annotations
T I S
I
Theory: Annotations are a form of metadata that provides supplemental information about a
E
program to the compiler. They always start with the @ symbol.
Crucial Spring Annotations:
@Component : Tells Spring to automatically detect the class and register it as a Bean.
@Service: Denotes classes that hold core business logic.
@Repository: Denotes Data Access Objects (DAOs) interacting directly with the database.
@RestController: Marks a class responsible for handling HTTP REST web requests.
L
G
E
Uses of Annotations:
A I N
R N
Compiler instructions - Java provides the 3 in built annotations which are used to give certain
instructions to the compiler. Java in built annotation are @Deprecated, @Override &
@SuppressWarnings.
15
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
T W inISpring
Annotations S
I
Build-time instructions - Java annotations can be used for build time or compile time
E
instructions. These instructions can be used by the build tools for generating source code,
compiling the source, generating XML files, packaging the compiled code and files into a JAR
file etc.
Runtime instructions - Normally, Java annotations are not present in your Java code after
compilation. However, we can define our own annotations that can be available at runtime.
G
E using Java Reflection.
These annotations can be accessed
A N
R N I
16
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
Spring Bean LifeW
Cycle & Callbacks
T I S
I to when & how the bean is instantiated, what action it
Lifecycle Flow: The bean life cycle refers
E
performs, and how it dies.
Life Cycle Callbacks: Spring allows developers to execute custom code during the initialization
and destruction phases:
Using the @PostConstruct annotation to run a method immediately after dependency
injection.
Using the @PreDestroy annotation to run a cleanup method just before the bean is removed
L
G
E
from the container.
A I N
R N
Note: We can choose a custom method name instead of init() and destroy(). Here, we will use init()
method to execute all its code as the spring container starts up and the bean is instantiated, and
destroy() method to execute all its code on closing the container.
17
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
E
L
G
E
A N
R N I
18
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
Spring Bean LifeW
Cycle & Callbacks
T I S
Lifecycle Working: I
E
The Spring Bean Lifecycle includes phases of initialization and destruction, along with the use
of Bean Aware interfaces to interact with the container.
Initialization callback methods are executed after dependency injection is complete. These
methods are used to validate bean properties, perform custom setup, or wrap/modify the
original bean. After these callbacks, the bean becomes ready for use.
Destruction callback methods are executed when the IoC container is about to remove the
L
G
bean. Their purpose is to releaseEresources or perform
N any necessary cleanup operations.
A I
R N
If multiple initialization and destruction callback methods are defined in a bean, they are
executed in a specific predefined order.
19
OOPS WITH JAVA (BCS-403)
SPRING FRAMEWORK
T W I
Bean IConfigurationSStyles
B
XML-Based Configuration: The traditional approach where beans and dependencies are explicitly
E
declared in an XML file using <bean> tags.
Annotation-Based Configuration: Uses annotations like @Service, @Component, and @Autowired
directly within the Java code, drastically reducing XML configuration overhead.
Java-Based Configuration: A completely programmatic approach where beans are configured
using Java classes annotated with @Configuration and methods annotated with @Bean.
L
G
E
A N
R N I
20
OOPS WITH JAVA (BCS-403)
SPRING BOOT
IntroductionW
to Spring Boot
T I S
I
Theory: Spring Boot is an advanced, powerful framework built directly on top of the Spring
E
Framework. While the core Spring framework significantly simplifies Java EE development, it still
requires extensive and complex configuration (like XML files and server setups). Spring Boot
solves this by operating on the principle of "Convention over Configuration".
Key Advantages: It simplifies the process of developing, configuring, and deploying Spring-based
applications by providing Auto-configuration (minimizing manual setup), incorporating
Embedded Web Servers (like Apache Tomcat, meaning you don't need to deploy WAR files
L
G
E
manually), and offering production-ready
A N checks and metrics
features like health
R N I
21
OOPS WITH JAVA (BCS-403)
SPRING BOOT
Spring BootW
Build Systems
T I S
I
When developing enterprise applications, developers need tools to automatically manage external
E
dependencies (libraries), compile the code, and package the final application. Spring Boot primarily
supports two powerful build automation systems:
A. Maven
Theory: Maven is a widely-used build automation tool primarily used for Java projects. It relies on
an XML file called [Link] (Project Object Model) to manage all project configurations.
Mechanism: If your project needs the Spring Web module or a MySQL driver, you simply declare
L
G
them inside the <dependencies> tagEin the [Link] file.N
Maven automatically downloads these
A
libraries from the internet. R N I
Build Lifecycle: It follows a strict, predefined set of lifecycle phases (clean, compile, test, package).
It is highly preferred by beginners and industry professionals for its simplicity and massive
community support. 22
OOPS WITH JAVA (BCS-403)
SPRING BOOT
Spring BootW
Build Systems
T I S
B. Gradle I
E
Theory: Gradle is a modern, faster alternative to Maven that offers much greater flexibility.
Instead of using verbose XML, Gradle uses a Groovy-based or Kotlin-based Domain Specific
Language (DSL).
Mechanism: Project configurations and dependencies are maintained in a file named [Link].
It uses a more concise syntax (e.g., implementation '[Link]:spring-boot-
starter-web').
L
G
E around specific tasks, offering faster build times making
Task-Based: Gradle builds are organized
A N I
R N
it an excellent choice for massive, complex projects (and is the default for Android development).
23
OOPS WITH JAVA (BCS-403)
SPRING BOOT
Spring BootW
Code Structure
T I S
I
To promote clean code organization, maintainability, and scalability, Spring Boot enforces a standardized directory
E
structure. Understanding this is crucial for placing components correctly:
src/main/java: This directory contains the entire core Java source code of your application, logically separated
into sub-packages:
controller/: Contains classes annotated with @RestController that handle incoming HTTP web requests.
service/: Contains classes annotated with @Service that encapsulate the core business logic of the
application.
G
E with @Repository responsible for managing database interactions
repository/: Contains interfaces annotated
A N
R N I
(data access logic).
model/ or entity/: Contains the domain classes (annotated with @Entity) that represent the actual tables in
the relational database.
[Link]: The starting point of the application containing the @SpringBootApplication
annotation and the standard public static void main(String[] args) method. 24
OOPS WITH JAVA (BCS-403)
SPRING BOOT
Spring BootW
Code Structure
T I S
I resources required by the application:
src/main/resources: Contains all non-Java
E
static/: Stores static frontend assets like HTML, CSS files, JavaScript, and images.
templates/: Stores server-side dynamic template files (like Thymeleaf) used to generate dynamic web
pages.
[Link]/: A vital configuration file used to define global application settings like server
ports, logging levels, and database connection URLs (using simple key-value pairs instead of
XML).
L
G
E
A I N
R N
src/test/java: Contains all the unit and integration testing code.
25
OOPS WITH JAVA (BCS-403)
SPRING BOOT
W Runners
Spring Boot
T I S
I
Theory: Runners are special functional interfaces provided by Spring Boot that allow developers to
E
execute specific blocks of code immediately after the Spring Boot application starts up.
CommandLineRunner: This interface provides a run(String... args) method. It gives developers access to
the application's command-line arguments as a raw, basic array of Strings.
ApplicationRunner: Similar to CommandLineRunner, but it provides a more advanced and structured
object-oriented approach. It uses the run(ApplicationArguments args) method. It parses the command-
line arguments, making it incredibly easy to extract specific key-value options (e.g., extracting "admin"
L
G
E
from --username=admin).
A N
R N I
26
OOPS WITH JAVA (BCS-403)
SPRING BOOT
Logger inWSpring Boot
T I S
I of recording events, operations, and errors into a console or
Theory: Logging is the automated process
E
a file while an application is running. It is indispensable for monitoring application health, tracing user
actions, and debugging system crashes.
Standard Log Levels (In order of increasing severity):
TRACE: The most fine-grained, detailed information (lowest severity).
DEBUG: Information useful for developers to debug the application.
INFO: General operational messages highlighting the progress of the application.
L
G
E
WARN: Indicates a potentially harmful N that isn't a strict error yet.
or risky situation
A I
R N
ERROR: Indicates a serious failure preventing normal execution (highest severity).
Implementation: Developers create a logger instance using [Link]([Link]). The
threshold for showing logs is configured in the [Link] file using [Link]=info.
27
OOPS WITH JAVA (BCS-403)
SPRING BOOT
W Web Services
Building RESTful
T I S
Deep Theory & Definition: REST stands for IREpresentational State Transfer. It is an architectural style
E
(not a protocol) developed by Roy Thomas Fielding, who also helped develop the HTTP protocol.
Core Concept: The main goal of RESTful web services is to make web services more effective by
defining services using the standard concepts already present in HTTP.
The "Resource" Abstraction: The key abstraction in REST is a Resource (e.g., a 'Student' or 'Employee'
record). A resource can be anything and is uniquely accessed and identified through a Uniform
Resource Identifier (URI).
L
G
E
Representations: Resources can be represented
A I N
in various formats like XML, HTML, and JSON, with
R N
JSON (JavaScript Object Notation) being the most popular format for REST.
28
OOPS WITH JAVA (BCS-403)
SPRING BOOT
W Web Services
Building RESTful
T I S
I For an API to be considered truly RESTful, it must adhere
RESTful Service Constraints & Characteristics:
E
to several strict constraints.
Client-Server Architecture: The client (consumer) and server (producer) are completely separate
concerns. The client is not concerned with data storage, improving scalability.
Statelessness: Every request from a client to the server must contain all the necessary information to
fulfill that request. The server does not store any client context between requests.
Cacheability: Responses from the server must explicitly label themselves as cacheable or non-cacheable.
L
G
E
This drastically improves performance.
A I N
R N
Uniform Interface: REST APIs use a standard, uniform interface to access resources (using standard
HTTP methods to perform CRUD operations).
Layered System: The architecture can be layered, allowing proxies, gateways, or load balancers to be
inserted between clients and servers without the client knowing. 29
OOPS WITH JAVA (BCS-403)
SPRING BOOT
W
Advantages of RESTful
T
Web Services
I S
Advantages of RESTful Web Services: I
E
Platform-Independent: They can be written in any programming language (Java, Python, C++) and
executed on any platform.
Language Neutral & Reusable: REST APIs are reusable and language-neutral.
Multiple Data Formats: Unlike older technologies like SOAP, REST provides flexibility by supporting
JSON, text, HTML, and XML.
Fast & Scalable: It is significantly faster than SOAP because there is no strict, heavy specification.
L
G
E
A N
R N I
30
OOPS WITH JAVA (BCS-403)
SPRING BOOT
GETWMethod
I S
T
I
The GET method is the most fundamental HTTP method used to request and retrieve data from a specified
E
resource or URL. When using GET, the client simply requests a representation of a resource from the
server.
Idempotence and Safety: It is strictly designed to be safe and idempotent. This means it only reads data;
it does not modify or change the state of the resource on the server. Making multiple identical GET
requests will have the exact same effect as making a single request.
Common Usage: Used for fetching a webpage, getting specific user details, or retrieving a list of items
L
G
E with the SELECT command in databases.
from a database. It is directly associated
A I N
R N
Request Parameters: Any data sent with a GET request is typically embedded directly in the URL path
(as a Path Variable) or appended as a Query Parameter.
31
OOPS WITH JAVA (BCS-403)
SPRING BOOT
WMethod
POST
T I S
The POST method is used to submit data to Ibe processed by the server, which frequently results in the
E
creation of a brand new resource on the server.
Non-Idempotent: Unlike GET, the POST method is strictly non-idempotent. This means that making
multiple identical POST requests will have different effects each time (e.g., submitting the exact same
user registration request twice will result in two duplicate records being created in the database).
Common Usage: Commonly used for submitting forms, uploading files, or creating new records in a
database. It is associated with the INSERT command.
L
G
E via POST does not travel in the URL. Instead, it is packaged
Request Parameters: The data submitted
A NI
R N
securely inside the Request Body (usually in JSON format). This keeps the data hidden from the URL
string.
32
OOPS WITH JAVA (BCS-403)
SPRING BOOT
PUTWMethod
T I S
I or entirely replace an existing resource on the server with
The PUT method is used specifically to update
E
new data provided by the client.
Idempotent: The PUT method is idempotent. Even if you execute the exact same PUT request 100
times, the final state of the resource on the server remains identical to executing it just once (e.g.,
updating a user's age to 25 multiple times leaves the age at 25).
Common Usage: Used when you have the complete updated representation of a resource and want to
replace the current version residing on the server. It maps to the UPDATE command in databases.
L
G
E using the PUT method, it is highly important to handle
Data Consistency & Concurrency: When
A N I
R N
concurrency issues. If multiple clients attempt to update the same resource simultaneously, data
conflicts can occur. To resolve this, developers use mechanisms like optimistic locking or versioning to
ensure that an update does not blindly overwrite another concurrent modification.
33
OOPS WITH JAVA (BCS-403)
SPRING BOOT
W Method
DELETE
T I S
I for the permanent removal or deletion of a specified resource
The DELETE method is specifically designed
E
from the server.
Idempotent: The DELETE operation is considered idempotent. Deleting a resource that has already
been deleted has no further effect on the server's state.
Common Usage: Removing a user account, deleting a post, or dropping a specific record from the
database. It is associated with the DELETE command in databases.
Error Handling: WhWhen implementing a DELETE API, you must provide proper error handling and
L
G
E
feedback to the client.
A I N
R N
If the deletion is successful, the server typically returns a 204 NO CONTENT or 200 OK status.
If the resource does not exist (or was already deleted), the server should gracefully return a 404 NOT
FOUND rather than crashing.
34
OOPS WITH JAVA (BCS-403)
SPRING BOOT
E
Method
Used to request and retrieve data from a Safe & Idempotent: It only reads data; it does
GET
specified resource (e.g., getting user details). not modify the resource on the server.
G
E
A I N Idempotent: Making multiple identical PUT
PUT
R existing
Used to update or replace an entire N requests will result in the same final updated
resource with new data at a specified URI.
state.
SPRING BOOT
Spring Boot Core Annotations for REST APIs
W
Spring Boot uses specific annotations to build web servicesI effortlessly,
T
I S removing the need for manual
configuration:
E
@RestController vs @Controller:
@Controller: A traditional Spring MVC annotation used to mark a class as a web controller. It
requires the @ResponseBody annotation on every handler method to output data directly;
otherwise, it attempts to return a View (like an HTML page)..
@RestController: Introduced in Spring 4.0, it is a specialized combination of @Controller and
L
G
E to create RESTful web services. It automatically maps the
@ResponseBody. It is used specifically
request data and directly serializes theAoutput into I N
JSON or XML format without looking for a
R N
View..
@RequestMapping:
This is a highly versatile annotation used to map incoming HTTP requests to specific handler
36
methods or controller classes.
OOPS WITH JAVA (BCS-403)
SPRING BOOT
Spring Boot Core Annotations for REST APIs
W
Class-level: Defines a base URL for all methods inI the
T
I S class (e.g., @RequestMapping("/users")).
Method-level: Specializations like @GetMapping, @PostMapping, @PutMapping, and
E
@DeleteMapping are used on individual methods to handle specific HTTP verb requests.
@RequestBody
Data sent to the server can be in JSON, XML, or HTTP Forms.
The @RequestBody annotation is responsible for retrieving the incoming HTTP request body and
automatically deserializing (converting) it into a Java POJO (Plain Old Java Object). It relies on a
L
G
HttpMessageConverter to resolve E
the method argument based on the request's Content-Type.
A N
R N I
37
OOPS WITH JAVA (BCS-403)
SPRING BOOT
@PathVariable vs @RequestParam
T W I S
I
Feature @PathVariable @RequestParam
E
Extracts dynamic values directly embedded in Extracts values from the Query Parameters
Usage
the URL path. (after the ? in the URL)
G
Example
E
getUser(@PathVariable String id) getAcc(@RequestParam String type)
A N
R N I
The value is always required; if missing, the URL Can be optional; allows binding to a default
Requirement
pattern fails. value if not present
Must be placed directly on the method Can be placed anywhere in the method
Position
parameter parameter list 38
OOPS WITH JAVA (BCS-403)
SPRING BOOT
Build Web Applications (Spring MVC)
T W I program
What is a Web Application - A web application is a software
I S accessed through a web browser
over the internet. While static websites can be built using plain HTML and CSS, dynamic web
E
applications require server-side technologies (like Java) to process logic, interact with databases, and
render dynamic content.
Building with Spring Boot MVC Architecture: Spring Boot dramatically simplifies web development by
utilizing the Model-View-Controller (MVC) architecture:
Model: Represents the data structure, database interaction (Entities and Repositories), and the core
L
G
E
business logic. It handles data manipulation.
View: The user interface (what the user sees). I N
A In Spring Boot, instead of writing raw Servlets or JSPs,
R N
developers use modern server-side template engines like Thymeleaf. Thymeleaf allows dynamic server
data (from the Model) to be smoothly injected into standard HTML files.
Controller: The intermediate hub. It receives HTTP requests from the User (via the View),
39
communicates with the Model to process data, and then returns the appropriately updated View.
OOPS WITH JAVA (BCS-403)
SPRING BOOT
W IWorkflow
The Development
T
I S
Spring Initializr ([Link]) - Developers use this web-based tool to rapidly generate the standard
E
directory structure of the application.
Dependencies: Crucial dependencies like Spring Web (which includes RESTful capabilities and the
embedded Apache Tomcat server) and Thymeleaf (for dynamic HTML rendering) are selected here.
Packaging: The project is generated (usually managed by Maven or Gradle), coded in an IDE (like
Eclipse or VS Code), and packaged into an executable JAR or WAR file that runs seamlessly using the
embedded server.
L
G
E
A N
R N I
40
41