Saturday, March 21, 2009

Spring Framework Interview Questions

1. What is IOC (or Dependency Injection)?
The basic concept of the Inversion of Control pattern (also known as dependency injection) is that you do not create your objects but describe how they should be created. You don't directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container (in the case of the Spring framework, the IOC container) is then responsible for hooking it all up.i.e., Applying IoC, objects are given their dependencies at creation time by some external entity that coordinates each object in the system. That is, dependencies are injected into objects. So, IoC means an inversion of responsibility with regard to how an object obtains references to collaborating objects.
2. What are the different types of IOC (dependency injection) ?
There are three types of dependency injection:
Constructor Injection (e.g. Pico container, Spring etc): Dependencies are provided as constructor parameters.
Setter Injection (e.g. Spring): Dependencies are assigned through JavaBeans properties (ex: setter methods).
Interface Injection (e.g. Avalon): Injection is done through an interface.
Note: Spring supports only Constructor and Setter Injection
3. What are the benefits of IOC (Dependency Injection)?
Benefits of IOC (Dependency Injection) are as follows:
Minimizes the amount of code in your application. With IOC containers you do not care about how services are created and how you get references to the ones you need. You can also easily add additional services by adding a new constructor or a setter method with little or no extra configuration.
Make your application more testable by not requiring any singletons or JNDI lookup mechanisms in your unit test cases. IOC containers make unit testing and switching implementations very easy by manually allowing you to inject your own objects into the object under test.
Loose coupling is promoted with minimal effort and least intrusive mechanism. The factory design pattern is more intrusive because components or services need to be requested explicitly whereas in IOC the dependency is injected into requesting piece of code. Also some containers promote the design to interfaces not to implementations design concept by encouraging managed objects to implement a well-defined service interface of your own.
IOC containers support eager instantiation and lazy loading of services. Containers also provide support for instantiation of managed objects, cyclical dependencies, life cycles management, and dependency resolution between managed objects etc.
4. What is Spring ?
Spring is an open source framework 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 you use while also providing a cohesive framework for J2EE application development.
5. What are the advantages of Spring framework?
The advantages of Spring are as follows:
Spring has layered architecture. Use what you need and leave you don't need now.
Spring Enables POJO Programming. There is no behind the scene magic here. POJO programming enables continuous integration and testability.
Dependency Injection and Inversion of Control Simplifies JDBC
Open source and no vendor lock-in.
6. What are features of Spring ?
Lightweight:
spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 1MB. And the processing overhead is also very negligible.
Inversion of control (IOC):
Loose coupling is achieved in spring using the technique Inversion of Control. The objects give their dependencies instead of creating or looking for dependent objects.
Aspect oriented (AOP):
Spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services.
Container:
Spring contains and manages the life cycle and configuration of application objects.
MVC Framework:
Spring comes with MVC web application framework, built on core Spring functionality. This framework is highly configurable via strategy interfaces, and accommodates multiple view technologies like JSP, Velocity, Tiles, iText, and POI. But other frameworks can be easily used instead of Spring MVC Framework.
Transaction Management:
Spring framework provides a generic abstraction layer for transaction management. This allowing the developer to add the pluggable transaction managers, and making it easy to demarcate transactions without dealing with low-level issues. Spring's transaction support is not tied to J2EE environments and it can be also used in container less environments.
JDBC Exception Handling:
The JDBC abstraction layer of the Spring offers a meaningful exception hierarchy, which simplifies the error handling strategy. Integration with Hibernate, JDO, and iBATIS: Spring provides best Integration services with Hibernate, JDO and iBATIS

7. How many modules are there in Spring? What are they?
Spring comprises of seven modules. They are..

