Spring Interview Questions Part: 1

  • What is mean by Dependency Injection? Or What do you mean by Inversion of Control?

Dependency injection (DI) is a programming design pattern and architectural model, sometimes also referred to as inversion of control or IOC, although technically speaking, dependency injection specifically refers to an implementation of a particular form of IOC.

Dependancy Injection describes the situation where one object uses a second object to provide a particular capacity. For example, being passed a database connection as an argument to the constructor instead of creating one internally. The term "Dependency injection" is a misnomer, since it is not a dependency that is injected, rather it is a provider of some capability or resource that is injected. There are three common forms of dependency injection: setter-, constructor- and interface-based injection.

Dependency injection is a way to achieve loose coupling. Inversion of control (IOC) relates to the way in which an object obtains references to its dependencies. This is often done by a lookup method. The advantage of inversion of control is that it decouples objects from specific lookup mechanisms and implementations of the objects it depends on. As a result, more flexibility is obtained for production applications as well as for testing.

  • What are the modules in Spring?
  1. The core container:

    The core container provides the fundamental functionality of the Spring framework. In this module primary component is the BeanFactory, an implementation of the Factory pattern. The BeanFactoryapplies the Inversion of Control (IOC) pattern to separate an application’s configuration and dependency specification from the actual application code.

  2. Spring context module :

    TThe Spring context is a configuration file that provides context information to the Spring framework. The Spring context includes enterprise services such as e-mail, JNDI, EJB, internalization, validation, scheduling and applications lifecycle events. Also included is support for the integration with templating frameworks such as velocity.

  3. Spring AOP module:

    The Spring AOP module allows a software component to be decorated with additional behavior, 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.

  4. Spring DAO module:

    The Spring DAO module provides a JDBC-abstraction layer that reduces the need to do tedious JDBC coding and parsing of database-vendor specific error codes. Also, the JDBC package provides a way to do programmatic as well as declarative transaction management, not only for classes implementing special interfaces, but for all your POJOs (plain old Java objects).

  5. Spring ORM module:

    : Spring provides integration with OR mapping tools like Hibernate, JDO and iBATIS. Spring transaction management supports each of these ORM frameworks as well as JDBC.

  6. Spring Web module:

    The Web context module provides basic web-oriented integration features 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.

  7. Spring MVC framework module:

    Spring provides a pluggable MVC architecture. The users have a choice to use the web framework or continue to use their existing web framework. Spring separates the roles of the controller; the model object, the dispatcher and the handler object which makes it easier to customize them. Spring web framework is view agnostic and does not push the user to use only JSPs for the view. The user has the flexibility to use JSPs, XSLT, velocity templates etc to provide the view.

  • What is a BeanFactory and XMLBeanFactory?

Bean factory is a container. It configures, instantiates and manages a set of beans. These beans are collaborated with one another and have dependencies among themselves. The reflection of these dependencies are used in configuring data that is used by BeanFactory.

XMLBeanFactory is a bean factory that is loaded its beans from an XML file.

  • What are Inner Beans?

A bean inside another bean is known as Inner Bean. They are created and used on the fly, and can not be used outside the enclosing beans. The Id and scope attributes for inner beans are of no use.

  • What is DataAccessException?

DataAccessException is an unchecked RuntimeException. These type of exceptions are unforced by users to handle. This exception is used to handle the errors occurring when the details of the database access API in use, such as JDBC.

About these ads

A review of “Spring Web Flow 2 Web Development” book from Packt.

About Spring Web Flow

Spring Web Flow allowing us to represent the UI flow in (part of) a web application in a clear and simple way. It has several advantages:

  • The UI flow in a web application is clearly visible by looking at the corresponding web flow definition (typically in an XML file).
  • Web Flows can be designed to be self contained. This allows you to see a part of your application as a module and reuse it in multiple situations.
  • Web Flows can define any reasonable UI flow in a web application, always using the same consistent technique. You’re not forced into using specialized controllers for very particular situations.

About this book:

“Spring Web Flow 2 Web Development” by Markus Stäuble, Sven Lüppken (from Packt) is a very good book to start with Spring Web flow. I got a chance to go through this book and I thought of writing a small review about this book in my page.

