Archive

Archive for June, 2014

Spring Framework Primer

 

 

 

  

  

Spring Framework Primer 

The Spring Framework is an open source application framework, for the Java platform and also the .NET Framework (Spring.NET). The first version was written by Rod Johnson who released the framework with the publication of his book Expert One-on-One J2EE Design and Development in October 2002. The framework was first released under the Apache 2.0 license in June 2003. The Spring 1.2.6 framework won a Jolt productivity award and a JAX Innovation Award in 2006. The current Spring framework version is 3.0.

VMware acquired SpringSource for approximately $362 million on September 16, 2009.

Spring was created to address the complexity of enterprise application development. One of the chief advantages of the Spring framework is its layered architecture, which allows you to be selective about which of its components or modules you want to use for your application development. Unlike single-tier frameworks, such as Struts or Hibernate, Spring aims to help structure whole applications in a consistent, productive manner, pulling together best-of-breed single-tier frameworks to create a coherent architecture.

The core features of the Spring Framework can be used by any Java application, but there are extensions for building web applications on top of the Java Enterprise platform. Although the Spring Framework does not impose any specific programming model, it has become popular in the Java community as an alternative, replacement, or even addition to the Enterprise JavaBean (EJB) model.

 

Spring is unique for several reasons:

  • It addresses important areas that other popular frameworks don’t. Spring focuses around providing a way to manage your business objects.
  • Spring is comprehensive and modular (because of its modules). Spring has a layered architecture, meaning that you can choose to use just about any part of it in isolation, yet its architecture is internally consistent. So you get maximum value from your learning curve. For example: You might choose to use Spring only to simplify use of JDBC, or you might choose to use Spring to manage all your business objects. 
  • It’s easy to introduce Spring incrementally into existing projects.
  • Spring is designed from the ground up to help you write code that’s easy to test. Spring is an ideal framework for test driven projects.
  • Spring is an increasingly important integration technology, its role is recognized by vendors both large and small.
  • Spring also addresses most infrastructure concerns (cross-cutting concerns such as logging, security etc) of typical applications.

 

  

Architectural benefits of Spring:

Let’s look at some of the benefits Spring can bring to your project:

  • Spring can effectively organize your middle tier objects. Spring takes care of plumbing that would be left up to you if you use only Struts or any other framework that use J2EE APIs.
  • Spring’s configuration management services can be used in any architectural layer, in whatever runtime environment.
  • Spring can eliminate the increase of Singletons used in many projects. This is a major problem that reduces testability and object orientation.
  • Spring eliminates the need to use a variety of custom properties file formats, by handling configuration in a consistent way throughout the application.
  • Spring facilitates good programming practice by reducing the cost of programming to interfaces rather than classes.
  • Spring is designed so that applications built with it depend on as few of its APIs as possible. Most business objects in Spring applications have no dependency on Spring.
  • Applications built using Spring are very easy to test. For certain unit testing scenarios, the Spring Framework provides mock objects and testing support classes. Spring also provides unique “integration testing” functionality in the form of the Spring TestContext Framework and legacy JUnit 3.8 support classes that enable you to test your code quickly and easily, even while accessing a staging database.
  • Spring helps you solve problems though being a most lightweight possible infrastructure. Spring provides an alternative to EJB that’s appropriate for many applications. For example, Spring can use AOP to deliver declarative transaction management without using an EJB container; even without a JTA implementation.
  • Spring provides a consistent framework for data access, whether using JDBC or an O/R mapping product such as TopLink, Hibernate or a JPA or JDO implementation.

 

Spring is essentially a technology dedicated to enable building applications using Plain Old Java Objects (POJOs). It enables you to develop components as POJOs containing only your business logic, while the framework takes care of the many value adds you need while building enterprise applications — even in areas that you may not have considered when initially authoring the application. This goal requires a sophisticated framework, which conceals much complexity from the developer.

Since your business logic is abstracted from infrastructure concerns, it’s also likely to enjoy a longer life. As the business logic is abstracted from the infrastructure concerns, any changes to the inevitable infrastructure change (such as choice of application server) can be minimized. Thus Spring can enable you to implement the simplest possible solution to your problems. And that’s worth a lot.

 

What does Spring do?  Read more…

Advertisements

Exercise 2 – Using overloaded methods in Java

 

Exercise – 2 for module 3 of Using operators and decision constructs:

 

This post has the exercise – 2 for module 3 of Using operators and decision constructs. Let’s practice what we have learnt. Before practicing the exercise, follow the instructions below which will give you a step-by-step instruction:

 

 

 

 

You can download the source code (WJ-1103A-module3-exercise2.zip) for this exercise from the Box widget in the sidebar. Follow the video tutorial below if you ever get stuck while executing the programs. Read more…

Eclipse IDE Workbench, Editing, Ant, Help Tips & Tricks

 

Eclipse IDE Workbench, Editing, Ant,  Help Tips & Tricks:

 

In continuation to the previous post, this one has Tips & Tricks for Views in Eclipse IDE. Refer to posts in Eclipse Tips & Tricks for others.   

 

