0% found this document useful (0 votes)
68 views7 pages

What Is A Framework

The document discusses the key differences between libraries and frameworks. Libraries are collections of pre-written code that perform specific tasks, while frameworks provide reusable components and define application structure and flow. Specifically, frameworks invert control by having the framework call user-provided code rather than the other way around as with libraries. The document also provides an overview of the popular Spring framework, describing its lightweight and flexible design that improves coding efficiency.

Uploaded by

shyam
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)
68 views7 pages

What Is A Framework

The document discusses the key differences between libraries and frameworks. Libraries are collections of pre-written code that perform specific tasks, while frameworks provide reusable components and define application structure and flow. Specifically, frameworks invert control by having the framework call user-provided code rather than the other way around as with libraries. The document also provides an overview of the popular Spring framework, describing its lightweight and flexible design that improves coding efficiency.

Uploaded by

shyam
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
You are on page 1/ 7

What Is a Framework?

A framework is like the foundation upon which developers build applications for
specific platforms. It includes reusable pieces of code written to perform common
tasks and uses code provided by a developer for custom functionality. The
framework may include defined and undefined objects and functions that
developers can use to create applications

What is a Library?

A library is a collection of prewritten code that can be used to simplify tasks. The
term library simply refers to a collection of code that is reused repeatedly. It is
essentially a set of pre-defined functions and classes that programmers can use
to simplify their work and speed up the development process. So, developers do
not have to write code to accomplish specific functionality

Parameters Library Framework


Libraries provide developers with
Framework, on the other hand, is like the
predefined functions and classes
Definition foundation upon which developers build
to make their work easier and
applications for specific platforms. 
boost the development process.
By using a library, you can control In contrast, when you use a framework,
Inversion of
the flow of the application and call the control is inverted, i.e., the framework
Control
the library.  controls the flow and calls your code.
Generally, libraries are a
collection of helper modules, Frameworks consist of a lot of APIs,
Collection objects, classes, functions, compilers, toolsets, support programs,
message templates, pre-written libraries, etc.
code, etc.
Code Codes in libraries are geared Despite the fact that frameworks generate
Modification toward a particular program or to new codes for developers. These codes
solve a specific development cannot be altered or modified later. Unlike
problem. Therefore, developers libraries, frameworks do not allow users to
must modify library code to meet modify their pre-written codes, so you
their needs. don’t have to worry about deleting or
changing them.
It is possible to call a library out of On the other hand, you can only call and
Scope context. You may use the library use what belongs to a Framework within
wherever you see fit in your code. the same Framework. 
Using them, you can build and deploy
applications in a standard way as the
In the program linking and binding
framework already provides code to
Function process, they play an important
perform common tasks and uses code
role.
provided by a developer for custom
functionality.
Having a library means
understanding the functionality of Frameworks, on the other hand, embody
each method, and it isn’t easy to the basic flow, and since plugins need to
Complexity
create complex interactions since be added to code, it is easier to do the
you need to call many methods to right modification.
get the desired results. 
Frameworks provide general functionality.
Generally, libraries aren’t
Because of this, they are built to be
designed for extensibility; they are
Extensibility extensible, which allows developers to
designed to accomplish a specific
incorporate app-specific features without
purpose.
modifying the framework’s source code.
It is easy to replace a library with
Frameworks are difficult to replace. If, for
another library. For instance, if
instance, you were using AngularJS to
you do not like the jQuery date
Replaceable build your product, you cannot simply
picker library, you can use
swap it out for another framework. It
another date picker like a
requires rewriting the entire codebase.
bootstrap date picker or pick date.
Less code is required to build
Developing a framework requires a lot of
libraries, which leads to faster
Performance coding, which increases loading times and
loading times and better
decreases performance.
performance.
The purpose of libraries is to
Frameworks can be used for performing a
perform a defined and specific
wide range of tasks. Among these are
Usage task. Eg: Image manipulation,
Web application systems, plug-in
network protocols, math
managers, GUI systems, and so on.
operations, etc.
Spring Framework
Spring is a lightweight framework. It can be thought of as a framework of
frameworks because it provides support to various frameworks such as Struts

, Hibernate

, Tapestry, EJB

, JSF

The Spring framework comprises several modules such as IOC, AOP, DAO, Context, ORM, WEB
MVC etc

