Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
1K views

Java Developers Guide - IBM Java Interview Questions For 3-8 Year Experience

The document discusses several differences between programming concepts in Java: - Interface allows implementing multiple inheritance while abstract class does not. Interface contains only abstract methods while abstract class can contain abstract and non-abstract methods. - Final methods cannot be written in interfaces since interfaces do not have method bodies but can be written in abstract classes using non-abstract methods. - Iterator traverses only forward while ListIterator can traverse backward and forward. ListIterator has additional methods like hasPrevious() and previous().

Uploaded by

Rohini Bauskar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Java Developers Guide - IBM Java Interview Questions For 3-8 Year Experience

The document discusses several differences between programming concepts in Java: - Interface allows implementing multiple inheritance while abstract class does not. Interface contains only abstract methods while abstract class can contain abstract and non-abstract methods. - Final methods cannot be written in interfaces since interfaces do not have method bodies but can be written in abstract classes using non-abstract methods. - Iterator traverses only forward while ListIterator can traverse backward and forward. ListIterator has additional methods like hasPrevious() and previous().

Uploaded by

Rohini Bauskar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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