You are on page 1of 14

7/11/2016 69SpringInterviewQuestionsandAnswersTheULTIMATEList

KnowledgeBase Resources Deals JobBoard JoinUs About Search...

ANDROID JAVA JVM LANGUAGES SOFTWARE DEVELOPMENT AGILE CAREER COMMUNICATIONS DEVOPS META JCG

HomeJavaEnterpriseJava69SpringInterviewQuestionsandAnswersTheULTIMATEList(PDFDownload)

ABOUT THEODORA FRAGKOULI

TheodorahasgraduatedfromComputerEngineeringandInformaticsDepartmentintheUniversityofPatras.ShealsoholdsaMaster
degreeinEconomicsfromtheNationalandTechnicalUniversityofAthens.Duringherstudiesshehasbeeninvolvedwithalarge
numberofprojectsrangingfromprogrammingandsoftwareengineeringtotelecommunications,hardwaredesignandanalysis.She
worksasajuniorSoftwareEngineerinthetelecommunicationssectorwheresheismainlyinvolvedwithprojectsbasedonJavaand
BigDatatechnologies.

69 Spring Interview Questions and Answers The ULTIMATE List (PDF


Download)
Postedby :TheodoraFragk ouli inEnterpriseJav a May 2nd,2014

Thisisasummaryofsomeofthemost
importantquestionsconcerningtheSpring
Framework,thatyoumaybeaskedtoanswer
inanintervieworinaninterviewtest
procedure!Thereisnoneedtoworryforyour
nextinterviewtest,becauseJavaCodeGeeks
arehereforyou!

Themajorityofthethingsyoumaybeaskedis
NEWSLETTER
collectedinthelistbelow.Allcoremodules,
frombasicSpringfunctionalitysuchasSpring
Beans,uptoSpringMVCframeworkare
presentedanddescribedinshort.Aftercheckingtheinterviewquestions,youshould 163133insidersarealreadyenjoying
checkourSpringTutorialspage. weeklyupdatesandcomplimentary
whitepapers!
So,letsgo! Jointhemnowtogainexclusive
accesstothelatestnewsintheJavaworld,
JavaInterviewComingUp? aswellasinsightsaboutAndroid,Scala,
Groovyandotherrelatedtechnologies.

SubscribetoournewsletteranddownloadtheUltimateSpring Emailaddress:
interviewquestionsandanswerscollectionrightnow!
Youremailaddress

InordertogetyoupreparedforyournextJavaInterview,wehavecompiledahugelistof
relevantQuestionsandtheirrespectiveAnswers.Besidesstudyingthemonlineyoumay Signup
downloadtheeBookinPDFformat!

Emailaddress:
JOIN US
Youremailaddress
With 1,240,600 monthly
uniquevisitorsandover
Signup
500 authorsweare
placedamongthetopJava
relatedsitesaround.
Constantlybeingonthe
Tip lookoutforpartnerswe
AreyoulookingforcareeropportunitiesinJava? encourageyoutojoinus.
SoIfyouhaveablogwith

uniqueandinterestingcontentthenyoushould
VisitourJobBoardtosearchandreviewahandpickedselectionofJavajobsforITprofessionalsaroundtheworld. checkoutourJCGpartnersprogram.Youcanalso
beaguestwriterforJavaCodeGeeksandhone
yourwritingskills!
AdditionallyyoucanaddyourresumetoourResumesBoardpromotingyourskillstoawiderangeofJavajobrecruitersaroundtheworld.

TableofContents
Springoverview
DependencyInjection
SpringBeans

https://www.javacodegeeks.com/2014/05/springinterviewquestionsandanswers.html 1/14
7/11/2016 69SpringInterviewQuestionsandAnswersTheULTIMATEList
SpringBeans
SpringAnnotations
SpringDataAccess
SpringAspectOrientedProgramming(AOP)
SpringModelViewController(MVC)

Springoverview
1.WhatisSpring?
SpringisanopensourcedevelopmentframeworkforEnterpriseJava.ThecorefeaturesoftheSpringFrameworkcanbeusedindeveloping
anyJavaapplication,butthereareextensionsforbuildingwebapplicationsontopoftheJavaEEplatform.Springframeworktargetstomake
JavaEEdevelopmenteasiertouseandpromotegoodprogrammingpracticebyenablingaPOJObasedprogrammingmodel.