Spring Framework
The Spring Framework (Spring) is an open-source application framework that
provides infrastructure support for developing Java applications. One of the
most popular Java Enterprise Edition (Java EE) frameworks, Spring helps
developers create high performing applications using plain old
Java objects (POJOs).  

A framework is a large body of predefined code to which developers can add


code to solve a problem in a specific domain. There are many popular Java
frameworks including Java Server Faces (JSF), Maven, Hibernate, Struts, and
Spring.

Released in June 2003 by Rod Johnson under the Apache 2.0 license, the
Spring Framework is hosted by SourceForge.     

Why Spring?
Java programs are complex and feature many heavyweight components.
Heavyweight means the components are dependent on the underlying
operating system (OS) for their appearance and properties.
Spring is considered to be a secure, low-cost and flexible framework. Spring
improves coding efficiency and reduces overall application development time
because it is lightweight -- efficient at utilizing system resources -- and has a
lot of support.

Spring removes tedious configuration work so that developers can focus on


writing business logic. Spring handles the infrastructure so developers can
focus on the application.  

How Spring works


A web application (layered architecture) commonly includes three layers:

1. Presentation/view layer (UI) - This is the outermost layer which handles the
presentation of content and interaction with the user.

2. Business logic layer - The central layer that deals with the logic of a
program.

3. Data access layer - The deep layer that deals with data retrieval from
sources.

Each layer is dependent on the other for an application to work. In other


words, the presentation layer talks to the business logic layer, which talks
to the data access layer. Dependency is what each layer needs to perform its
function. A typical application has thousands of classes and many
dependencies.

Without a Spring Framework, application code tends to be tightly coupled


(interdependent), which is not considered good coding practice. Loose
coupling is ideal because loosely coupled components are independent,
meaning changes in one will not affect the operation of others.

Spring’s core logic is dependency injection. Dependency injection is a


programming pattern that allows developers to build more decoupled
architectures. Dependency injection means that Spring understands the
different Java annotations that a developer puts on top of classes. Spring
knows that the developer wants to create an instance of a class and that
Spring should manage it. Spring also understands the dependency and
makes sure that all instances created have properly populated dependencies.

For the Spring Framework to instantiate objects and populate the


dependencies, a programmer simply tells Spring which objects to manage and
what the dependencies are for each class. A developer does so by using
annotations like:

@component - Lets Spring know which classes to manage (create). Marks the
beans (objects) as managed components, which means that Spring will
autodetect these classes for dependency injection.

@autowired - Tells Spring how to handle the instantiation of the class (so it


starts looking for that dependency among components/classes to find a
match). This spares developers from wiring with code and allows Spring to
find what needs to be injected where.

Important terms
Autowiring - The process by which Spring identifies dependencies and
matches and populates them.

Bean - A Spring bean is an object that is instantiated, created, and managed


by the IoC container. Beans are the backbone of an application.

Dependency injection - A programming design pattern that makes code


loosely coupled, meaning that any change in the application of one, will not
affect the other.
Inversion of control (IoC) - Taking control away from the class and giving it to
the Spring Framework.

Inversion of control container - This is the core of the Spring Framework


where objects are created, wired together, configured, and managed
throughout their life cycle.

If we were to apply the inversion of control pattern to the above example, the
developer could not use the new keyword and call the constructor of the Question
class.

Instead, when needed, a magical and mysterious black box -- often referred to as the
IoC container -- will provide instances of the Question class.

Question q1 =
MysteriousBlackBox.getInstance(Question.class);

Inversion of control in Spring

Inversion of control compared to typical development


practices.

The use of the MysteriousBlackBox class in the previous line of code may seem silly,
but it's actually not.

If a developer introduces this inversion of control example with the Spring


framework, the actual code would look as follows:
Question q1 =
context.getBean(com.mcnz.ioc.explained.Question.class);

JPA :-> current version 2.2


1) JPA stands for Java Persistence API
2) JPA is just a specification that facilitates object-relational mapping to
manage relational data in Java applications. It provides a platform to
work directly with objects instead of using SQL statements and
hibernate is a kind of implementation so that we can map our class to
table by annotations or by XML
3) if you want to use JPA then you need to add spring-boot-starter-
data-jpa dependency
4) we need data base layer to talk with database so that we needs to
create a interface(you can give any name here we use UserRepository
for standard) that extends CRUDRepository or JPARepository to get
some inbuild methods from spring boot

You might also like