Nearby lessons
1 of 35Spring - Introduction
- Understand Spring - Introduction
- See working code examples
- Learn from common mistakes and Q&A
Learn Spring - Introduction step by step — simple explanations, complete programs with their output, common beginner mistakes, and exam-style MCQs.
System Arch.
To define level or height of the enterprise applications we have to use System Arch.
EX:
1-Tier Arch.
2-Tier Arch.
3-Tier Arch.
n-Tier Arch.
1-Tier Arch.
- In 1-Tier Arch, we have to prepare and execute the complete enterprise application with
in a single machine.
- In 1-Tier Arch, all the enterprise application layers like presentation Layer, Business
Layer and Persistence layer must be provided in a single machine, no separation between
all the layers, it will provide tightly coupled design in enterprise applications, it is not
suggestible.
- In 1-Tier arch, the complete enterprise application must be executed in a single
machine, where single machine resources may not be sufficient to manage the complete
enterprise application, it may affect the application performance.
- 1-Tier Arch is suggestible for Standalone Applications, not for enterprise Applications or
distributed Applications.
- in 1-Tier Arch, Sharability and Reusability are very less , it may increase application
length.
- In 1-Tier Arch, multi user environment is not existed, only Single user environment is
existed.
2-Tier Arch:
- IN 2-Tier Arch, we have to distribute the complete enterprise application over two
machines.
- In 2-Tier Arch, Tier-1 machine is able to manage presentation logic and Business Logic,
Tier-2 machine is able to manage Persistence Logic.
- In 2-Tier Arch, we are able to get loosely coupled design when compared with 1-Tier
Arch, because, Persistence layer is separated from Presentation layer and Business Layer.
System Arch.
sharability and Reusability are increased.
- 2-Tier Arch will provide multi user environment to access application.
Note: If want to use 2-Tier arch for web applications then we have use Tier-1 is for client , it
has to manage presentation layer and Tier-2 is for Server , it has to manage Business Layer
and Persistence Layer.
- 3-Tier Arch:
--> This arch will propose to use three machines in order to execute the complete
enterprise application.
--> In 3-Tier Arch, we will provide Presentation Layer at Tier-1 Machine, Business Layer at
Tier-2 machine and Persistence layer at Tier-3 machine.
--> 3-Tier arch will provide more more loosely coupled design to design applications. -
-> 3-Tier Arch will provide Multi User environment, it will improve sharability and
Reusability.
--> 3-Tier arch will improve application Server components sharability and database
components sharability.
Note: If we increase no of Tiers in applications then flexibility will be increased, but,
maintenance cost will be increased. In enterprise applications we have to increase no of
ties as per the purpose only, we must not increase no of tiers unnecessarily.
There are two types of Enterprise Applications.
1.web applications[Web Related Distributed Appl]
2.Distributed Applications[Remote based Distributed Appl].
Q)What are the differences between Web Applications and Distributed Applications?
Answer:
----
- Web Application is a Client-Server Application, where the complete application logic is
distributed over Server machine.
Distributed Application is a client-server Application, where the complete application logic
is distributed over Client machine and Server machine.
- To prepare web applications, we will use a set of technologies called as web
technologies.
EX: Servlets, JSPS,
To prepare Distributed Applications, we will use a set of technologies called as Distributed
technologies.
EX: Socket programming
RMI
CORBA
EJBs
Web Services
- The main intention of Web applications is to generate dynamic response from server.
The main intention of Distributed Applications is to establish Communication between local
machine and remote machine in order to get Remote Services from Remote machine.
- Web applications are executed by both web servers and application servers.
Distributed applications are executed by only application servers.
- Web application is the collection of web components like servlets, jsps,... , which are
executed by web containers.
Distributed Application is the Collection of distributed components like EJBs, which are
executed by EJB Container.
- In web applications, Client is fixed, that is, Browser.
In Distributed Applications, Client is not fixed, it may be a normal java program with main()
method, it may be a GUI Application, it may be a Servlet program, it may be a JSP
program,.....
To prepare web applications, SUN Microsystems has provided the following Modeled Arch.
1 .Model-I Arch.
- Model-II Arch.
- Model-I Arch.
In Model-I Web Application Arch, we will use a JSP page as controller as well as
Presentation part and a Java Bean component is acting as Model Component.
In Model-I web application Arch, a JSP page is acting as Controller to controll the complete
web application, so that, Model-I Web application Arch is also called as "Page-Centric
Arch".
In Model-I web application Arch, a JSP page is taking responsibility to take requests from
client, so that, Model-I web application Arch is also called as "JSP Front".
IN Model-I web application Arch, we will use JSP pages as Controller and for presentation,
there is no clear cut seperation between Controller logic and presentation logic, it will provide
tightly coupled design in web applications, it is not suggestible in web applications.
In Model-I web applicatio Arch., a JSP page is acting controller, to perform controller
functionalities the existed JSP features are not sufficient, where it is required to write java
code inside JSP pages, it is against to JSP rules and regulations.
In Model-I web applicatio Arch., a JSP page is acting controller, to perform controller functionalities the
existed JSP features are not sufficient, where it is required to write java code inside JSP pages, it is against
to JSP rules and regulations.
Model-II Arch :
In Model-II web application Arch, we will use a Servlet as controller, a set of JSP pages as
View part and Java bean, DAO, JDBC,... as used as Model Components.
In Model-II Arch, a servlet is acting as controller to control the complete web applications,
so that, Model-II web Arch is called as "Servlet-Centric Arch".
In Model-II Arch, a servlet is taking responsibility to take all the requests from Client , so
that, Model-II Arch is also be called as "Servlet Front Arch".
Note: Model-II Arch is an implantation of MVC Arch, on the basis of Model-II Arch only the
web frameworks like Struts, JSF,... are designed.
Rules and regulations of MVC Arch:
- MVC is a design pattern, it will define a standard template to prepare web applications.
- MVC will define standard flow of execution to prepare web applications.
- In MVC based web applications, we must use a Servlet as controller and a set of JSP
pages as view part.
- In MVC based web applications, we must provide single controller per application.
- In MVC based web applications, Controller component must take all the requests which
are coming from clients and View part must take the responsibility to generate response to
client.
- IN MVC based web applications, both controller and view part are not responsibile to
interact with database, they have to interact with database through Model component.
- In MVC based web applications, Controller is able to set data to model component, not
to get data from model component and View part is able to get data from model
component , not to set data to Model component.
- IN MVC based web applications, we can provide any no of pages as view part, but we
must provide all the pages as Java code less.
- IN MVC based web applications, we can provide no of pages as view part, where we
must not provide page-to-page communication directly, where we have to provide page-
controller-page communication.
In general, from application to application, some components like ControllerServlet and
some generic Services like Internationalization, Security, Data Validations,.... are very mush
common, these common components may provide 70% implementation in the complete
enterprise application.
In the above context, If any third party organization is providing the common 70%
implementation then developers may take responsibility to provide the remaining 30% of
the implementation.
In the above situation, some third party organizations like Apache Software
Foundations, Soft Tree, .... has provided the common 70% of the implementation in the
form of their own products called as "Frameworks".
Framework is a pre fabricated Software components that programmer can reuse, share and
customize inorder to simplify enterprise application development.
Framework is a semi implemented application, it will provide very good environment to
prepare enterprise applications as per developers convenience.
Framework is the Collection of Tools and APIs, it will provide very good environment
to prepare enterprise applications in simplified manner.
In enterprise application development, Frameworks wil provide the folowing
advantages.
- Frameworks will define standard template to design applications.
- Frameworks will define a fixed flow of execution between the components.
- Frameworks provide parallel development and modularization.
- Frameworks will provide all the commonly used generic services like I18N, Security,
Exception handling, Data validations,....
- Frameworks will reduce development time.
- Framewords will reduce application development cost.
- Frameworks will increase productivity.
.
There are two types of Frameworks .
- Web Frameworks
- Application Frameworks
- Web Frameworks
Web frameworks will provide environment to design and execute only web applications.
EX: Struts, JSF, Xwork2,
- Application Frameworks
Application Frameworks will provide very good environment to prepare all the types of
applications like Standalone Applications, Web Applications, Distributed Applications,.....
EX: Spring
Q)What are the differences between Struts, JSF and Spring?
Answer:
- Struts and JSF are web frameworks, which we will provide very good environment to
prepare and execute web applications only.
Spring Framework is an application Framework, it will provide very good environment to
prepare and execute all the types of applications like standalone applications, web
applications, distributed applications......
- Struts and JSF are designed on the basis of only MVC design pattern.
In Spring , only WEB Module is designed on the basis of MVC, SPriong is using no of other
design patterns like IOC[Dependency Injection], Locater design patterns, Creational Design
Patterns, Decorator Design pattern,.....
- Struts is controller layered framework, it has very good focus on controller layer in
MVC.
JSF is is view layered Framework, it has very good focus on View layer in
MVC. Spring Framework has provided very good support for all Controller Layer, Model
Layer and View Layer.
- In Enterprise Application Development, Struts and JSF are used to prepare mainly
Presentation layer.
In Enterprise Application Development, Spring Framework will cover all the
layers like Presentation Layer, Business Layer, Persistence Layer.
- Struts and JSF are provide support for the basic services like I18N, Validations,
Exception Handling,..., but, Struts and JSF are not providing support for the
middleware services like JAAS, JNDI, JTA, Java Mail, JMS,......
Spring Framework is providing very good support for all basic services like I18N,
Validations, Exception Handling ... and the Middleware services like JAAS, JNDI, JTA, Java
Mail, JMS, JCA......
- Struts and JSF are not modularized Frameworks, to prepare any application in Struts
and JSF we have to load all the jar files irrespective of their utilization.
Spring framework is modularized framework, to prepare applications in spring framework
we will load only the module respective jar files, not required to load other modules
respective jar files unnecessarily.
- Struts and JSF are more API dependent; they are not having POJO/POJI kind of
implementations.
Spring is less API dependent, it has POJO/POJI kind of implementations.
- Due to the above reasons, debugging and testing are difficult in Struts and JSf.
Testing and Debugging are very simple in Spring framework.
- Struts and JSF are heavy weight Frameworks.
Spring is light weight Framework.
- Struts and JSF are not providing any predefined support to integrate the other
applications like JDBC, EJBS, Hibernate, JPA, RMI,....
Spring has provided very good predefined support to integrate the other
applications like JDBC, EJBS, Hibernate, JPA, RMI,....
- Struts and JSF are allowing the basic view related technologies like Html, JSp, ..... to
prepare view part.
Spring Framework is allowing the most advanced view related tech like Velocity, Free
marker,... along with basic view related tech in order to prepare view part.
- Struts and JSF are not having Aspect Oriented Programming to prepare applications.
Spring has provided very good Aspect Oriented Programming to prepare Applications.
Spring History
1.Home: Interface1
2.Author: Mr. Rod Janson
3.Objective: To simplify and Accelerate the complete Enterprise Applications.
4.Type: Open Source Software.
5.Type of Framework: Application Framework.
6.Initial Version: Spring1.0[Oct, 2004]
7.Used Version: Spring3.x[Dec, 2014]
8.Latest Version: Spring4.3.8[April, 2017]
9.Website: http://spring.io
10.Designed on: Java[JAVA SE API, Servlets API]
11.Compatibility:Supported by All IDEs and all Servers
12:Designi Tool: STS[Spring tool Suit][Designed on the top of Eclipse]
- Key ideas of Spring - Introduction explained simply
- Ready-to-use code examples
- Exam-style questions at the end