Wednesday, 13 May 2015

Inheritance in Javascript

in Javascript inheritance can be achieved by using below two methods
1.Prototype chaining
2.Constructor stealing

1.prototype chaining

base=function()
{
this.name="base";
}

derived=function
{
this.marks="20";

this.prototype=new base();//creating inheritance using prototype
}

with above approach we face some problems while usig collectios like arrays.

Example


base=function()

{
this.name="base";
this.languages=["tel","eng","hindi"];
}

derived=function
{
this.marks="20";

this.prototype=new base();//creating inheritance using prototype
}

var  d1=new derived();
var d2=new derived();
d1.push("Kannada");

alert(d1.laguages) //prints tel,eng,hindi,kannada

alert(d2.languages) //also prints tel,eng,hindi,kannada

this is the problem with prototype chaiing when we use arrays, and try tomodify them,it will be reflected in all instances of the class.as when we modify an array, it points to a different location/reference


Constructor stealing


This is the second way of implementing inheritance in javascript where we invoke constructor of the parent class directly in the child class to perform inheritance.


base=function()
{
this.name="base";
}

derived=function
{
this.marks="20";

this.prototype=new base();//creating inheritance using prototype
}

with above approach we face some problems while usig collectios like arrays.

Example


base=function()

{
this.name="base";
this.languages=["tel","eng","hindi"];
}

derived=function
{
this.marks="20";

base.call(this);
}

var  d1=new derived();
var d2=new derived();
d1.push("Kannada");

alert(d1.laguages) //prints tel,eng,hindi,kannada

alert(d2.languages) // prints tel,eng,hindi 

so to avoid problems usig prototype chaiing, we can prefer constructor stealing.



Struts2 and Spring Integration

As we all now, struts2 can be integrated with other frameworks also. In this article,I will try to expalin how to integrate struts2 with spring framework.

To perform the integration, follow the below steps.

1.download the struts2-spring-plugin-x.y.z.jar file and add to class path file
2.In the web.config file configure the ContextLoaderListener listner as shown below.




<listener>
      <listener-class>
         org.springframework.web.context.ContextLoaderListener
      </listener-class>
 </listener>



The main purpose of this file is to load the applicatioContext.xml file. This file should be at the same level of web.xml file.

Friday, 24 April 2015

Spring Tutorials


Spring is a light weight framework used to develop complex java applications.
Advantages of spring are
1.It is very light weight when compared to EJBs
2.It can be easily integrated with other frameworks
3.No need of any web server while developing applications. As it provides some inbuilt containers.
4.Provides built in support for connection pooling and transaction management.

Spring provides below two containers

1.BeanFatory container.(Bean factory container is also called as IOC container or Core container)
2.ApplicationContextContainer

BeanFactory container :

1.BeanFactory container is also called as IOC Container or core container
2.It is implementation of BeanFactory class
2.It supports lazy loading. i.e. objects are injected only when they are invoked.
4.By default it considers all beans as singleton
5.

Search This Blog