2. 1. Framework
2. OOPS Concepts
3. Spring
4. JSP & Servlets
5. Loggers
6. ANT Tool
7. Web Services
Agenda
2
August 1, 2016
3. It is an essential supporting structure of a building,
vehicle,
enterprise a or object. In software, framework is used to
construct applications which basically are integrated
With each other
What is a Framework ?
A software framework is a re-usable
design for a software system.
9. • The Spring Framework is an open source application
framework and inversion of control container for
the Java platform.
• The framework's core features can be used by any Java
application
• Philosophy: “Lightweight Container” concept
Spring Overview
10. • Lightweight Frameworks simplify application development
• By removing re-occurring pattern code
• Productivity friendly
• Unit test friendly
• Very pluggable
• Usually open source
• Examples:
• Spring, Pico
• Hibernate, IBatis
What are Lightweight Frameworks?
11. Spring 3.0 MVC- Basic Architecture
Dispacth
erServlet
(Front controller)
HandlerMapping
(Map of URL and
controllers)
Controller
(Responsibl
e to handle
request)
View (JSP,
XML,
Velocity)
Model
(POJO
Beans)
Request
1
5
4
3
2
13. This framework has very loosely coupled components which are widely reusable
and are packaged separately.
Overview of the Spring Framework
14. The Spring Framework can be considered as a collection of frameworks-
in-the-framework:
1. Core - Inversion of Control (IoC) and Dependency Injection
2. AOP - Aspect-oriented programming
3. DAO - Data Access Object support, transaction management, JDBC-
abstraction
4. ORM - Object Relational Mapping technique for converting data b/w
incompatible type system in OOP language.
5. MVC - Model-View-Controller implementation for web-applications
6. Remote Access, Authentication and Authorization, Remote Management,
Messaging Framework, Web Services, Email, Testing, …
Modules of the Spring Framework
15. • Basic JavaBean pattern:
• include a “getter” and “setter” method for each field:
• Rather than locating needed resources, application components provide getter &
setter methods through which resources are passed in during initialization
• In Spring Framework, this pattern is used extensively, and initialization is usually
done through configuration file(web.xml) rather than application code
Bean
class MyBean {
private int counter;
public int getCounter()
{ return counter; }
public void setCounter(int counter)
{ this.counter = counter; }
}
16. • package player;
public class PersonBean implements java.io.Serializable {
private String name = null;
private boolean deceased = false;
public PersonBean() {
}
/* Getter for property */
public String getName() {
return name;
}
/**
* Setter for property */
public void setName(final String value) {
name = value;
}
/ * Getter for property "deceased"*/
public boolean isDeceased() {
return deceased;
}
/ * Setter for property */
public void setDeceased(final boolean value) {
deceased = value;
}
}
Example of BEAN Class
17. August 1, 2016
17
Bean
Autowiring feature of spring framework enables you to inject the object
dependency implicitly. It internally uses setter or constructor injection.
@Bean
@Bean is a method-level annotation and a direct analog of the
XML <bean/> element.
The annotation supports most of the attributes offered by <bean/> such as init-
method, destroy-method, autowiring.
@Configuration
public class AppConfig { @Bean publicTransferService transferService() { return new
TransferServiceImpl(); } }
The above is exactly equivalent to thefollowing appConfig.xml:
<beans><bean name="transferService" class="com.acme.TransferServiceImpl"/> </beans>
18. • Based on “Inversion of Control Containers and the Dependency Injection
pattern”
Spring Provides centralized, automated configuration, managing and wiring of
application Java objects.
• Container responsibilities:
1. creating objects,
2. configuring objects,
3. calling initialization methods
4. passing objects to registered callback objects
5. etc
• All together form the object lifecycle which is one of the most important
features
Dependency Injection -Inversion of
Control (IoC)
19. Dependency Injection-Container resolves (injects)
dependencies of components by setting implementation
object during runtime
Draw()
Triangle
During Implementation
Circle
20. • Beans define their dependencies through constructor arguments or properties
• Container resolves (injects) dependencies of components by setting
implementation object during the runtime
• BeanFactory interface – It is the core that
loads bean definitions and manages beans
• Most commonly used implementation
is the XmlBeanFactory class
• It allows you to express the objects that compose
application, and the interdependencies
between such objects, in terms of XML
• The XmlBeanFactory takes this XML
configuration metadata and uses it to create a fully configured system
Dependency Injection - IoC
21. • Spring address solutions to major J2EE problem areas:
• Web application development (MVC)
• Enterprise Java Beans (EJB, JNDI) Annotations+ POJO
• Database access (JDBC,ORM)
• Transaction management ( Hibernate, JDBC)
• Remote access (Web Services, RMI)
Spring Solutions
27. • log4j is a reliable, fast and flexible logging
framework (APIs) written in Java, which is
distributed under the Apache Software License.
• log4j has three main components:
1. loggers: Responsible for capturing logging
information.
2. appenders: Responsible for publishing logging
information to various preferred destinations.
3. layouts: Responsible for formatting logging
information in different styles.
August 1, 2016
27
Logging in Java
28. August 1, 2016
28
Logging Levels
Level Description
ALL All levels including custom levels.
DEBUG Designates fine-grained informational events that are most useful to debug
an application.
ERROR Designates error events that might still allow the application to continue
running.
FATAL Designates very severe error events that will presumably lead the
application to abort.
INFO Designates informational messages that highlight the progress of the
application at coarse-grained level.
OFF The highest possible rank and is intended to turn off logging.
TRACE Designates finer-grained informational events than the DEBUG.
WARN Designates potentially harmful situations.
30. • All the possible options are:
1. DateLayout
2. HTMLLayout
3. PatternLayout
4. SimpleLayout
5. XMLLayout
• Using HTMLLayout and XMLLayout, you can generate log in HTML and in
XML format as well.
August 1, 2016
30
Types of Layouts
31. • ANT stands for Another Neat Tool. It is a Java-based build tool from
Apache.
• Need for a Build Tool (DEV OPS)
• On an average, a developer spends a substantial amount of time
doing mundane tasks like build and deployment that include:
• Compiling the code
• Packaging the binaries
• Deploying the binaries to the test server Testing the changes
• Copying the code from one location to another
• To automate and simplify the above tasks, Apache Ant is useful. It is
an Operating System build and deployment tool that can be executed
from the command line.
August 1, 2016
31
ANT-Build Tool
32. August 1, 2016
32
What is the use of the build.xml file?
The build.xml file is an Ant script that is created by the Plug-in Development Environment (PDE) to
take your plug-in components and combine them into a deployable format.
This file compiles and archives your plug-in source code into a single JAR file.
The build.properties file controls what goes into your plug-in distribution.
The build.xml file can be created by using the context menu on plugin.xml and selecting PDE Tools >
Create Ant Build File.
Ant build files are low-level mechanisms to package up plug-ins. A much easier way to share and
deploy plug-ins is to create a feature for your plug-in and then an update site.
33. • The build path is used for building your application. It
contains all of your source files and all Java libraries
that are required to compile the application.
• The classpath is used for executing the application.
This includes all java classes and libraries that are
needed to run the java application. A Classpath is
mandatory, the default path is . which is used if the
java virtual machine can't find a user defined path.
August 1, 2016
33
Build path vs Class Path
34. JAR
EJB modules which contains enterprise java beans class files
and EJB deployment descriptor are packed as JAR files with
.jar extenstion
WAR
Web modules which contains Servlet class files,JSP
FIles,supporting files, GIF and HTML files are packaged as
JAR file with .war( web achive) extension
EAR
All above files(.jar and .war) are packaged as JAR file with
.ear ( enterprise archive) extension and deployed into
Application Server.
August 1, 2016
34
What is the difference between EAR, JAR and
WAR file
36. August 1, 2016
36
Web service is a technology to communicate one
programming language with another. For example, java
programming language can interact with PHP and .Net by
using web services. In other words, web service provides a
way to achieve interoperability.
SOAP & REST Webservices
WEB SERVICES
37. • Controller is separated from Model
• View is separated from Model (View can be seen
on any type of UI-Mobile ,desktop etc)
• View is separated from Controller
• There are different types of MVC Frameworks
• Each is used as per unique requirement
• Popular:-Spring,Struts,Hibernate,JSF
August 1, 2016
37
Advantages Of MVC Framework
38. • Enable you to write powerful, scalable applications using POJOs
• Lifecycle – responsible for managing all your application components, particularly those in
the middle tier container sees components through well-defined lifecycle: init(), destroy()
• Dependencies - Spring handles injecting dependent components without a component
knowing where they came from (IoC)
• Configuration information - Spring provides one consistent way of configuring everything,
separate configuration from application logic, varying configuration
• In J2EE (e.g. EJB) it is easy to become dependent on container and deployment
environment; Spring eliminates them
• Portable (can use server-side in web/ejb app, client-side in swing app, business logic is
completely portable)
Advantages of Spring Architecture