2.WhatarebenefitsofSpringFramework?
Lightweight:Springislightweightwhenitcomestosizeandtransparency.Thebasicversionofspringframeworkisaround2MB.
Inversionofcontrol(IOC):LoosecouplingisachievedinSpring,withtheInversionofControltechnique.Theobjectsgivetheir
dependenciesinsteadofcreatingorlookingfordependentobjects.
Aspectoriented(AOP):SpringsupportsAspectorientedprogrammingandseparatesapplicationbusinesslogicfromsystemservices.
Container:Springcontainsandmanagesthelifecycleandconfigurationofapplicationobjects.
MVCFramework:SpringswebframeworkisawelldesignedwebMVCframework,whichprovidesagreatalternativetoweb
frameworks.
TransactionManagement:Springprovidesaconsistenttransactionmanagementinterfacethatcanscaledowntoalocaltransactionand
CAREER OPPORTUNITIES
scaleuptoglobaltransactions(JTA).
ExceptionHandling:SpringprovidesaconvenientAPItotranslatetechnologyspecificexceptions(thrownbyJDBC,Hibernate,orJDO)into EntryLevelSoftwareDeveloperEmploymentTrust
consistent,uncheckedexceptions. Seattle,WA
Jun,10
JavaDeveloperORACLECorporation
3.WhicharetheSpringframeworkmodules? Reston,VA
Jun,29
ThebasicmodulesoftheSpringframeworkare: SoftwareEngineer0703Earning$257,000EMF
Industries
Coremodule Reston,VA
Jul,09
Beanmodule SoftwareEngineer0708Earning$257,000EMF
Contextmodule Industries
Herndon,VA
ExpressionLanguagemodule Jul,09
JDBCmodule JavaDeveloperGreenHealthcareSolutions
Fairfax,VA
ORMmodule Jul,06
OXMmodule JavaDeveloperPyramidSystems,Inc.
Fairfax,VA
JavaMessagingService(JMS)module Apr,29
Transactionmodule JavaDeveloper(entrylevel)Workforce
OpportunityServices(WOS)
Webmodule Herndon,VA
WebServletmodule Jul,07
FederalEntryLevelTrainingProgramTechnology
WebStrutsmodule EngineerAnalyst+Accenture
WebPortletmodule Arlington,VA
May,06
ConsultantJavaEngineerHedgeFundCaspianOne
4.ExplaintheCoreContainer(Applicationcontext)module NewYork,NY
Jun,28
ThisisthebasicSpringmodule,whichprovidesthefundamentalfunctionalityoftheSpringframework. JavaDeveloperPiperCompanies
Vienna,VA
BeanFactory
Jun,28
1 2 ... 6585
istheheartofanyspringbasedapplication.Springframeworkwasbuiltonthetopofthismodule,whichmakestheSpringcontainer.

Freelance

5.BeanFactoryBeanFactoryimplementationexample Keyword... Fulltime

Intership
A Location...
Parttime
BeanFactory
Country...
All

isanimplementationofthefactorypatternthatappliesInversionofControltoseparatetheapplicationsconfigurationanddependenciesfrom FilterResults
theactualapplicationcode.
jobsby

Themostcommonlyused
BeanFactory

implementationisthe
XmlBeanFactory

class.

6.XMLBeanFactory
Themostusefuloneis
org.springframework.beans.factory.xml.XmlBeanFactory

,whichloadsitsbeansbasedonthedefinitionscontainedinanXMLfile.ThiscontainerreadstheconfigurationmetadatafromanXMLfileand
https://www.javacodegeeks.com/2014/05/springinterviewquestionsandanswers.html 2/14
7/11/2016 69SpringInterviewQuestionsandAnswersTheULTIMATEList
,whichloadsitsbeansbasedonthedefinitionscontainedinanXMLfile.ThiscontainerreadstheconfigurationmetadatafromanXMLfileand
usesittocreateafullyconfiguredsystemorapplication.

7.ExplaintheAOPmodule
TheAOPmoduleisusedfordevelopingaspectsforourSpringenabledapplication.MuchofthesupporthasbeenprovidedbytheAOPAlliance
inordertoensuretheinteroperabilitybetweenSpringandotherAOPframeworks.Thismodulealsointroducesmetadataprogrammingto
Spring.

8.ExplaintheJDBCabstractionandDAOmodule
WiththeJDBCabstractionandDAOmodulewecanbesurethatwekeepupthedatabasecodecleanandsimple,andpreventproblemsthat
resultfromafailuretoclosedatabaseresources.Itprovidesalayerofmeaningfulexceptionsontopoftheerrormessagesgivenbyseveral
databaseservers.ItalsomakesuseofSpringsAOPmoduletoprovidetransactionmanagementservicesforobjectsinaSpringapplication.

9.Explaintheobject/relationalmappingintegrationmodule
Springalsosupportsforusingofanobject/relationalmapping(ORM)tooloverstraightJDBCbyprovidingtheORMmodule.Springprovides
supporttotieintoseveralpopularORMframeworks,includingHibernate,JDO,andiBATISSQLMaps.Springstransactionmanagement
supportseachoftheseORMframeworksaswellasJDBC.

10.Explainthewebmodule
TheSpringwebmoduleisbuiltontheapplicationcontextmodule,providingacontextthatisappropriateforwebbasedapplications.This
modulealsocontainssupportforseveralweborientedtaskssuchastransparentlyhandlingmultipartrequestsforfileuploadsand
programmaticbindingofrequestparameterstoyourbusinessobjects.ItalsocontainsintegrationsupportwithJakartaStruts.

11.ExplaintheSpringMVCmodule
MVCframeworkisprovidedbySpringforbuildingwebapplications.SpringcaneasilybeintegratedwithotherMVCframeworks,butSprings
MVCframeworkisabetterchoice,sinceitusesIoCtoprovideforacleanseparationofcontrollerlogicfrombusinessobjects.WithSpring
MVCyoucandeclarativelybindrequestparameterstoyourbusinessobjects.

