You are on page 1of 4

Q.WhatisDifferencebetweeninterfaceandabstractclass?

Ans:InterfaceandAbstractclassbotharelookssimilarfromdeclarationpointofview.Themajordifferenceisfor
implementingmultipleinheritanceyouneedinterface,becausejavadoesnotsupportmultipleinheritance.All
methodsandvariablesofinterfacearepublic.Interfacecancontainonlyabstractmethod(withoutmethodbody),
butabstractclasscancontainsabstractandnonabstractmethods.Abstractclassmustbeinheritedbysubclass.
Thesearefewmajorpointsyoucananswerforinterview.Formoreininterfacereadhere.

Q.Canyouwritefinalmethodininterface?
Ans:No,becauseinterfacemethodsdonothavebody.Itneedtobeimplementinimplementedclass.

Q.Isthispossibletowritefinalmethodinabstractclass?
Ans:Yes,youcandothisbyusingnonabstractmethods.

Q.WhatisDifferencebetweenIteratorandListIterator?
Ans:Bothareusedtoretrievethedatafromcollection.Iteratoronlytraverseinforwarddirection,butListIteratorcan
traverseinbothforwardandbackwarddirection.ListIteratorhashasPrevious()andprevious()methodwhichisnot
availableinIterator.
Q.Differencebetweensynchronizedblockandsynchronizedmethod?
Ans:SynchronizedMethoddefinesaselfcontainedblockanditseasytohandleinmultithreadedenvironment.
Bothactassimilarthereisnomajoradvantageovereachother.Thedifferenceisthatasynchronizedblockcan
choosewhichobjectitsynchronizeson.Asynchronizedmethodcanonlyuse'this '(orthecorrespondingClass
instanceforasynchronizedclassmethod).

Q.DifferencebetweenStringandStringBufferclass?
Ans:Stringisimmutable,butStringBufferisnot.StringBufferusedtorepresentcharactersthatcanbe
modified.StringBufferisfasterwhenperformingconcatenations.ThisisbecausewhenyouconcatenateaString,
youarecreatinganewobject(internally)everytimesinceStringisimmutable.

Q.Howtogetthesessionobjectinjsp?
Ans:Byusingimplicitobjectsession.Youcanusesession.getAttributes()methods.

Q.Howtogetthesessionfactoryobjectinhibernate?
Ans:BytheuseofbuildSessionFactory()method.Syntaxasbelow.

SessionFactoryfactory=newConfiguration().configure().buildSessionFactory()

Q.Howtohandletheruntimeexceptioninjsp?
Ans:InjsppagedirectiveyoucanuseisErrorPage=true.

Q.Differencebetweenmethodoverloadingandoverriding?
Ans:Bothareconceptofpolymorphism.Methodoverloadingisaformofstaticbinding.Methodoverridingisa
formdynamicbinding.Overloadingisappliedinsingleclass,butoverridingisapplicableforinheritedclass.Method
overloadingisalwaysspecifictomethodsignature.Itdefinesnumberofparameter,typeofparameterandsequence
ofparameter.

Q.Differencebetweenjava.util.dateandjava.sql.date?
Ans:Asweknoweverydatabasesupportmostthreeformofentryi.e.date,timeandtimestamp.InjavaJDBC
havingallthosesupportsusingjava.sql.Date,java.sql.Time,java.sql.TimeStamp.InternallyalltheseJDBCclasses
extendsjava.util.Date.

Q.Ihave1to100elementsinarrayunordered,oneelementmissedfindthatone?
Ans:Thereisexistingoldformula.Calculatethesumofallnumbersstoredinthearrayofsize11meansithold12
data.Then,subtractthesumfrom(12*13)/2

BasicFormula:n*(n+1)/2.

Q.Differencebetweenequals()andhashcode()?
Ans:BothmethodsarefromObjectclass.Equals()methodisusedtocomparethecontentsofobjectorreference.
But,hashcode()methodisusedtogettheuniquehashcodeforanyobject.Hashcodeisusedforhash
implementationslikeHashMap,HashTable,HashSetetc.

Q.WhatisComparator?

Ans:Itsaninterface.Ithas2importantmethods.But,thefrequentlyusedmethodiscompareTo().Itcompares2
differentobjects.

Q.Wehaveequals()tocomparetwomethodsthenwhycomparatoragain?
Ans:Because,equals()methodwillonlycomparethecontent.Itcannotcomparetwodifferentobjects.Comparator
interfacehascompareTo()methodwhichcompare2differentobject.

Q.Whatisautowiringinspring?
Ans:AutowiringisamechanismforinjectingobjectsinSpring.Byusingtheannotation@Autowired,youcan
achievethat.
Itsavailableinsideorg.springframework.beans.factory.annotationpackage.

Q.WecangetthecontainerobjectthroughBeanfactoryandApplicationcontextwhatisthedifferencein
both?
Ans:ABeanFactoryisusedtojustinstantiatesandconfiguresbeans.AnApplicationContextalsodoesthat,andit
providesthesupportinginfrastructuretoenablelotsofenterprisespecificfeaturessuchastransactionsand
AOP.ReadmoreonSpringSpecification.

Q.WhatistheDifferencebetweenget()andload()inhibernate?
Ans:ThesetwomethodsaremostusefulmethodinHibernate.Bothmethodsareusedtoget/fetchtherecords
fromdatabase.Theget()methodwillreturnnull,ifthedatanotfound.Theload()methodalwaysreturnsproxy.

Q.Differencebetweenpageandpagecontextinjsp?
Ans:AsweknowbothareimplicitobjectofJSP.Pageisatypejava.lang.Objectanditsaninstanceofgenerated
servletfromthisJSP,butPageContextisatypeofjavax.servlet.jsp.PageContext.PageContextisusedforstoring
andretrievingpagerelatedinformationandsharingobjectswithinthesametranslationunitandsamerequest.

Q.Whatisapplicationinjsp?
Ans:Itsascope.ItdefinesthevisibilityfordataoverApplication.

You might also like