বুধবার, ২৭ জুন, ২০১২

Spring framework interview questions


Spring framework interview questions :


Question1: What is IOC or inversion of control?

Ans: This question is first step towards spring and mostly interviewer starts from this question. As the name implies inversion of control means now we have inverted the control of creating the object from our own using new operator to container or framework
Now it’s the responsibility of container to create object as required.
We maintain one xml file where we configure our components, services, all the classes and their property. We just need to mention which service is needed by which component and container will create the object for us. This concept is known as dependency injection because all object dependency (resources) is injected into it by framework.

Example:
 
        
    
In this example CreateNewStockAccont class contain getter and setter for newBid and container will instantiate newBid and set the value automatically when it is used.


Question 2: Explain Bean-LifeCycle.


Ans: Spring framework is based on IOC so we call it as IOC container also So Beans reside inside the IOC container beans are nothing but Plain old java object (POJO).
Following steps explain their lifecycle inside container.
1. Container will look the bean definition inside configuration file (eg.bean.xml).
2 using reflection container will create the object and if any property is defined inside the bean definition then it will also be set.
3. If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean’s ID.
4. If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself.
5. If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization () methods will be called before the properties for the Bean are set.
6. If an init-method is specified for the bean, it will be called.
7. If the Bean class implements the DisposableBean interface, then the method destroy() will be called when the Application no longer needs the bean reference.
8. If the Bean definition in the Configuration file contains a 'destroy-method' attribute, then the corresponding method definition in the Bean class will be called.

Question 3: what is Bean Factory, have you used XMLBean factory?

Ans: BeanFactory is factory Pattern which is based on IoC.it is used to make a clear separation between application configuration and dependency from actual code.
XmlBeanFactory is one of the implementation of bean Factory which we have used in our project.
org.springframework.beans.factory.xml.XmlBeanFactory is used to creat bean instance defined in our xml file.

BeanFactory factory = new XmlBeanFactory(new FileInputStream("beans.xml"));
Or
ClassPathResource resorce = new ClassPathResource("beans.xml");
XmlBeanFactory factory = new XmlBeanFactory(resorce);

Question 4: what are the difference between BeanFactory and ApplicationContext in spring?
Ans: This one is very popular spring interview question and often asks in entry level interview. ApplicationContext is preferred way of using spring because of functionality provided by it and interviewer wanted to check whether you are familiar with it or not.



ApplicationContext.


BeanFactory
Here we can have more than one config files possible
In this only one config file or .xml file
Application contexts can publish events to beans that are registered as listeners
Doesn’t support.
Support internationalization (I18N) messages
It’s not
Support application lifecycle events, and validation.
Doesn’t support.
Support  many enterprise services such JNDI access, EJB integration, remoting
Doesn’t support.



Question 5: What are different modules in spring?

Ans: spring have seven core modules
1.      The Core container module
2.      Application context module
3.      AOP module (Aspect Oriented Programming)
4.      JDBC abstraction and DAO module
5.      O/R mapping integration module (Object/Relational)
6.      Web module

রবিবার, ২৪ জুন, ২০১২

Mobile app for non native


They can be categorized into three groups:

1.  Use another language and compiles a native app in one or more platforms.
  • Titanium Appcelerator (html/js/css -> iPhone/Android/Blackberry)
  • Ansca Mobile (ActionScript, Lua -> iPhone/Android)

2. Embed your native platform language to expose certain native features to web app.
  • PhoneGap
  • QuickConnect

3.  Create Touch device optimized/native look and feel web apps.
  • Sencha
  • jQTouch
  • xui
  • PastryKit
  • jQuery Mobile

সোমবার, ১৮ জুন, ২০১২

Forward vs Redirect in servlet

Forward vs Redirect in servlet

 Forward

    * a forward is performed internally by the servlet
    * the browser is completely unaware that it has taken place, so its original URL remains intact
    * any browser reload of the resulting page will simple repeat the original request, with the original URL

Redirect

    * a redirect is a two step process, where the web application instructs the browser to fetch a second URL, which differs from the original
    * a browser reload of the second URL will not repeat the original request, but will rather fetch the second URL
    * redirect is marginally slower than a forward, since it requires two browser requests, not one
    * objects placed in the original request scope are not available to the second request