Just like the main well known Spring books, this book is also approaching learning by doing a small project.  In the entire book we are developing a small project (bug tracking system) and through that we are trying to learn web flow.

The source code for the book can be download from HERE .
Publisher: Packt Publishing (March 20, 2009)
Language: English

star-rating

Authors: Markus Stäuble, Sven Lüppken

TO BUY THIS BOOK (Click on the Pic): 

Whats special in this Book?

  • The book is different in some cases like it does not only explain how to create flows with Spring Web Flow, but also shows the integration with other technologies like JavaServer Faces, EasyMock, Hibernate, Spring Security.
  • Explains web flow example project which is using so many other technologies, tools and frameworks like Maven/Ant, Eclipse/Netbeans IDE, Easymock, Apache Tiles etc etc.

Advantages:

  • More importantly it covers latest version and advantages of Spring Web Flow.
  • “Spring Web Flow 2 Web Development” is special in one case. They are started with the Installation and set-up of the whole environment. As a programmer it will help you very much. (although they are proving Code).
  • It starts from the very basics and moves on further.
  • Explains things with Maven/Ant, eclipse/Netbeans. This sounds very good.
  • This book explains the integration of Spring and Java Server Pages very clearly. And it  also explains the Spring web flow and Faces integration. This may consider an added advantage of this book.
  • Authors are given Class diagrams also for our reference in many framework class cases. This helps us to get a full idea about that class and the functionalities that provides.
  • It also also explains the essential modules of the complete Spring framework stack.
  • Given the complete configuration files and details of flows and others. This helps us to get the overall picture of the configurations.
  • Given so many reference links to follow. This also given at each specific parts of the book where that respective technology explains.
  • Explains Spring Java Script. It is really good to find some tutorial about that Library framework. Though it is coming through Spring Web Flow 2, a very few authors touches it in their books.
  • Another great advantage is it covers Spring Security. Gives us a chance to learn about this Library.
  • Apache Tiles integration and configuration is also covered although the book.
  • It also covers Unit testing of this Spring Web flow using EasyMock. This is really good point with respect to developers point of view.
  • It gives us an idea about running in the SpringSource dm Server (modular OSGi -Open Services Gateway initiative).

Disadvantages:

  • In the installation chapter we are coming across a lot of frameworks/tools. If you are a person who knows most of them then that chapter will be easy for you. Otherwise you need a bit more time to understand that.
  • Missing Spring IDE explanation.
  • Not much information about Spring basics. That’s seems to be Okay because they mentioned it as a book for the people who knows Spring.
  • The code mentioned in the book follows the same font. If they would have make the syntax/code highlighted/with some sort of separation  then that would have been great to read.
  • One basic thing about the formatting. Paragraphs are not JUSTIFIED. May be  that affects the code snippets. But surely this is making a bit bad look for the entire book in my view.

A really good Spring book from Packt! “Spring Web Flow 2 Web Development”

Spring Web Flow Book from Packt

If you know Spring Application Framework and keen to study its Web Strength specially its MVC and Web flow then this book will be a really better way for that. Packt published its latest book regarding one of the key member of Spring Family; “Spring Web Flow 2“.  It covers a lot many things like Spring Faces ( Specially its inegration with JSF), Spring Web Flow (With its very Latest version) and Spring Security…The key point about the book is, it describes everything, starting from the basics like Installing and configuring the web flow to its unit testing. 

Do visit the home of  this  book from Packt through this link. Click here

Find out the Table of contents here. You can also do a free download of one Chapter.

‘Six’ best web frameworks in Java

A web application framework is a software framework that is designed to support the development of dynamic websites, Web applications and Web services. The framework aims to alleviate the overhead associated with common activities used in Web development. Here is the list of SIX best web frameworks which we are using in Java. Each one has its own advantages.

1. Java Server Faces – JSF

  • From Sun Microsystems
  • Based on Component Centric approach
  • Best Feature : The most using web framework. Because of its component architecture, the developer doesn’t need to mess with writing HTML, JavaScript etc to get rich “AJAX” type of functionality. It also takes care of state and event management. It has very less configuration too.

