Springing :D => Something About Dependency Injection

I just got an understanding of what is dependency injection!! I was hearing Dependency Injection from my colleagues and all, and I was stumbled!! what actually it is?   Well now I say that’s a real piece of cake !!!.

The phrase “Dependency Injection” may sound intimidating. But as when we look closer we will realize that it’s not complex as it sounds .And by applying these DesignPattern(DependencyInjection is_a DesignPattern). to your code, then it become significantly easier to understand and easier to extent and test. Am quoting an example from a text  here through which one can easily understand what actually it is.

Consider a Knight class.

  1. package com.springaction.knights;
  2.  public class DamselRescuingKnight implements Knight {
  3.               private RescueDamselQuest quest;
  4.  public DamselRescuingKnight() {
  5.         quest = new RescueDamselQuest();
  6.    }
  7.  public void embarkOnQuest() throws QuestException {
  8.        quest.embark();
  9.    }
  10. }

In the above snippet you can see DamselResuceKnight creates it’s on quest , a RescueDamselQuest(), within the constructor (LOC – 4&5).This actually makes a DamselRescuingKnight tightly coupled to a RescueDamselQuest() and it severly limits the knight’s quest-embarking repertoire. Actually it can rescue a Damsel yea it is supposed to that, but what else it can do? Nothing but simply sit.

And also when you get familiar with testing, you will find it difficult to test such a piece of code.(unitTests). In writing test, the scenario here is you got to assert that quest’s embark(); method is called when the knight’s embarkOnQuest() is called, the code is supposed to do so, But there is no clear way to test that here, so the DamselRescuingKnight will remain untested.

Here comes the Dependency Injection(DI). With DI, objects are given their dependencies at creation time by some third party that coordinates each object in the system. Objects aren’t expected to create or obtain their dependencies – dependencies are injected into the objects that need them.

Illustrating DI with the below code snippet

Consider a class BraveKnight and see that BraveKnight is ready and flexible enough to take any Quest!!

  1. package com.springaction.knights;
  2. public class BraveKnight implements Knight {
  3.    private Quest quest;
  4. public BraveKnight (Quest quest) {
  5.    this.quest = quest;  <————-    //Here the quest is being injected
  6.  }
  7. public void embarkOnQuest() throws QuestException {
  8.   quest.embark();
  9.  }
  10. }

As in the above snippet unlike DamselRescueKnight, BraveKnight doesn’t create his own quest. Instead he is given a quest at the construction time as a constructor argument.This is a type of DI and is known as Constructor Injection.

The quest he’s give as type Quest, is an interface that all quests implement. So the BraveKnight  could embark on a RescueDamselQuest, a SlyDragonQuest , or any other Quest implementation he is given. The point here is that BraveKnight isn’t coupled to any specific implementation of Quest.It doesn’t matter to him what kind of quest he is asked to embark upon.


Something About Hibernate

Hibernate is an Object Relational Mapping solution for Java, and it’s an open-source persistent framework.

It is a powerful, High Performance, Object Relational Persistence Query Service for any Java Application.

How Hibernate Functions:-

  • Hibernate maps Java Classes to Database Types and Java Data types to SQL data types, and thus it makes the life of a programmer easier.
  • Hibernate make use of XML configurations for mapping Java Classes to  database Objects.
  • Provides simple API for accessing Java Objects to and from the database.
  • Changes in the database can be reflected by changing the XML configuration file.
  • It Abstracts the SQL queries & helps us working with Java Objects.
  • It doesn’t require an application server to work.
  •  Can manage complex associations through Objects.
  • Ease in Data Retrieval
  • And It supports almost all RDBMS.
  • It uses existing Java API’s like JDBC ,JNDI, Java TransactionAPI. JDBC provides a rudimentary level of abstraction,and also it allows any database with a JDBC driver can be integrated with Hibernate.
  • JNDI and Java Transaction API (JTI) helps Hibernate to get integrated with J2EE application servers.


Hibernate sits between Traditional Java objects and database server to handle all the work in persisting objects based on appropriate Object-Relational mechanisms and patterns.

A High Level Hibernate Architecture


Objects which gave birth in an Hibernate Application

  • Configuration Object
  • Session Factory Object
  • Session Object
  • Transaction Object
  • Query Object
  • Criteria Object


  • Configuration Object

It’ the first ever object that get created in an Hibernate Application, and it’s created automatically during application initialization process. The two key components of Configuration Objects are :

  1. Database Connection => which is handled by hibernate.properties and hibernate.cfg.xml.
  2. Class Mapping Setup => This helps in creating in connection with Java Classes and DB tables.
  •  Session Factory Object

The above mentioned Configuration Object is used to create Session Factory Object which inturn configures Hibernate for the application with the supplied configuration file => which instantiates a Session Object. Session Factory Object is created during application startup.We will need one SessionFactory Object per Database and vice versa.

  • Session Object

The basic purpose of this object is to get a physical connection with the database & this object will be instantiated each time when database interaction occurs. They are not thread safe( should be destroyed/created as needed).

  • Transaction Object

This is an optional object , and Hibernate applications may choose not to use this interface.

  •   Query Object