12.Springconfigurationfile
SpringconfigurationfileisanXMLfile.Thisfilecontainstheclassesinformationanddescribeshowtheseclassesareconfiguredand
introducedtoeachother.

13.WhatisSpringIoCcontainer?
TheSpringIoCisresponsibleforcreatingtheobjects,managingthem(withdependencyinjection(DI)),wiringthemtogether,configuring
them,asalsomanagingtheircompletelifecycle.

14.WhatarethebenefitsofIOC?
IOCordependencyinjectionminimizestheamountofcodeinanapplication.Itmakeseasytotestapplications,sincenosingletonsorJNDI
lookupmechanismsarerequiredinunittests.Loosecouplingispromotedwithminimaleffortandleastintrusivemechanism.IOCcontainers
supporteagerinstantiationandlazyloadingofservices.

15.WhatarethecommonimplementationsoftheApplicationContext?
TheFileSystemXmlApplicationContextcontainerloadsthedefinitionsofthebeansfromanXMLfile.ThefullpathoftheXMLbean
configurationfilemustbeprovidedtotheconstructor.
TheClassPathXmlApplicationContextcontaineralsoloadsthedefinitionsofthebeansfromanXMLfile.Here,youneedtoset

CLASSPATH

properlybecausethiscontainerwilllookbeanconfigurationXMLfilein
CLASSPATH

.
TheWebXmlApplicationContext:containerloadstheXMLfilewithdefinitionsofallbeansfromwithinawebapplication.

16.WhatisthedifferencebetweenBeanFactoryandApplicationContext?
Applicationcontextsprovideameansforresolvingtextmessages,agenericwaytoloadfileresources(suchasimages),theycanpublish
eventstobeansthatareregisteredaslisteners.Inaddition,operationsonthecontainerorbeansinthecontainer,whichhavetobehandledin
aprogrammaticfashionwithabeanfactory,canbehandleddeclarativelyinanapplicationcontext.Theapplicationcontextimplements
MessageSource

,aninterfaceusedtoobtainlocalizedmessages,withtheactualimplementationbeingpluggable.

17.WhatdoesaSpringapplicationlooklike?
Aninterfacethatdefinesthefunctions.
Theimplementationthatcontainsproperties,itssetterandgettermethods,functionsetc.,
https://www.javacodegeeks.com/2014/05/springinterviewquestionsandanswers.html 3/14
7/11/2016 69SpringInterviewQuestionsandAnswersTheULTIMATEList
Theimplementationthatcontainsproperties,itssetterandgettermethods,functionsetc.,
SpringAOP
TheSpringconfigurationXMLfile.
Clientprogramthatusesthefunction

DependencyInjection
18.WhatisDependencyInjectioninSpring?
DependencyInjection,anaspectofInversionofControl(IoC),isageneralconcept,anditcanbeexpressedinmanydifferentways.This
conceptsaysthatyoudonotcreateyourobjectsbutdescribehowtheyshouldbecreated.Youdontdirectlyconnectyourcomponentsand
servicestogetherincodebutdescribewhichservicesareneededbywhichcomponentsinaconfigurationfile.Acontainer(theIOCcontainer)
isthenresponsibleforhookingitallup.

19.WhatarethedifferenttypesofIoC(dependencyinjection)?
Constructorbaseddependencyinjection:ConstructorbasedDIisaccomplishedwhenthecontainerinvokesaclassconstructorwitha
numberofarguments,eachrepresentingadependencyonotherclass.
Setterbaseddependencyinjection:SetterbasedDIisaccomplishedbythecontainercallingsettermethodsonyourbeansafter
invokinganoargumentconstructorornoargumentstaticfactorymethodtoinstantiateyourbean.

20.WhichDIwouldyousuggestConstructorbasedorsetterbasedDI?
YoucanusebothConstructorbasedandSetterbasedDependencyInjection.Thebestsolutionisusingconstructorargumentsformandatory
dependenciesandsettersforoptionaldependencies.

SpringBeans
21.WhatareSpringbeans?
TheSpringBeansareJavaObjectsthatformthebackboneofaSpringapplication.Theyareinstantiated,assembled,andmanagedbythe
SpringIoCcontainer.Thesebeansarecreatedwiththeconfigurationmetadatathatissuppliedtothecontainer,forexample,intheformof
XML
<bean/>

definitions.

Beansdefinedinspringframeworkaresingletonbeans.Thereisanattributeinbeantagnamed
"singleton"

ifspecifiedtruethenbeanbecomessingletonandifsettofalsethenthebeanbecomesaprototypebean.Bydefaultitissettotrue.So,allthe
beansinspringframeworkarebydefaultsingletonbeans.

22.WhatdoesaSpringBeandefinitioncontain?
ASpringBeandefinitioncontainsallconfigurationmetadatawhichisneededforthecontainertoknowhowtocreateabean,itslifecycle
detailsanditsdependencies.

23.HowdoyouprovideconfigurationmetadatatotheSpringContainer?
TherearethreeimportantmethodstoprovideconfigurationmetadatatotheSpringContainer:

XMLbasedconfigurationfile.
Annotationbasedconfiguration
Javabasedconfiguration

24.Howdoyoudefinethescopeofabean?

