Saturday, December 7, 2013

Java Interview Questions and Answers


java interview questions and answer,java interview questions and answers,java interview questions and answers for experienced,java interview questions and answers pdf,java interview questions and answers for beginners,java interview questions and answers for experienced pdf,java interview questions and answers for qa,java interview questions and answers for 6 years experienced,java interview questions and answers for testers,java interview questions and answers pdf free download,java interview questions and answers book.




How to inject collections in spring IOC
Step1:we can take one pojoclass, then mentioned all values then provide setter and getter methods.
Step2::next pojoclass initialized in spring-config.xml.
Step3::finally take main class then get values.

Lets take small example::
package balu.javainterviewquestionsguru.blogspot.in;
import  java .util. *;
public class JavaCollections
{
 List addreslist;
 Set addresset;
 Map addresmap;
 Properties addprops;
//provide setter and getter methods
Public void  setAddreslist(addlist){
this.addlist=list;
}
Public list getAddreslist(){
System.out.println(“list Elements:”+ addlist’);

return addlist;
}
// a setter method to set setvalues and get values
Public void  setAddresSet(addset){
this.addSet=set;
}
Public Set getAddresSet(){
System.out.println(“set Elements:”+ addset’);

return addset;
}

/ a setter method to set mapvalues and get values
Public void  setAddresMap(addMap){
this.addMap=map;
}
Public Map getAddresMap(){
System.out.println(“map Elements:”+ addmap’);

return addset;
}


/ a setter method to set mapvalues and get values
Public void  setAddresMap(addMap){
this.addMap=map;
}
Public Map getAddresMap(){
System.out.println(“map Elements:”+ addmap’);

return addMap;
}


/ a setter method to set propertiesvalues and get values
Public void  setAddresproperties(addprops){
this.addprops=props;
}
Public Map getAddresproperties(){
System.out.println(“properties Elements:”+ addprops’);

return addprops;
}
}

main.java:::
package com.balu.javainterviewquestionsguru.blogspot.in;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class mainApp{
public static void main(String args[]){
ApplicationContext cxt= new ClassPathXmlApplicationContext(“Beans.xml”);
javaCollection jc =(javaCollcetion)cxt.getBean(“JavaCollection”);
jc.getAddList();
jc.getAddSet();
jc.getAddMap();
jc.getAddProps();
}
}

Beans.xml::
<? Xml  version=”1”>
<bean id =”javacollection”   class=”balu.javainterviewquestionsguru.blogspot.in”>
//results setAddres List
<property name=”addlist”>
<list><value>india</value><value>ap</value></list></property>
//results set Addres set
<property name=”addset”>
<set><value>usa</value><value>hyd</value></set></property>
// results set  Addres Map
<property name=”addmap”>
<map><entry key=”1”  value=”jermany”/><entry key=”2”  value=”goa”/></map></property>
//results set Addres props
<property name=”addprops”><props></props><prop key=”one”>balu</prop><prop key=”two”>pinky</prop></property>

o/p::
list values(duplicate values allowed)india,ap.
set values(duplicate not allowed)usa,hyd
map values(key,value anytype)1=jermany,2=goa.
props values(key,value both strings)one=balu,two=pinky





No comments:

Post a Comment