JavaServer Faces (JSF) is a new standard Java framework for building Web applications. It simplifies development by providing a component-centric approach to developing Java Web user interfaces. JavaServer Faces also appeals to a diverse audience of Java/Web developers. “Corporate developers” and Web designers will find that JSF development can be as simple as dragging and dropping user interface (UI) components onto a page, while “systems developers” will find that the rich and robust JSF API offers them unsurpassed power and programming flexibility. JSF also ensures that applications are well designed with greater maintainability by integrating the well established Model-View-Controller (MVC) design pattern into it’s architecture. Finally, since JSF is a Java standard developed through Java Community Process (JCP), development tools vendors are fully empowered to provide easy to use, visual, and productive develop environments for JavaServer Faces.

2. GWT

  • From Google
  • Based on Widgets
  • Best Feature : Speed development. Easy to develop good, neat and “Browser independent” Ajax applications. Give more stress to pure browser independent ;).

Google Web Toolkit (GWT) is an open source Java software development framework that makes writing AJAX applications like Google Maps and Gmail easy for developers who don’t speak browser quirks as a second language. Writing dynamic web applications today is a tedious and error-prone process; you spend 90% of your time working around subtle incompatibilities between web browsers and platforms, and JavaScript’s lack of modularity makes sharing, testing, and reusing AJAX components difficult and fragile.GWT lets you avoid many of these headaches while offering your users the same dynamic, standards-compliant experience. You write your front end in the Java programming language, and the GWT compiler converts your Java classes to browser-compliant JavaScript and HTML.Project Home and More features

3. Stripes

  • From Mc4j
  • Based on MVC architecture
  • Best Feature: No Configurations ) . Annotation based programming makes coding more interesting and easy.

Stripes is a presentation framework for building web applications using the latest Java technologies. The main driver behind Stripes is that web application development in Java is just too much work! It seems like every existing framework requires gobs of configuration.Project Home and more features

4. Spring MVC

  • From SpringSource
  • Based on MVC architecture
  • Best Feature : Speed development. Now so many Annotations are also included (v2.5). Its from SpringSource and have a good support too. Being a person who likes and works with Spring framework.. I really encouraged by their good and really fast support.

Spring Web MVC is the own web framework of Spring Framework.The Spring MVC Framework’s architecture and design are in such a way that every piece of logic and functionality is highly configurable. Also Spring can integrate effortlessly with other popular Web Frameworks like Struts, WebWork, Java Server Faces and Tapestry. It means that you can even instruct Spring to use any one of the Web Frameworks. More than that Spring is not tightly coupled with Servlets or Jsp to render the View to the Clients. Integration with other View technologies like Velocity, Freemarker, Excel or Pdf is also possible

5. Struts2

  • From Apache
  • Based on MVC architecture
  • Best Feature : No more ActionForms! Use any JavaBean to capture form input or put properties directly on an Action class. Use both binary and String properties! and its enhanced and rich tags

Apache Struts 2 is an elegant, extensible framework for creating enterprise-ready Java web applications. The framework is designed to streamline the full development cycle, from building, to deploying, to maintaining applications over time.Project Home and More Features

6. Wicket

  • From Apache
  • Based on Component Centric approach
  • Best Feature : Swing-like OO Component Model. This feature separates Wicket from all other frameworks

With proper mark-up/logic separation, a POJO data model, and a refreshing lack of XML, Apache Wicket makes developing web-apps simple and enjoyable again. Swap the boilerplate, complex debugging and brittle code for powerful, reusable components written with plain Java and HTML.Project Home and More Features here…

Please put your Suggestions and Ratings here and the frameworks which you are used and known as great ones. That will be more helpful to all of us to get the real idea. As we all know the selection is entirely related with the requirement, learning time and the using situation, this post is gives you an idea about the frameworks using nowadays. Its not at all easy to “rate” the Java frameworks and here I am putting this as per my knowledge and the current trends only. I expect your positive and negative suggestions through valuable comments. All the SIX frameworks noted here are excellent ones and do NOT consider the order as a RANK given to them.

Technorati Tags: , , , , , , , ,