Whendefininga
<bean>

inSpring,wecanalsodeclareascopeforthebean.Itcanbedefinedthroughthe
scope

attributeinthebeandefinition.Forexample,whenSpringhastoproduceanewbeaninstanceeachtimeoneisneeded,thebeans
scope

attributetobe
prototype

.Ontheotherhand,whenthesameinstanceofabeanmustbereturnedbySpringeverytimeitisneeded,thethebean

https://www.javacodegeeks.com/2014/05/springinterviewquestionsandanswers.html 4/14
7/11/2016 69SpringInterviewQuestionsandAnswersTheULTIMATEList
scope

attributemustbesetto
singleton

25.ExplainthebeanscopessupportedbySpring
TherearefivescopedprovidedbytheSpringFrameworksupportsfollowingfivescopes:

Insingletonscope,SpringscopesthebeandefinitiontoasingleinstanceperSpringIoCcontainer.
Inprototypescope,asinglebeandefinitionhasanynumberofobjectinstances.
Inrequestscope,abeanisdefinedtoanHTTPrequest.ThisscopeisvalidonlyinawebawareSpringApplicationContext.
Insessionscope,abeandefinitionisscopedtoanHTTPsession.ThisscopeisalsovalidonlyinawebawareSpringApplicationContext.
Inglobalsessionscope,abeandefinitionisscopedtoaglobalHTTPsession.ThisisalsoacaseusedinawebawareSpring
ApplicationContext.

ThedefaultscopeofaSpringBeanis
Singleton

26.AreSingletonbeansthreadsafeinSpringFramework?
No,singletonbeansarenotthreadsafeinSpringframework.

27.ExplainBeanlifecycleinSpringframework
ThespringcontainerfindsthebeansdefinitionfromtheXMLfileandinstantiatesthebean.
Springpopulatesallofthepropertiesasspecifiedinthebeandefinition(DI).
Ifthebeanimplements
BeanNameAware

interface,springpassesthebeansidto
setBeanName()

method.
IfBeanimplements

BeanFactoryAware

interface,springpassesthe
beanfactory

to
setBeanFactory()

method.
Ifthereareanybean
BeanPostProcessors

associatedwiththebean,Springcalls
postProcesserBeforeInitialization()

method.
Ifthebeanimplements
IntializingBean

,its
afterPropertySet()

methodiscalled.Ifthebeanhasinitmethoddeclaration,thespecifiedinitializationmethodiscalled.
IfthereareanyBeanPostProcessorsassociatedwiththebean,theirpostProcessAfterInitialization()methodswillbecalled.
Ifthebeanimplements
DisposableBean

,itwillcallthe
destroy()

method.

28.Whicharetheimportantbeanslifecyclemethods?Canyouoverride
them?
https://www.javacodegeeks.com/2014/05/springinterviewquestionsandanswers.html 5/14
7/11/2016 69SpringInterviewQuestionsandAnswersTheULTIMATEList
them?
Therearetwoimportantbeanlifecyclemethods.Thefirstoneis
setup

whichiscalledwhenthebeanisloadedintothecontainer.Thesecondmethodisthe
teardown

methodwhichiscalledwhenthebeanisunloadedfromthecontainer.
The
bean

taghastwoimportantattributes(
init-method

and
destroy-method

)withwhichyoucandefineyourowncustominitializationanddestroymethods.Therearealsothecorrespondiveannotations(
@PostConstruct

and
@PreDestroy

).

29.WhatareinnerbeansinSpring?
Whenabeanisonlyusedasapropertyofanotherbeanitcanbedeclaredasaninnerbean.SpringsXMLbasedconfigurationmetadata
providestheuseof
<bean/>

elementinsidethe

<property/>

or
<constructor-arg/>

elementsofabeandefinition,inordertodefinethesocalledinnerbean.Innerbeansarealwaysanonymousandtheyarealwaysscopedas
prototypes.

30.HowcanyouinjectaJavaCollectioninSpring?
Springoffersthefollowingtypesofcollectionconfigurationelements:

The
<list>

typeisusedforinjectingalistofvalues,inthecasethatduplicatesareallowed.
The
<set>

typeisusedforwiringasetofvaluesbutwithoutanyduplicates.
The
<map>

typeisusedtoinjectacollectionofnamevaluepairswherenameandvaluecanbeofanytype.
The
<props>

typecanbeusedtoinjectacollectionofnamevaluepairswherethenameandvaluearebothStrings.

31.Whatisbeanwiring?
Wiring,orelsebeanwiringisthecasewhenbeansarecombinedtogetherwithintheSpringcontainer.Whenwiringbeans,theSpring
containerneedstoknowwhatbeansareneededandhowthecontainershouldusedependencyinjectiontotiethemtogether.

32.Whatisbeanautowiring?
TheSpringcontainerisabletoautowirerelationshipsbetweencollaboratingbeans.ThismeansthatitispossibletoautomaticallyletSpring
resolvecollaborators(otherbeans)forabeanbyinspectingthecontentsofthe
BeanFactory

withoutusing

https://www.javacodegeeks.com/2014/05/springinterviewquestionsandanswers.html 6/14
7/11/2016 69SpringInterviewQuestionsandAnswersTheULTIMATEList
<constructor-arg>

