Showing posts from June, 2015

What is IoC Container in Spring

Spring Container is core of Spring framework. Spring Container is responsible for instantiating beans, configure  and assemble them together. It manage their compete life-cycle from creation to destruction. The Container gets its instruction on what object to instantiate, configure and assemble by reading configuration metadata. The configuration  metadata is represented by XML, Java annotation and Java code. There are two types of IoC Container in Spring- BeanFactory ApplicationContext 1. BeanFactory : BeanFactory is simplest container. This is defined by org.springframework.bean.factory.BeanFactory interface. The most commonly used BeanFactory implementation is the XmlBeanFactory class . BeanFactory instantiate bean when getBean("") method is called. 2. ApplicationContext : ApplicationContext is more advanced container. This is defined by org.springframework.context.ApplicationContext interface.This interface extends org.springframework.bean.factory.BeanFactor

What is Dependency Injection

Dependency Injection is style of object configuration in which Object fields and collaborators are set by external entity. Dependency Injection is alternation to having object configure itself. Dependency Injection design pattern allows us to remove hard-coded  dependency and make our application loosely coupled, extensible and mantainable. Below class diagram explains Dependency Injection Traveler: public class Traveler { private Vehicle vehicle; public void setVehicle(Vehicle vehicle) { this.vehicle = vehicle; } public void travel(){ vehicle.start();; vehicle.stop(); } } Vehicle: public interface Vehicle { void start(); void run(); void stop(); } public class Bike implements Vehicle{ @Override public void start() { System.out.println("Bike is started"); } @Override public void run() { System.out.println("Bike is runnig"); } @Override public void stop() { System.out.println("Bike is stop

What is difference between HashMap and Hashtable classs

Synchronization & Thread Safe - All methods in Hashtable are synchronized and thread safe whereas methods in HashMap are not synchronized and it is not thread safe. HashMap is more faster than Hashtable because its methods are not synchronized. Null Key & Null Value - HashMap allows one null key and any number of null values whereas null key and null value is not allowed in Hashtable. Hashtable's put method will throw NullPointerException if null is used as key or value Iterating the values - HashMap uses Iterator to iterate over the values whereas Hashtable uses Enumerator. Super class & Lagacy - Hashtable is subclass of Dictionary class which is now obsolete in JDK1.7. HashMap is sub class of AbstractMap Note :-  It is better of externally synchronize a HashMap or Using concurrentMap implementation. (i.e. ConcurrentHashMap)