The core container:The core container provides the essential functionality of the Spring framework. A primary component of the core container is the BeanFactory, an implementation of the Factory pattern. The BeanFactory applies the Inversion of Control (IOC) pattern to separate an application's configuration and dependency specification from the actual application code.
Spring context:The Spring context is a configuration file that provides context information to the Spring framework. The Spring context includes enterprise services such as JNDI, EJB, e-mail, internalization, validation, and scheduling functionality.
Spring AOP:The Spring AOP module integrates aspect-oriented programming functionality directly into the Spring framework, through its configuration management feature. As a result you can easily AOP-enable any object managed by the Spring framework. The Spring AOP module provides transaction management services for objects in any Spring-based application. With Spring AOP you can incorporate declarative transaction management into your applications without relying on EJB components.
Spring DAO:The Spring JDBC DAO abstraction layer offers a meaningful exception hierarchy for managing the exception handling and error messages thrown by different database vendors. The exception hierarchy simplifies error handling and greatly reduces the amount of exception code you need to write, such as opening and closing connections. Spring DAO's JDBC-oriented exceptions comply to its generic DAO exception hierarchy.
Spring ORM:The Spring framework plugs into several ORM frameworks to provide its Object Relational tool, including JDO, Hibernate, and iBatis SQL Maps. All of these comply to Spring's generic transaction and DAO exception hierarchies.
Spring Web module:The Web context module builds on top of the application context module, providing contexts for Web-based applications. As a result, the Spring framework supports integration with Jakarta Struts. The Web module also eases the tasks of handling multi-part requests and binding request parameters to domain objects.
Spring MVC framework:The Model-View-Controller (MVC) framework is a full-featured MVC implementation for building Web applications. The MVC framework is highly configurable via strategy interfaces and accommodates numerous view technologies including JSP, Velocity, Tiles, iText, and POI.

8. What are the types of Dependency Injection Spring supports?
Setter Injection:Setter-based DI is realized by calling setter methods on your beans after invoking a no-argument constructor or no-argument static factory method to instantiate your bean.
Constructor Injection:Constructor-based DI is realized by invoking a constructor with a number of arguments, each representing a collaborator.

9. What is Bean Factory ?
A BeanFactory is like a factory class that contains a collection of beans. The BeanFactory holds Bean Definitions of multiple beans within itself and then instantiates the bean whenever asked for by clients.
BeanFactory is able to create associations between collaborating objects as they are instantiated. This removes the burden of configuration from bean itself and the beans client.
BeanFactory also takes part in the life cycle of a bean, making calls to custom initialization and destruction methods.
10. What is Application Context?
A bean factory is fine to simple applications, but to take advantage of the full power of the Spring framework, you may want to move up to Springs more advanced container, the application context. On the surface, an application context is same as a bean factory.Both load bean definitions, wire beans together, and dispense beans upon request. But it also provides:
A means for resolving text messages, including support for internationalization.
A generic way to load file resources.
Events to beans that are registered as listeners.

AJAX Tools