and
<property>

elements.

33.Explaindifferentmodesofautowiring?
TheautowiringfunctionalityhasfivemodeswhichcanbeusedtoinstructSpringcontainertouseautowiringfordependencyinjection:

no:Thisisdefaultsetting.Explicitbeanreferenceshouldbeusedforwiring.
byName:Whenautowiring
byName

,theSpringcontainerlooksatthepropertiesofthebeansonwhich
autowire

attributeissetto
byName

intheXMLconfigurationfile.Itthentriestomatchandwireitspropertieswiththebeansdefinedbythesamenamesintheconfiguration
file.
byType:Whenautowiringby
datatype

,theSpringcontainerlooksatthepropertiesofthebeansonwhich
autowire

attributeissetto
byType

intheXMLconfigurationfile.Itthentriestomatchandwireapropertyifitstypematcheswithexactlyoneofthebeansnamein
configurationfile.Ifmorethanonesuchbeansexist,afatalexceptionisthrown.
constructor:Thismodeissimilarto
byType

,buttypeappliestoconstructorarguments.Ifthereisnotexactlyonebeanoftheconstructorargumenttypeinthecontainer,afatalerror
israised.
autodetect:Springfirsttriestowireusingautowirebyconstructor,ifitdoesnotwork,Springtriestoautowireby
byType

34.Aretherelimitationswithautowiring?
Limitationsofautowiringare:

Overriding:Youcanstillspecifydependenciesusing
<constructor-arg>

and
<property>

settingswhichwillalwaysoverrideautowiring.
Primitivedatatypes:Youcannotautowiresimplepropertiessuchasprimitives,Strings,andClasses.
Confusingnature:Autowiringislessexactthanexplicitwiring,soifpossiblepreferusingexplicitwiring.

35.CanyouinjectnullandemptystringvaluesinSpring?
Yes,youcan.

SpringAnnotations
36.WhatisSpringJavaBasedConfiguration?Givesomeannotation
example.
JavabasedconfigurationoptionenablesyoutowritemostofyourSpringconfigurationwithoutXMLbutwiththehelpoffewJavabased
annotations.
Anexampleisthe
@Configuration

annotation,thatindicatesthattheclasscanbeusedbytheSpringIoCcontainerasasourceofbeandefinitions.Anotherexampleisthe
https://www.javacodegeeks.com/2014/05/springinterviewquestionsandanswers.html 7/14
7/11/2016 69SpringInterviewQuestionsandAnswersTheULTIMATEList
annotation,thatindicatesthattheclasscanbeusedbytheSpringIoCcontainerasasourceofbeandefinitions.Anotherexampleisthe
@Bean

annotatedmethodthatwillreturnanobjectthatshouldberegisteredasabeanintheSpringapplicationcontext.

37.WhatisAnnotationbasedcontainerconfiguration?
AnalternativetoXMLsetupsisprovidedbyannotationbasedconfigurationwhichreliesonthebytecodemetadataforwiringupcomponents
insteadofanglebracketdeclarations.InsteadofusingXMLtodescribeabeanwiring,thedevelopermovestheconfigurationintothe
componentclassitselfbyusingannotationsontherelevantclass,method,orfielddeclaration.

38.Howdoyouturnonannotationwiring?
AnnotationwiringisnotturnedonintheSpringcontainerbydefault.InordertouseannotationbasedwiringwemustenableitinourSpring
configurationfilebyconfiguring
<context:annotation-config/>

element.

39.@Requiredannotation
Thisannotationsimplyindicatesthattheaffectedbeanpropertymustbepopulatedatconfigurationtime,throughanexplicitpropertyvalueina
beandefinitionorthroughautowiring.Thecontainerthrows
BeanInitializationException

iftheaffectedbeanpropertyhasnotbeenpopulated.

40.@Autowiredannotation
The
@Autowired

annotationprovidesmorefinegrainedcontroloverwhereandhowautowiringshouldbeaccomplished.Itcanbeusedtoautowirebeanonthe
settermethodjustlike
@Required

annotation,ontheconstructor,onapropertyorpnmethodswitharbitrarynamesand/ormultiplearguments.

41.@Qualifierannotation
Whentherearemorethanonebeansofthesametypeandonlyoneisneededtobewiredwithaproperty,the
@Qualifier

annotationisusedalongwith
@Autowired

annotationtoremovetheconfusionbyspecifyingwhichexactbeanwillbewired.

SpringDataAccess
42.HowcanJDBCbeusedmoreefficientlyintheSpringframework?
WhenusingtheSpringJDBCframeworktheburdenofresourcemanagementanderrorhandlingisreduced.Sodevelopersonlyneedtowrite
thestatementsandqueriestogetthedatatoandfromthedatabase.JDBCcanbeusedmoreefficientlywiththehelpofatemplateclass
providedbySpringframework,whichisthe
JdbcTemplate

(examplehere).

43.JdbcTemplate
JdbcTemplate

classprovidesmanyconveniencemethodsfordoingthingssuchasconvertingdatabasedataintoprimitivesorobjects,executingpreparedand
callablestatements,andprovidingcustomdatabaseerrorhandling.