Query Objects use SQL or Hibernate Query Language string to retrieve data from the database and create objects.

  • Criteria Object

These objects are used to create and execute object oriented criteria queries to retrieve objects.

A new experience || blogging from BlackBerry

Well just trying to write some craps!! Or in other words am simply testing the BlackBerry WordPress App! It’s really good and fast too!! UI is designed in a pretty awesome way! I found at certain options app getting a bit laggy, but in short this is a great piece of work!


A screen shot to show how the interface is, well for me this app is really a piece of cake 😉

That’s distracting

Today happened to see!! “the facebook profile again” its all because of the recommendation engine by #Facebook!! huh facebook knows whom I wanna see, but I shouldn’t have looked,as its really making me frustrated and more sad! and I remember that slight mistake from my part if needed can be forgiven, but now it had taken this form and it’s like this in present.I forgot about many other things to worry 😉 so right now am leaving this, and I believe something good will happen!! No matter what ever be the situation I will always stand with truth and I will be truthful.and it’s like now its more than 3 or 4 years my struggle with life continues, still the hope that I can bring it, I can make it, is driving me forward, and at some instant I feel am loosing, simultaneously these kind off pop ups also adding a bit to sufferings. well still am keeping my heads up, even if inside is burning!!! Trying to be focused, learning to intake, and learning to let go!!

കലാലയ ജീവിതവും സഫലമാവാത്ത ചില സ്വപ്നങ്ങളും !!!

ഇന്നു  ഞാൻ ഒരു youtube വീഡിയോ  കാണുക  ഉണ്ടായി !! വലിയ  ഡീൽ  ഒന്നുമില്ല , ഇറ്റ്‌  വാസ്  എ “ഫ്ലാഷ് മോബ് “!! അത്  എന്നെ  എന്റെ കലാലയത്തിലേക്ക്  ആണ്  കൊണ്ട്  പോയത് , അവിടുത്തെ ചില ഓർമകൾ !! 
ഒരുപാടു  സ്വപങ്ങളും  ആയി ആണ്  ഞാൻ  അവിടെ  ചെന്ന്  കേറുന്നത് !! >>>>

Walking With Dreams!!

വീണ്ടും ഞാൻ ഒരു RAILS  ജീവിതം   തുടങ്ങുകയാണ് !!  ഒരുപാട്  ഒരുപാട്  സ്വപ്നങ്ങളുമായി  ഞാന്  എന്നും  ശുഭ  പ്രതീക്ഷയുമായി  നടക്കുന്നു !!

Am always walking with dreams!! A dream of a firm which wont get restricted to a single floor of a building! A dream to do something philanthropic!! that can really change the world. And luckily am having a small team who got the same taste and vision, We are looking forward for a greater tomorrow which would be a result of our efforts and dedication.

I really want to change the current education system, and the views of foiks towards education and gaining a degree!! I just want to make sure that, don’t study just for gaining a degree!! Make use of the education period to gain as much as you can, rather than wasting your time, find time to build on projects, keep working/keep learning!! Form new concepts, from learning, try to think out of the box, and formulate some principles, theories and keep trying to implement that!! Keep the better use of internet!! rather than wasting your energy on porn sites and social networks, make these social containers for a betterment of yourself, make it as a tool for building business/ healthy relations , never think of it as a tool for killing your time.
And always keep in mind that , “If you are not making someone else life better you are simply wasting your time”,
And never be afraid of making decisions in your life!!! You can’t always win!! but you can try and never be afraid of giving up certain things which you don’t really worth posse sing it. We got to leave , “What we are right now” to “What you will become!” 

Always be aware of the surroundings, develop logical thinking!! Practice solving real life issue!! Try and keep thinking from various perspectives, try to view your problems from a higher level of existence, and don’t be panic when problems are put in your front!! Develop a thought like this ” These problems are put in front of me, because I only can solve that”, keep doing things which you love and love the things you do! 

All these things, the above I mentioned I had followed certain things, certain things which I really wished to follow but couldn’t follow may be because of various circumstances!! and one more thing I got to say to you!! circumstance always place the role of villain, so there is no use in blaming that, remember you are the hero!! and  you got the power you got the magic!! and believe in yourself. You are really powerfull beyond imaginations!! because all these things exist in the world are created by mind kind, see that immense potential try to make use of your hidden potential. No body can stop you!! Only you can win!

Ruby on Rails Installation

Steps to Install Ruby on Rails on Ubuntu with RVM

1 Install curl by sudo apt-get install curl

2 \curl -L https://get.rvm.io | bash -s stable

3 After the curl installation, we need to reload so exit out of the current shell&start a new      one.

4 source ~/.rvm/scripts/rvm

5 Inorder for working with RVM correctly check for it’s corresponding dependencies

6 Check for RVM dependencies  by rvm requirements.

Additional Dependencies:
# For Ruby / Ruby HEAD (MRI, Rubinius, & REE), install the following:
  ruby: /usr/bin/apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config

Just follow the instructions
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config


Next is installing ruby


 rvm install 1.9.3



After this Ruby will be installed

to set the default ruby version on your system you need to issue the below command

rvm use 1.9.3 --default

Install Ruby gems

 rvm rubygems current

Next and final we gonna install rails

gem install rails