AJAX Tools 0.6 is a free and open source AppExchange application that helps developer to author Salesforce.com SControls. It is written ontop of AJAX Toolkit 8.0 (Winter '07) and dojo. AJAX Tools contains an editor, debug shell, SOQL explorer, samples and more.
  • Features
    Editor
  • Syntax highlighting for html, javascript, css.
  • Line numbers
  • Quick Save (Ctrl-S)
  • Search (Ctrl-F)
  • Works with Firefox and IE
  • Tested more with Firefox
  • Execute selected code (Ctrl-Enter)
  • Support for Browser Back/Forward buttons
  • Quick Run (Ctrl-;)
  • Run SControls with merge fields
  • (Todo)Backup S-Controls
  • (Todo)Format code
  • (Todo)Go to line number
  • (Todo)Tab completion

click the screen shot:http://www.cheenath.com/ajaxtools/editor.GIF

AJAX Toolkit 8.0 Samples
More than 50+ AJAX Toolkit 8.0 samples
Samples are executed by clicking the samples link
UI and DOJO Samples
Submit your samples (see Help link)
(Todo)Add more UI samples
(Todo)Add more dojo samples
(Todo)Add Apex samples

click the screen shot:http://www.cheenath.com/ajaxtools/samples.GIF

SOQL Explorer
Display describe result as tree
Constructs SOQL query string by selecting entity field
Can run query and display result as table
(Todo)Generate AJAX Code for the selected query
(Todo)Make async describe calls
Click for larger image

Debug Shell
Javascript command line shell
Type Javascript into the text box and press Enter to run it
Make API calls using AJAX Toolkit 8.0
Tab Completion in the edit box
Display large result set as expandable table
Enter multi Line scripts using Ctrl-Enter
Type clear() to clear the logs
See Help for more details
(Todo)Fix Tab completion in IE
Click for larger image



Web services tutorials final part

Web Services Summary
This tutorial has taught you how to convert your applications into web-applications.
You have learned how to use XML to send messages between applications.
You have also learned how to export a function (create a web service) from your application.
Now You Know Web Services, What's Next?
The next step is to learn about WSDL and SOAP.
WSDL
WSDL is an XML-based language for describing Web services and how to access them.
WSDL describes a web service, along with the message format and protocol details for the web service.
If you want to learn more about WSDL, please visit our WSDL tutorial.
SOAP
SOAP is a simple XML-based protocol that allows applications to exchange information over HTTP.
Or more simply: SOAP is a protocol for accessing a web service.
If you want to learn more about SOAP, please visit our SOAP tutorial.
Web Services can convert your applications into Web-applications.By using Web services, your application can publish its function or message to the rest of the world.
Web Services can be used by other applications.With Web services your accounting department's Win 2k servers can connect with your IT supplier's UNIX server.
The basic Web Services platform is XML + HTTP.Web services uses XML to code and decode your data and SOAP to transport it.
Learn how to create Web Services from an ASP.NET application.This tutorial converts an ASP.NET application to a Web Service.

web services tutorial part 3

Using the Web Service Example
In the previous page we created a Web service.
The FahrenheitToCelsius() function can be tested here: FahrenheitToCelsius
The CelsiusToFahrenheit() function can be tested here: CelsiusToFahrenheit
These functions use HTTP POST and will send an XML response like this:

38
Put the Web Service on Your Web Site
Using a form and HTTP POST, you can put the web service on your site, like this:
Fahrenheit to Celsius:
Celsius to Fahrenheit:
How To Do It
Here is the code to add the Web Service to a web page:
method="POST">









Fahrenheit to Celsius:size="30" name="Fahrenheit">
value="Submit" class="button">


method="POST">









Celsius to Fahrenheit:size="30" name="Celsius">
value="Submit" class="button">

We services tutorials part 2

Web Services have three basic platform elements: SOAP, WSDL and UDDI.
What is SOAP?
SOAP is a simple XML-based protocol to let applications exchange information over HTTP.
Or more simple: SOAP is a protocol for accessing a Web Service.
SOAP stands for Simple Object Access Protocol
SOAP is a communication protocol
SOAP is a format for sending messages
SOAP is designed to communicate via Internet
SOAP is platform independent
SOAP is language independent
SOAP is based on XML
SOAP is simple and extensible
SOAP allows you to get around firewalls
SOAP is a W3C standard

What is WSDL?
WSDL is an XML-based language for describing Web services and how to access them.
WSDL stands for Web Services Description Language
WSDL is based on XML
WSDL is used to describe Web services
WSDL is also used to locate Web services
WSDL is a W3C standard

What is UDDI?
UDDI is a directory service where businesses can register and search for Web services.
UDDI stands for Universal Description, Discovery and Integration
UDDI is a directory for storing information about web services
UDDI is a directory of web service interfaces described by WSDL
UDDI communicates via SOAP
UDDI is built into the Microsoft .NET platform

-------------------------------------------------------------------------------------------------
Any application can have a Web Service component.
Web Services can be created regardless of programming language.
A Web Service Example
In the following example we will use ASP.NET to create a simple Web Service that converts the temperature from Fahrenheit to Celsius, and vice versa:
<%@ WebService Language="VBScript" Class="TempConvert" %>Imports System
Imports System.Web.ServicesPublic Class TempConvert :Inherits WebService Public Function FahrenheitToCelsius
(ByVal Fahrenheit As String) As String
dim fahr
fahr=trim(replace(Fahrenheit,",","."))
if fahr="" or IsNumeric(fahr)=false then return "Error"
return ((((fahr) - 32) / 9) * 5)
end function Public Function CelsiusToFahrenheit
(ByVal Celsius As String) As String
dim cel
cel=trim(replace(Celsius,",","."))
if cel="" or IsNumeric(cel)=false then return "Error"
return ((((cel) * 9) / 5) + 32)
end functionend class
This document is saved as an .asmx file. This is the ASP.NET file extension for XML Web Services.
Example Explained
Note: To run this example, you will need a .NET server.
The first line in the example states that this is a Web Service, written in VBScript, and has the class name "TempConvert":
<%@ WebService Language="VBScript" Class="TempConvert" %>
The next lines import the namespace "System.Web.Services" from the .NET framework:
Imports System
Imports System.Web.Services
The next line defines that the "TempConvert" class is a WebService class type:
Public Class TempConvert :Inherits WebService
The next steps are basic VB programming. This application has two functions. One to convert from Fahrenheit to Celsius, and one to convert from Celsius to Fahrenheit.
The only difference from a normal application is that this function is defined as a "WebMethod()".
Use "WebMethod()" to convert the functions in your application into web services:
Public Function FahrenheitToCelsius
(ByVal Fahrenheit As String) As String
dim fahr
fahr=trim(replace(Fahrenheit,",","."))
if fahr="" or IsNumeric(fahr)=false then return "Error"
return ((((fahr) - 32) / 9) * 5)
end function Public Function CelsiusToFahrenheit
(ByVal Celsius As String) As String
dim cel
cel=trim(replace(Celsius,",","."))
if cel="" or IsNumeric(cel)=false then return "Error"
return ((((cel) * 9) / 5) + 32)
end function
Then, end the class:
end class
Publish the .asmx file on a server with .NET support, and you will have your first working Web Service.
Look at our example Web Service
ASP.NET Automates the Process
With ASP.NET, you do not have to write your own WSDL and SOAP documents.
If you look closer at our example Web Service, you will see that ASP.NET has automatically created a WSDL and SOAP request.

Introduction to Web Services tutorial part 1

Introduction to Web Services
Web Services can convert your applications into Web-applications.
Web Services are published, found, and used through the Web


=======================================================
What You Should Already Know
Before you continue you should have a basic understanding of the following:
HTML
XML

========================================================

Introduction to Web Services
Web Services can convert your applications into Web-applications.
Web Services are published, found, and used through the Web.
What You Should Already Know
Before you continue you should have a basic understanding of the following:
HTML
XML

What are Web Services?
Web services are application components
Web services communicate using open protocols
Web services are self-contained and self-describing
Web services can be discovered using UDDI
Web services can be used by other applications
XML is the basis for Web services
How Does it Work?
The basic Web services platform is XML + HTTP.
The HTTP protocol is the most used Internet protocol.
XML provides a language which can be used between different platforms and programming languages and still express complex messages and functions.
Web services platform elements:
SOAP (Simple Object Access Protocol)
UDDI (Universal Description, Discovery and Integration)
WSDL (Web Services Description Language)
We will explain these topics later in the tutorial.
The Future of Web services
Don't expect too much, too soon.
The Web Services platform is a simple, interoperable, messaging framework. It still misses many important features like security and routing. But, these features will be available as soon as SOAP becomes more advanced.
Hopefully, Web services can make it much easier for applications to communicate

A few years ago Web services were not fast enough to be interesting.
Thanks to the major IT development the last few years, most people and companies have broadband connection and use the web more and more.
Interoperability has Highest Priority
When all major platforms could access the Web using Web browsers, different platforms could interact. For these platforms to work together, Web applications were developed.
Web-applications are simple applications run on the web. These are built around the Web browser standards and can mostly be used by any browser on any platform.
Web Services take Web-applications to the Next Level
Using Web services, your application can publish its function or message to the rest of the world.
Web services use XML to code and to decode data, and SOAP to transport it (using open protocols).
With Web services, your accounting department's Win 2k server's billing system can connect with your IT supplier's UNIX server.
Web Services have Two Types of Uses
Reusable application components.
There are things applications need very often. So why make these over and over again?
Web services can offer applications components like currency conversion, weather reports, or even language translation as services.
Ideally, there will be only one type of each application component, and anyone can use it in their application.
Connect existing software.
Web services help to solve the interoperability problem by giving different applications a way to link their data.
With Web services you can exchange data between different applications and different platforms.