44.SpringDAOsupport
TheDataAccessObject(DAO)supportinSpringisaimedatmakingiteasytoworkwithdataaccesstechnologieslikeJDBC,HibernateorJDO
inaconsistentway.Thisallowsustoswitchbetweenthepersistencetechnologiesfairlyeasilyandtocodewithoutworryingaboutcatching
exceptionsthatarespecifictoeachtechnology.

https://www.javacodegeeks.com/2014/05/springinterviewquestionsandanswers.html 8/14
7/11/2016 69SpringInterviewQuestionsandAnswersTheULTIMATEList

45.WhatarethewaystoaccessHibernatebyusingSpring?
TherearetwowaystoaccessHibernatewithSpring:

InversionofControlwithaHibernateTemplateandCallback.
Extending
HibernateDAOSupport

andApplyinganAOPInterceptornode.

46.ORMsSpringsupport
SpringsupportsthefollowingORMs:

Hibernate
iBatis
JPA(JavaPersistenceAPI)
TopLink
JDO(JavaDataObjects)
OJB

47.HowcanweintegrateSpringandHibernateusing
HibernateDaoSupport?
UseSprings
SessionFactory

called

LocalSessionFactory

.Theintegrationprocessisof3steps:

ConfiguretheHibernateSessionFactory
ExtendaDAOImplementationfrom
HibernateDaoSupport

WireinTransactionSupportwithAOP

48.TypesofthetransactionmanagementSpringsupport
Springsupportstwotypesoftransactionmanagement:

Programmatictransactionmanagement:Thismeansthatyouhavemanagedthetransactionwiththehelpofprogramming.Thatgives
youextremeflexibility,butitisdifficulttomaintain.
Declarativetransactionmanagement:Thismeansyouseparatetransactionmanagementfromthebusinesscode.Youonlyuse
annotationsorXMLbasedconfigurationtomanagethetransactions.

49.WhatarethebenefitsoftheSpringFrameworkstransaction
management?
ItprovidesaconsistentprogrammingmodelacrossdifferenttransactionAPIssuchasJTA,JDBC,Hibernate,JPA,andJDO.
ItprovidesasimplerAPIforprogrammatictransactionmanagementthananumberofcomplextransactionAPIssuchasJTA.
Itsupportsdeclarativetransactionmanagement.
ItintegratesverywellwithSpringsvariousdataaccessabstractions.

50.WhichTransactionmanagementtypeismorepreferable?
MostusersoftheSpringFrameworkchoosedeclarativetransactionmanagementbecauseitistheoptionwiththeleastimpactonapplication
code,andhenceismostconsistentwiththeidealsofanoninvasivelightweightcontainer.Declarativetransactionmanagementispreferable
overprogrammatictransactionmanagementthoughitislessflexiblethanprogrammatictransactionmanagement,whichallowsyoutocontrol
transactionsthroughyourcode.

SpringAspectOrientedProgramming(AOP)
51.ExplainAOP
Aspectorientedprogramming,orAOP,isaprogrammingtechniquethatallowsprogrammerstomodularizecrosscuttingconcerns,orbehavior
thatcutsacrossthetypicaldivisionsofresponsibility,suchasloggingandtransactionmanagement.

52.Aspect
ThecoreconstructofAOPistheaspect,whichencapsulatesbehaviorsaffectingmultipleclassesintoreusablemodules.Itiaamodulewhich
hasasetofAPIsprovidingcrosscuttingrequirements.Forexample,aloggingmodulewouldbecalledAOPaspectforlogging.Anapplication
canhaveanynumberofaspectsdependingontherequirement.InSpringAOP,aspectsareimplementedusingregularclassesannotatedwith
the

https://www.javacodegeeks.com/2014/05/springinterviewquestionsandanswers.html 9/14
7/11/2016 69SpringInterviewQuestionsandAnswersTheULTIMATEList
@Aspect

annotation(
@AspectJ

style).

53.Whatisthedifferencebetweenconcernandcrosscuttingconcernin
SpringAOP
TheConcernisbehaviorwewanttohaveinamoduleofanapplication.AConcernmaybedefinedasafunctionalitywewanttoimplement.
Thecrosscuttingconcernisaconcernwhichisapplicablethroughouttheapplicationanditaffectstheentireapplication.Forexample,logging,
securityanddatatransferaretheconcernswhichareneededinalmosteverymoduleofanapplication,hencetheyarecrosscuttingconcerns.

54.Joinpoint
ThejoinpointrepresentsapointinanapplicationwherewecanpluginanAOPaspect.Itistheactualplaceintheapplicationwhereanaction
willbetakenusingSpringAOPframework.


55.Advice
Theadviceistheactualactionthatwillbetakeneitherbeforeorafterthemethodexecution.Thisisactualpieceofcodethatisinvokedduring
theprogramexecutionbytheSpringAOPframework.

Springaspectscanworkwithfivekindsofadvice:

before:Runadvicebeforetheamethodexecution.
after:Runadviceaftertheamethodexecutionregardlessofitsoutcome.
afterreturning:Runadviceaftertheamethodexecutiononlyifmethodcompletessuccessfully.
afterthrowing:Runadviceaftertheamethodexecutiononlyifmethodexitsbythrowinganexception.
around:Runadvicebeforeandaftertheadvisedmethodisinvoked.