Note: If the image displayed below is unclear, then click on the image.  Then hover over the image in the newly opened window. You will get a zoom icon, click the image with it and it will be displayed with better visibility. Read more…

Spring Framework Introduction

 

Chapter 2: Introduction to Spring

 

Spring Framework:

The Spring framework is a comprehensive layered Java/Java EE application platform. It was created to address the complexity of enterprise application development. The Spring Framework takes best practices and design patterns that have been proven over the years, codifies these patterns as first class objects that can be integrated into applications. Spring makes it possible to use plain-vanilla Java Beans (POJOs) to achieve things that were previously only possible with EJBs.

 

Spring includes:

  • An IOC lightweight container
  • AOP functionality
  • Abstraction layer for JDBC / transaction management                    
  • ORM integration layer
  • Web integration layer
  • A flexible MVC web application framework 

 

Spring is not only an application framework, it also serves as a platform for several open source projects that are based on the core Spring Framework project such as Spring IDE, Spring Security, Spring Web Flow, Spring Web Services, Spring Rich Client,  Spring Batch, Spring Modules, Spring Dynamic Modules, Spring Integration, Spring LDAP, Spring JavaConfig, Spring .NET, Spring BeanDoc.

 

Spring’s features:

Framework:

Spring makes it possible to develop and maintain complex applications using simple components. In Spring, application objects are configured declaratively typically in an XML file. Spring also provides much infrastructure functionality (transaction management, integration, etc.), leaving only the development of application logic to you.

 

Lightweight:

Spring is lightweight in terms of both size and overhead. Spring Framework can be distributed in a single JAR file that weighs just over 2.5 MB and the processing overhead required by Spring is negligible. Spring is non intrusive in a way that the objects in a Spring-enabled application often have no dependencies on Spring-specific classes.

 

Container:

Spring provides a container which contains and manages the lifecycle and configuration of application objects. In Spring, you can declare how each of application objects should be created, how they should be configured, and how they should be associated with each other.

 

Dependency Injection:

Spring promotes loose coupling through dependency injection (DI). When DI is applied, objects are passively given their dependencies instead of looking for dependencies themselves. You can think of DI as JNDI in reverse — instead of an object looking up for dependencies from a container, the container gives the dependencies to the object at its instantiation without waiting to be asked.

 

Aspect-oriented:

Spring comes with rich support for aspect-oriented programming (AOP) that enables separating application business logic from system services (such as auditing, transaction management, logging etc). Application objects do what they’re supposed to do i.e., perform business logic — and nothing more. They are not responsible for or even be aware of other system concerns, such as logging or transactional support.

 

Spring Framework Architecture: Read more…

Spring Framework Terminologies

 

Chapter 1: Terminologies

 

Design Patterns:

A design pattern is a conceptual general reusable solution to a commonly occurring problem in software design. A design pattern can’t be transformed directly into code. It is a template for how to solve a problem that can be used in many different situations. Design patterns such as Factory, Builder, Decorator, and Service Locator (to name a few) have widespread recognition and acceptance within the software industry. Design patterns are best practices given a name that describe what the pattern does, where the pattern is best applied and the problems that the pattern addresses etc.

 

Framework:

Framework is a step ahead of design patterns. It is basically a conceptually organized structure based on best practices and design patterns to address complex issues. A software framework is an abstraction in which generic functionality can be selectively overridden, specialized or extensible by user code. Frameworks are similar to software libraries in way that they are reusable code wrapped in a well-defined API. However unlike libraries, the overall program’s flow of control is not dictated by the caller, but by the framework. This inversion of control is the distinguishing feature of software frameworks.

 

Object-Oriented Frameworks:

An object-oriented framework is a semi-finished object-oriented application laid out on OOPS concepts such as Inheritance, Polymorphism, Abstraction and Encapsulation.   Object-oriented design patterns typically show relationships and interactions between classes or objects. It encapsulates common features that can be used across the same application or even different applications. Common examples of such frameworks include Apache Struts, JSF, and Spring etc. A framework-driven approach to application development usually involves integration of multiple object-oriented frameworks and creation of specific functionalities as extensions to these frameworks.

Every framework provides its own extension points called hotspots. Hotspots are specific to a framework, usually pertaining to integration (application programming/service provider interfaces) and configuration (external metadata). For example, the EJB 2.0 specifications define hotspots for Java bean objects to be deployed in an EJB container.

 

Inversion of Control:

Inversion of control is a generic principle and not a design pattern. Rather, it is a broad concept that is implemented by several design patterns.

Inversion of control is applied during communication between a framework and custom application logic. A common feature of frameworks is to maintain control of all communication activities within an application because of which the primary objective of an application module will only be to provide functionalities that can be invoked by the framework. Compare this to a scenario without frameworks, in which there is a significant effort on how the modules can invoke and manage each other.

 

Application modules won’t have to directly access each other’s capabilities when deployed on top of a framework. The same is also true for invocations from external entities. Instead, every request must be routed through the framework. The framework, in turn, can make multiple calls across more than one module in a controlled fashion before returning a result back to the caller.

In the light of what has been said so far, inversion of control can be summed up as:

“Don’t call us (framework); we’ll call you (application)”

 

Service Locator pattern: Read more…