56.Pointcut
Thepointcutisasetofoneormorejoinpointswhereanadviceshouldbeexecuted.Youcanspecifypointcutsusingexpressionsorpatterns.

57.WhatisIntroduction?
AnIntroductionallowsustoaddnewmethodsorattributestoexistingclasses.

58.WhatisTargetobject?
Thetargetobjectisanobjectbeingadvisedbyoneormoreaspects.Itwillalwaysbeaproxyobject.Itisalsoreferredtoastheadvised
object.

59.WhatisaProxy?
Aproxyisanobjectthatiscreatedafterapplyingadvicetoatargetobject.Whenyouthinkofclientobjectsthetargetobjectandtheproxy
objectarethesame.

60.WhatarethedifferenttypesofAutoProxying?
BeanNameAutoProxyCreator
DefaultAdvisorAutoProxyCreator
Metadataautoproxying

61.WhatisWeaving?Whatarethedifferentpointswhereweavingcanbe
applied?
Weavingistheprocessoflinkingaspectswithotherapplicationtypesorobjectstocreateanadvisedobject.
Weavingcanbedoneatcompiletime,atloadtime,oratruntime.

62.ExplainXMLSchemabasedaspectimplementation?
Inthisimplementationcase,aspectsareimplementedusingregularclassesalongwithXMLbasedconfiguration.

63.Explainannotationbased(@AspectJbased)aspectimplementation
Thisimplementationcase(
@AspectJ

basedimplementation)referstoastyleofdeclaringaspectsasregularJavaclassesannotatedwithJava5annotations.

https://www.javacodegeeks.com/2014/05/springinterviewquestionsandanswers.html 10/14
7/11/2016 69SpringInterviewQuestionsandAnswersTheULTIMATEList

SpringModelViewController(MVC)
64.WhatisSpringMVCframework?
SpringcomeswithafullfeaturedMVCframeworkforbuildingwebapplications.AlthoughSpringcaneasilybeintegratedwithotherMVC
frameworks,suchasStruts,SpringsMVCframeworkusesIoCtoprovideacleanseparationofcontrollerlogicfrombusinessobjects.Italso
allowstodeclarativelybindrequestparameterstobusinessobjects.

65.DispatcherServlet
TheSpringWebMVCframeworkisdesignedarounda
DispatcherServlet


thathandlesalltheHTTPrequestsandresponses.

66.WebApplicationContext
The
WebApplicationContext

isanextensionoftheplain
ApplicationContext

thathassomeextrafeaturesnecessaryforwebapplications.Itdiffersfromanormal
ApplicationContext

inthatitiscapableofresolvingthemes,andthatitknowswhichservletitisassociatedwith.

67.WhatisControllerinSpringMVCframework?
Controllersprovideaccesstotheapplicationbehaviorthatyoutypicallydefinethroughaserviceinterface.Controllersinterpretuserinputand
transformitintoamodelthatisrepresentedtotheuserbytheview.Springimplementsacontrollerinaveryabstractway,whichenablesyou
tocreateawidevarietyofcontrollers.

68.@Controllerannotation
The
@Controller

annotationindicatesthataparticularclassservestheroleofacontroller.Springdoesnotrequireyoutoextendanycontrollerbaseclassor
referencetheServletAPI.

69.@RequestMappingannotation
@RequestMapping

annotationisusedtomapaURLtoeitheranentireclassoraparticularhandlermethod.

Ok,sonowyouarereadyforyourinterview!DontforgettocheckourdedicatedpagefullofSpringTutorials!

Ifyouenjoyedthis,thensubscribetoournewslettertoenjoyweeklyupdatesandcomplimentarywhitepapers!Also,checkoutJCG
Academyformoreadvancedtraining!

Youarewelcometocontributewithyourcommentsandwewillincludetheminthearticle!

Taggedwith: INTERVIEW INTERVIEWQUESTIONS SPRING ULTIMA TE

DoyouwanttoknowhowtodevelopyourskillsettobecomeaJava
Rockstar?
SubscribetoournewslettertostartRockingrightnow!
TogetyoustartedwegiveyouourbestsellingeBooksforFREE!

1.JPAMiniBook
2.JVMTroubleshootingGuide

3.JUnitTutorialforUnitTesting
4.JavaAnnotationsTutorial
5.JavaInterviewQuestions
6.SpringInterviewQuestions
7.AndroidUIDesign

andmanymore....

Emailaddress:
https://www.javacodegeeks.com/2014/05/springinterviewquestionsandanswers.html 11/14
7/11/2016 69SpringInterviewQuestionsandAnswersTheULTIMATEList

Youremailaddress

Signup

15 COMMENTS

Nachiketasahoo
August27th,2014at12:29pm

howtogetthesetwobookfree
Reply

BiswaranjanSahoo
September17th,2014at12:04pm

nothingisfree.
Reply

BiswaranjanSahoo
September17th,2014at12:04pm

goodfollowup.BetterYouaddmorequestionandanswerhere.
Reply

RanceMoest
October11th,2014at9:17pm

Ifanyinterviewerstartsinwithlistslikethis,Igetupandleave.Andthensendthemabillforwastingmytime.
Reply

PeterK.
October23rd,2014at11:17pm

Ishouldsendyouabillforreadingyouremail,realizingthatitisirrelevant
Reply

PeterK.
October23rd,2014at11:18pm

Greatcheatsheetbtw
Reply

Ram
January20th,2015at9:15am

Niceone.Goodforpreparation.Andbeginnerscanunderstandwhatitis.
Reply

gamai
February9th,2015at2:36pm

PleaseincludeinformationabouttheversionofSpringtheseanswersarefor:XmlBeanFactoryisdeprecatedsincev.3.1,thereisnowa
thirdDImethodie.usingproperty,etc.
Reply

Veer
February9th,2015at3:53pm

ithinkquestionsobasicsoprovidemoredeplyquestionandanswer..
https://www.javacodegeeks.com/2014/05/springinterviewquestionsandanswers.html 12/14
7/11/2016 69SpringInterviewQuestionsandAnswersTheULTIMATEList
Reply

quovadis
May15th,2015at3:27am

likegamaisaid,thisarticlecontainslotofdeprecatedoroldfashionedmaterial.

Overallitisusefulnodoubt,butpleaseclarifywhensayingdontuseautowiringasitisconfusingthatyoumeantXMLAutowiring,not
@Autowiring,andalsothedifferenttypesofautowiringapplyagainonlytoXMLbased..confusedtheheckoutofme.
Reply

Vivan
May21st,2015at8:46pm

Goodknowledgeofbeginner..sopostmoreandmorequestionandanswers.!!Andimproveyourknowledge..!!
Reply

Mudassir
July13th,2015at6:46pm

Amazingarticle.
ThoughIhaveusedandknowallofthethingsmentionedbutyouhavecollectedtheminthisarticleverybeautifully.
Itsdefinitelyamustread.
Wouldbeniceifyoucanaddsomearchitecturaldiagramsfornewbies.
Thankyou
Reply

Amit
October9th,2015at8:42pm

Nicearticle.
Foundsomeexampleson
http://modernpathshala.com/Article/1024/topspringinterviewquestionsandanswerspart1
Pleaseaddsomemoreexamples.
Reply

Sandy
December1st,2015at9:35am

Goodstuff.Thesearenotbasicquestions,butthefundamentalonesthatareveryimportanttoknowespeciallyforexperienced
professionals,andnotonlyforbeginners.Iamsurepeoplefinditahardtimewhenitcomestodefinesomethingtheyarealready
working:).
Reply

Chandan
June28th,2016at11:54am

IfIknowallanswersmeansIcangetjobeasily.Thisquestionsandanswersenoughtogetajob
Reply

LEAVE A REPLY

Youremailaddresswillnotbepublished.Requiredfieldsaremarked*

Name*

Email*

Website

Signmeupforthenewsletter!

ReceiveEmailNotifications?
no,donotsubscribe instantly
Or,youcansubscribewithoutcommenting.

PostComment

https://www.javacodegeeks.com/2014/05/springinterviewquestionsandanswers.html 13/14
7/11/2016 69SpringInterviewQuestionsandAnswersTheULTIMATEList

KNOWLEDGE BASE HALL OF FAME ABOUT JAVA CODE GEEKS

JCGs(JavaCodeGeeks)isanindependentonlinecommunityfocusedoncreatingthe
Courses AndroidFullApplicationTutorialseries
ultimateJavatoJavadevelopersresourcecentertargetedatthetechnicalarchitect,
technicalteamlead(seniordeveloper),projectmanagerandjuniordevelopersalike.
Examples 11OnlineLearningwebsitesthatyou
JCGsservetheJava,SOA,AgileandTelecomcommunitieswithdailynewswrittenby
shouldcheckout
domainexperts,articles,tutorials,reviews,announcements,codesnippetsandopen
Resources
sourceprojects.
AdvantagesandDisadvantagesofCloud
Tutorials ComputingCloudcomputingprosand
cons DISCLAIMER
Whitepapers
AndroidGoogleMapsTutorial AlltrademarksandregisteredtrademarksappearingonJavaCodeGeeksarethe
propertyoftheirrespectiveowners.Javaisatrademarkorregisteredtrademarkof
PARTNERS AndroidJSONParsingwithGsonTutorial OracleCorporationintheUnitedStatesandothercountries.ExamplesJavaCodeGeeks
isnotconnectedtoOracleCorporationandisnotsponsoredbyOracleCorporation.
AndroidLocationBasedServices
Mkyong ApplicationGPSlocation

AndroidQuickPreferencesTutorial
THE CODE GEEKS NETWORK
DifferencebetweenComparatorand
ComparableinJava
.NETCodeGeeks
GWT2Spring3JPA2Hibernate3.5
JavaCodeGeeks Tutorial
SystemCodeGeeks JavaBestPracticesVectorvsArrayListvs
HashSet
WebCodeGeeks

JavaCodeGeeksandallcontentcopyright20102016,ExelixisMediaP.C.|TermsofUse|PrivacyPolicy|Contact

https://www.javacodegeeks.com/2014/05/springinterviewquestionsandanswers.html 14/14