Java Interview Questions and Answers
Java Interview Questions and Answers
700JavainterviewquestionsandanswersJavaFAQPDF
Search
Interview Currentaffairs Civilservices Banking Engineering MBA GD Placementpapers HR CV Coverletter Aptitude English Onlinetest
Askquestion!
PDFDownload
JavaPDF
JavaProgrammingClass
Interviewquestions
700Javainterviewquestionsandanswers
Javainterviewquestions
JavaFAQs
Java1Java2Java3Java4Java5Java6Java7Java8Java9Java10Java11Java12Java13Java14Java15Java
16Java17Java18Java19Java20Java21Java22
DownloadJava/OracleFAQ
QUESTIONWhatisbytecodeinthecontextofJava?
TestJDBCskills New
ThetypeofcodegeneratedbyaJavacompiler
ThetypeofcodegeneratedbyaJavaVirtualMachine
ItisanothernameforaJavasourcefile
Itisthecodewrittenwithintheinstancemethodsofaclass.
ViewAnswer/HideAnswer
TestJavaskills New
TestEJBskills New
Javaobject,class,method
Javaoperator
Javavariables
Javaoverloadingoverriding
CoreJavainterviewtest(72questions)new
ByPradipPatil,LecturerIIMPMCA
Javaabstractclasses
Java(20questions)new
ByPradipPatil,LecturerIIMPMCA
Javaarrays
Javadatatypes
Javaexception
Javainterviewquestionsandanswersforfreshers
Advancedjavainterviewquestionsseniorleveljavainterview
QUESTIONWhatisgarbagecollectioninthecontextofJava?
Javaevents
Javavirtualmachine
Javainputandoutput
JavaURLconnections
Theoperatingsystemperiodicallydeletesallofthejavafilesavailableonthesystem.
Anypackageimportedinaprogramandnotusedisautomaticallydeleted.
Whenallreferencestoanobjectaregone,thememoryusedbytheobjectisautomaticallyreclaimed.
TheJVMcheckstheoutputofanyJavaprogramanddeletesanythingthatdoesn'tmakesense.
Javasockets
JNDI
Javaapplets
ViewAnswer/HideAnswer
BasicJavainterviewquestionsFrequentlyaskedJavainterview
CoreJavainterviewquestionsandanswersforfreshers
JavaAWT
JavadrawingAWTcomponents
Corejava
JDBC
Corejavainterviewquestionsandanswersforexperienced
Placementpracticetest:Java|SAP|.NET|Oracle|SqlServer|QA|Aptitude|Networking|AllSkills
JSP
QUESTIONWhatisdifferentbetweenaJavaappletandaJavaapplication?
Anapplicationcaningeneralbetrustedwhereasanappletcan't.
Anappletmustbeexecutedinabrowserenvironment.
Anappletisnotabletoaccessthefilesofthecomputeritrunson
Alloftheabove
ViewAnswer/HideAnswer
EJB
J2EE
JNI
Servlets
Struts
Javathreading
QUESTIONYoureadthefollowingstatementinaJavaprogramthatcompilesandexecutes.
J2ME
submarine.dive(depth)
JMS
Whatcanyousayforsure?
Javawebservices
depthmustbeanint
divemustbeamethod.
divemustbethenameofaninstancefield.
submarinemustbethenameofaclass
ViewAnswer/HideAnswer
QUESTIONWhichistrueaboutananonymousinnerclass?
http://www.careerride.com/JavaInterviewQuestions.aspx
RMI
Internationalization
JavaScript
EJBArchitecture
Spring
1/15
2/23/2015
700JavainterviewquestionsandanswersJavaFAQPDF
Itcanextendexactlyoneclassandimplementexactlyoneinterface.
Itcanextendexactlyoneclassandcanimplementmultipleinterfaces.
Itcanimplementmultipleinterfacesregardlessofwhetheritalsoextendsaclass.
JavaTransactionAPIJTA
ViewAnswer/HideAnswer
Javatransactionservices,JTS
QUESTIONIfathreadistobedeclaredasadaemonthread,itmustbedeclaredbefore
startmethod
runmethod
stopmethod
none
ViewAnswer/HideAnswer
JBOSS
JavaGUIFrameworkinterview
SWT/JFaceinterview
MVCandJface
JavaServerFaces
Hibernateinterview
JAAS
QUESTIONUnderwhatcircumstancesmightyouusetheyieldmethodoftheThreadclass
JavaMailinterview
Tocallfromthecurrentlyrunningthreadtoallowanotherthreadofthesameorhigherprioritytorun
Tocallonawaitingthreadtoallowittorun
Toallowathreadofhigherprioritytorun
Tocallfromthecurrentlyrunningthreadwithaparameterdesignatingwhichthreadshouldbeallowedtorun
Tomcat
ViewAnswer/HideAnswer
Antinterview
QUESTIONWhichofthefollowingisthecorrectsyntaxforsuggestingthattheJVMperformsgarbage
collection
System.free()
System.setGarbageCollection()
)System.out.gc()
System.gc()
ViewAnswer/HideAnswer
MIDPinterview
Weblogicinterview
Websphereinterview
Rubyinterview
jQueryinterview
AspectOrientedProgramming
Javadesignpatterns
Javalocalization
QUESTIONWhenmethoddefinedinsubclasswhichhassamesignatureasamethodinasuperclass,itis
knownasmethod________________
Overloading
Overriding
Packing
noneofthese
ViewAnswer/HideAnswer
QUESTIONInanAWTorSwingcontainer,BoxLayoutplacesthecomponentsinwhichform?
1)lefttoright
2)toptobottom
3)righttoleft
4)bottomtotop
1
2
1and2
3and4
ViewAnswer/HideAnswer
QUESTIONAclassthatcannotbeasubclassiscalledas______class.
abstract
parentclass
Final
noneofthese
ViewAnswer/HideAnswer
QUESTIONWhichmodelusedinswingcomponent?
Modelviewcontroller
Eventdelegationmodel
Documentobjectmodel
networkmodel
ViewAnswer/HideAnswer
QUESTIONWhenseveralthreadsactonobjectsimultaneouslyandtheresultisreliablethenitisknownas
____________
Boxing
Unsynchronized
synchronized
noneofthese
http://www.careerride.com/JavaInterviewQuestions.aspx
2/15
2/23/2015
700JavainterviewquestionsandanswersJavaFAQPDF
ViewAnswer/HideAnswer
QUESTIONAllcollectionclassesinjava.utilpackageareimplementationclassesofdifferentinterfaces
True
False
ViewAnswer/HideAnswer
QUESTIONDeflaterOutputStremandInflaterInputStreamclassesareavailableinwhichpackage?
java.io
java.util
java.io.zip
java.util.zip
ViewAnswer/HideAnswer
QUESTIONProcessofstoringtheobjectcontainintothefileisknownas______________
synchronization
serialization
zip
doping
ViewAnswer/HideAnswer
QUESTIONStaticandtransientvariablecannotbeserialized
Yes
No
ViewAnswer/HideAnswer
QUESTIONAllcomponentsfromjavax.swingaredevelopedin______________
C++
C
pascal
purejava
ViewAnswer/HideAnswer
QUESTIONFileOutputStreamclassstorethedataintheformof_________
character
file
bytes
bit
ViewAnswer/HideAnswer
QUESTIONWhatisthedefaultbuffersizeusedbyanybufferedclass?
128bytes
256bytes
512bytes
1024bytes
ViewAnswer/HideAnswer
DownloadJavainterviewquestionsandanswerspdf
ExplainthedifferencebetweenJavaandJavaScript.
ExplainhowtoobtainaperformanceprofileofmyJavaProgram.
Explainthepurposeoftheexecutablefilesthathaveanextra_gattheendoftheirnames,e.g.java_g.
IfJavaisplatformindependent,whydoesn'titrunonallplatforms?
ExplainhowtoaccessnativeoperatingsystemcallsfrommyJavaprogram.
HowdowecreateandusesocketsinJava?
ExplainhowtosenddatafrommyJavaprogramtoaCGIprogram.
ExplainthedifferencebetweenaURLinstanceandaURLConnectioninstance.
HowdoIreadalineofinputatatimeinJava?
Whyisthreadsynchronizationimportantformultithreadedprograms?
Explainhowtocreateathreadandstartitrunning.
Whenshouldweuseaneventadapterclass?
Explainthecomponentandcontainerclasses.
Whatisthedifferencebetweenaruntimeexceptionandaplainexception?
Canyouexplaininbrieflifecycleforstatelessandstatefulbeans?
WhatisPassivationandActivationinEJB?
HowdoweimplementcachinginJSP?
ExplainthedifferentAuthenticationoptionsavailableinServlets.
HowcanweusebeansinJSP?
ExplainthedifferencebetweenJavaBeansandtaglibdirectives.
http://www.careerride.com/JavaInterviewQuestions.aspx
3/15
2/23/2015
700JavainterviewquestionsandanswersJavaFAQPDF
ExplainthedifferentscopesanobjectcanhaveinaJSPpage.
ExplaintheuseofExternalizationinterface.
ExplainwideningconversionandNarrowingconversion.
Howdoweimplementdeepcloning?
Javainterviewquestionsandanswersforfreshersandexperienced
Javafeatures
Simple,ObjectOriented,Robust,Distributed,Portable,Interpreted,Multithreaded,PlatformIndependent,Secure...........
Readansw er
Javaprogramexecution
WhatisJVM?Explainitsrolesandfunctions.
ExplainwhyJavaiscalledasPlatformindependentlanguage.ExplainhowJavaexecutableexecutesonanyplatformwhereJVMis
available...................
Readansw er
Javaarchitecture
Javaprogramminglanguage,Javaclassfileformat,JavaApplicationProgrammingInterface,Javavirtualmachine.............
Readansw er
Javaclass
ExplainthefeaturesofJavaclass.ExplainFields,Methods,andAccessLevels.
WhatareaccessorsandmutatormethodsinaJavaclass?Explainwithexampleforeach.
Explaintheimportanceof'this'reference.Writeacodetodepictstheuseof'this'reference
ExplainstaticvariablesandstaticmethodsinJava.Provideanexampletoexplainthem..................
Readansw er
Javaconstructors
Whatisaconstructor?Explainthedifferencesbetweenmethodsandconstructor.
Differencesbetweenconstructorsandmethods.
Writecodetodepicttheuseofconstructor.....................
Readansw er
Javaclassmember
Whatisinstancemembers?Explainwithanexample
Whatisinstancevariable?Explainwithanexample
Whatisinstancemethod?Explainwithanexample
Whatisstaticmember?Explainwithanexample
Whatisstaticvariable?Explainwithanexample......................
Readansw er
Javapackages
WhatareJavapackages?ExplaintheimportanceofJavapackages.
StepsforcreatingapackageinJava
Explainthepackagesaccessspecifier,i.e.private,protected,public,default.............
Readansw er
Javagarbagecollector
ExplainJavaGarbagecollector.Whygarbagecollection?BriefexplanationofGarbagecollectionalgorithms.
ExplaintheimportanceoffinalizersinJava.WritecodetodepicttheusesoffinalizersinJava...............
Readansw er
Javasuperkeyword
Explaintheimportanceof'super'keywordinJava.Writecodetodepicttheusesof'super'keywordThekeywordsuperisusedforreferring
parentclassinstance....................
Readansw er
Javaoverloading&overriding
DefineMethodoverloading.Explainitsuses.ProvideacodesampletoexplaintheusesofMethodoverloading
DefineMethodoverriding.Explainitsuses.ProvideacodesampletoexplaintheusesofMethodoverloading
Differencebetweenoverloadingandoverriding.......................
Readansw er
Javastringclass
DescribeJavastringclass.ExplainmethodsofJavastringclass.ExplainthecharacteristicsofStringBufferclassStringClass:TheString
http://www.careerride.com/JavaInterviewQuestions.aspx
4/15
2/23/2015
700JavainterviewquestionsandanswersJavaFAQPDF
classisimmutable,ThecontentsoftheStringobjectcannotbechanged,Stringclassisfinalclass.Thatimpliesitcannothavesub
classes......................
Readansw er
Javainnerclasses
WhatisJavainnerclass?Explainthetypesofinnerclasses,i.e.Staticmemberclasses,Memberclasses,Localclasses,Anonymous
classes
Needofinnerclassincontextwithadapterclasses
ExplainfewWrapperClassesMethods...............
Readansw er
Javareflectionclass
ExplainaboutJavareflectionclass.
WriteacodesampletodepicttheusesofJavareflectionclass.........
Readansw er
Javaswing
WhatisSwing?ExplaintheneedofSwing.
WritesomeimportantfeaturesofSwing.
DescribeJavaSwingclasshierarchy.
ExplaintheneedofLayoutmanager...........
Readansw er
Javalayoutmanager
ExplaindifferentlayoutmanagerinJava.Alayoutmanagerorganizestheobjectsinacontainer,Differentlayoutsareusedtoorganizeorto
arrangeobjects.............
Readansw er
Javaexceptionhandling
ExplaintheneedofExceptionhandling.
ExplaintheExceptionscategories,i.e.checkedanduncheckedexceptions.
ProvidethegeneralformofExceptionhandlingconstructswithexplanation
WhatisuserdefinedException?Explainwithanexample............
Readansw er
Javamultithreading
WhatisMultithreading?Explainthelifecycleofathread.
ExplainhowtousethreadclassforMultithreadinginJava.Explainwithanexample.
WhatisRunnableinterface?ExplainhowtouseRunnableinterfaceforMultithreading.
Whatarethemethodsofthreadclassinjava?Explainthem
Canyourexplainthreadpriorities?..............
Readansw er
Javafilehandling
ExplaintheuseofStreams.
DifferencebetweenStreamclassesandReaderwriterclasses
ExplainanddemonstratetheuseofFile,RandomAccessFileclasses.
ExplaintheuseofReaderandWriterclasses..............
Readansw er
Javautilityclasses
WhatisobjectSerialization?ExplaintheuseofPersistingobject.
DepictthestepofusingobjectDeserialization.....................
Readansw er
Javasocketprogramming
Whatissocket?Explainthefeaturesofsocket.
ExplainthecharacteristicsofJavasocketclass.
ExplainServerSocketclasswithanexample
ExplainInetAddressclasswithanexample
ExplainDatagramSocketclasswithanexample
ExplainDatagramPacketclasswithanexample.............
Readansw er
JDBC
PurposesofJDBCAPI
Describe4typesofJDBCdriversandtheircharacteristicswithusages.
StatethefunctionalitiesofimportantclassesinJDBCpackages.
http://www.careerride.com/JavaInterviewQuestions.aspx
5/15
2/23/2015
700JavainterviewquestionsandanswersJavaFAQPDF
ExplainhowtouseJDBCstatementtoexecuteSQLqueries.Showinanexample
ExplainhowtousePreparedStatementtoexecuteparameterizedqueries.Showinanexample
WhatisJDBCCallableStatement?
WhatisbatchupdatesinJDBC?Explainwithanexample......................
Readansw er
WriteyourcommentShareKnowledgeandExperience
DiscussionBoard
javainterviewQuestions
Here'ssomemorejavaquestions:
1)Juniorjavadeveloper
a)Basicocjp(formerscjp)questions:
Whatdoesstatic,finalmean,purposes
Howmanyaccesibilitymodifiersexist?Pleasedescribethem.
Whydoyouneedamainmethod?
Howmanyconstructorscanyouhave?
Defineoverwritingandoverloading
GivejavaAPIimplementationsforoverwritingandoverloading
DescribetheStringclassuniqueproperties
StringBuildervsStringBuffer
Collections:pleasedescribe,givesomeexamplesandcomparethemtoeachother
ArrayListvsVector
HashMapvsHashTable
Whatsatree
Whatsamap
Multithreading:describethemanagementinjava
Whatsasemaphone?
Howmanystatesarethereforthreads?
Describetheusageforsynchronizedword(2)
Serializationinjavaadescritionandusage
Garbagecollectioninjavadescriptionandusage
Canyouguaranteethegarbagecollectionprocess?
b)Simpledesignpatternquestions:
Singletonpleasedescribemainfeaturesandcoding
Factorypleasedescribemainfeaturesandcoding
Haveyouusedothers?pleasedescribethem
2)IntermediateandSeniorleveldependingonrateofgoodresponses,additionalquestionsto1):
http://centraladvisor.com/programming2/java/javadeveloperinterview
Bogdan081201210:34AM
Javainterviewquestionsandanswers
ExplaintheimportanceofDriverManager.
ThebasicservicetomanagesetofJDBCdrivers.
WhatarethemethodsinObject?
clone,equals,wait,finalize,getClass,hashCode,notify,notifyAll,toString
Defineanestedclass.
Ifallthemethodsofainnerclassisstaticthenitisanestedclass.
Whatisgarbagecollection?
http://www.careerride.com/JavaInterviewQuestions.aspx
6/15
2/23/2015
700JavainterviewquestionsandanswersJavaFAQPDF
Reclaimingtheunusedmemorybytheinvalidobjects.Garbagecollectorisresponsibleforthisprocess
DifferencebetweenLinkedListandArrayList.
LinkedListaremeantforsequentialaccessing.
ArrayListaremeantforrandomaccessing.
Defineapackage.
Packagesprovideswidenamespaceabilityandallowstogroupsetofclassesintoasingleunit.
Raj125201103:10AM
Javainterviewquestionsandanswers
ExplainthesignificanceofListIterator.
UsingListIteratoryoucaniteratebackandforth.
Canyouexplaininnerclass.
Ifthemethodsoftheinnerclasscanonlybeaccessedviatheinstanceoftheinnerclass,thenitiscalledinnerclass.
Canyouexplainthemeaningofaggregationandcomposition
AggregationItisaspecialtypeofcomposition.Ifyouexposeallthemethodsofacompositeclassandroutethemethodcalltothe
compositemethodthroughits
reference,thenitiscalledaggregation.
CompositionHoldingthereferenceoftheotherclasswithinsomeotherclassisknownascomposition.
IsitpossibletoinstantiatetheMathclass?
Youcantinstantiatethemathclass.
Pankaj125201103:10AM
Javainterviewquestionsandanswers
DefineLocale.
ALocaleobjectrepresentsaspecificgeographical,political,orculturalregion.
Howwillyouloadaspecificlocale?
ByusingResourceBundle.getBundle()
IsJVMacompileroraninterpreter?
Interpreter
CanyouexplaintheusagesofClass.forName()?
ItloadstheclassintotheClassLoader.ItreturnstheClass.Usingthatyoucangettheinstance(classinstance.newInstance()).
Inqaddsaquestion:Expainthereasonforeachkeywordof
publicstaticvoidmain(Stringargs[])
Akash125201103:10AM
Javainterviewquestionsandanswers
Definereflection.
Reflectionallowsprogrammaticaccesstoinformationaboutthefields,methodsandconstructorsofloadedclasses.
Canyoutellmerangeofbyte?
http://www.careerride.com/JavaInterviewQuestions.aspx
7/15
2/23/2015
700JavainterviewquestionsandanswersJavaFAQPDF
128to127
HowtoinvokeexternalprocessinJava.
Runtime.getRuntime().exec(.)
Whatisthebestwaytofindoutthetime/memoryconsumingprocess?
Byusingprofiler
Rakesh125201103:09AM
Javainterviewquestionsandanswers
Whatisskeletonandstub?Explaintheirpurposes.
Stubisaclientsiderepresentationoftheserver,whichtakescareofcommunicatingwiththeremoteserver.
WhatkindofthreadistheGarbagecollectorthread?
Daemonthread
ExplainthepurposeofVoidclass.
TheVoidclassisanuninstantiableplaceholderclasstoholdareferencetotheClassobjectrepresentingtheprimitiveJavatypevoid.
Nitin125201103:09AM
Javainterviewquestionsandanswers
Explaintheimportanceoffinalizemethod.
Finalizemethodcleansupsomeresourcesbeforeitgetgarbagecollected.
Definemutableobjectandimmutableobject.
ThevalueofMutableobjectischangeable.
Ex.,StringBuffer
Thevalueofanimmutableobjectcan'tbechanged
Ex.,String,Integer,Float
WhatarethebaseclassforErrorandException?
Throwable
Dharam125201103:09AM
Javainterviewquestionsandanswers
Differencebetweenstringandstringbufferobject.
Stringisanimmutableobject.
StringBufferisamutableobject.
Definedaemonthread.
Daemonthreadarethethreadswhichcanrunwithoutuserintervention.
TheJVMcanexitwhentherearedaemonthreadbykillingthemabruptly.
DefineaDatabaseMetaData.
Itrepresentscomprehensiveinformationaboutthedatabaseasawhole.
Jitu125201103:08AM
http://www.careerride.com/JavaInterviewQuestions.aspx
8/15
2/23/2015
700JavainterviewquestionsandanswersJavaFAQPDF
Javainterview
Explainpreemptiveschedulingandtimeslicing.
Inpreemptivescheduling,thehighestprioritytaskexecutesuntilitentersthewaitingordeadstatesorahigherprioritytaskcomesinto
existence.
Intimeslicing,ataskexecutesforapredefinedsliceoftimeandthenreentersthepoolofreadytasks.
ExplainthedifferentscopesforJavavariables.
3scopesofJavavariablesaredefinedbelow:
Instance
Initializedtodefaultvaluesatthetimeofcreationofobject,andremainaccessibleaslongastheobjectaccessible.
Local
DefinedwithinamethodandremainaccessbileonlyduringthecourseofmethodexcecutionandfalloutofscopeWhenthemethod
finishes
execution.
Static
Staticvariablesaretheclasslevelvariables.
StaticvariablesareinitializedwhentheclassisloadedinJVMforthefirsttimeandremainthereaslongastheclassremainsloaded.
Staticvariablesarenottiedtoanyparticularobjectinstance.
Akash1123201102:26AM
Javainterviewquestionsandanswers
Explainthepurposeoffinalization.
Itprovidesanunreachableobjecttheopportunitytoperformanycleanupprocessingbeforetheobjectisgarbagecollected.
Explaintheimportanceofdaemonthread.
Daemonthreadisalowprioritythread.
Itrunsintermittentlyinthebackgrounddoingthegarbagecollectionoperationforthejavaruntimesystem.
AdaemonthreadiscreatedusingsetDaemonmethod.
Synchronizedmethodsandsynchronizedstatements.
Synchronizedmethods
Methodsthatareusedtocontrolaccesstoanobject.
Athreadonlyexecutesasynchronizedmethodafterithasacquiredthelockforthemethod'sobjectorclass.
Synchronizedstatements
Theyaresimilartosynchronizedmethods.
Asynchronizedstatementcanonlybeexecutedafterathreadhasacquiredthelockfortheobjectorclassreferencedinthesynchronized
statement.
Nitin1123201101:31AM
Javainterviewquestionsandanswers
Whatarethewayofusingthread?
Canbeimplementedbyusingrunnableinterface
ByinheritingfromtheThreadclass.
Differencebetweenaconstructorandamethod.
Constructor
Aconstructorisamemberfunctionofaclassthatisusedtocreateobjectsofthatclass.
Ithasthesamenameastheclassitself.
Ithasnoreturntype,andisinvokedusingthenewoperator.
Method
http://www.careerride.com/JavaInterviewQuestions.aspx
9/15
2/23/2015
700JavainterviewquestionsandanswersJavaFAQPDF
Amethodisanordinarymemberfunctionofaclass.
Ithasitsownname,areturntype,andisinvokedusingthedotoperator.
Explainhowtoserializeanobjecttoafile.
TheclasswhoseinstancesaretobeserializedshouldimplementaninterfaceSerializable,passtheinstancetotheObjectOutputStream
whichisconnectedtoafileoutputstream.Thiswillsavetheobjecttoafile.
Naveen1123201101:25AM
Javaquestionsandanswers
AccessSpecifiersinJava.
Publicpublicclasses,methods,andfieldscanbeaccessedfromeverywhere.
Protected
Protectedmethodsandfieldscanonlybeaccessedwithinthesameclass,withinitssubclasses,andwithinclassesofthesame
package.
Default(nospecifier)
Suchaclass,method,orfieldwillbeaccessiblefrominsidethesamepackagetowhichtheclass,method,orfieldbelongs,butnotfrom
outsidethispackage.
Private
Privatemethodsandfieldscanonlybeaccessedwithinthesameclass.
Privatemethodsandfieldsarenotvisiblewithinsubclasses
Theyarenotinheritedbysubclasses.
Explainstaticmethods.
Staticmethodsaredeclaredwiththekeywordstaticasmodifier.
TheyarecalledStaticbecausetheyaffectaclassasawhole,notaparticularinstanceoftheclass.
Theyarealwaysinvokedwithoutreferencetoaparticularinstanceofaclass.
Restrictionsofusingstaticmethods:
Itcanonlycallotherstaticmethods.
Itmustonlyaccessstaticdata.
Itcannotreferencetothecurrentobjectusingkeywordssuperorthis.
Priya1123201112:55AM
Javainterviewquestions
CanyoutellmethemainImplementationsoftheSetinterface?
HashSet
TreeSet
LinkedHashSet
EnumSet
ExplaintheimportanceofHashSet.
Itisanunsorted,unorderedSet.
Itusesthehashcodeoftheobjectbeinginserted.
Youcanuseitwhenyouwantacollectionwithnoduplicatesandyoudontcareaboutorderwhenyouiteratethroughit.
ExplaintheimportanceofTreeSet.
Itisasetimplementationkeepingtheelementsinsortedorder.
Theelementsaresortedaccordingtothenaturalorderofelementsorbythecomparatorprovidedatcreationtime.
Tina1123201112:46AM
Javainterviewquestionsandanswers
Definenativemethod.
AnativemethodisimplementedinalanguageotherthanJava.
Explainexplicitcasting.
http://www.careerride.com/JavaInterviewQuestions.aspx
10/15
2/23/2015
700JavainterviewquestionsandanswersJavaFAQPDF
InExplicitcasting,thecomplierarespecificallyinformedabouttransformingtheobject.
Example
longa=890.20
intb=(int)a//Explicitcasting
Explainimplicitcasting.
Assigningoneentitytoanotherwithoutanytransformationguidancetothecompilerisimplicitcasting.
Thistypeofcastingisnotpermittedinallkindsoftransformationsandmaynotworkforallscenarios.
Example
inta=6000
longb=a//Implicitcasting
ExplainreflectionAPI
Reflectionistheprocessofintrospectingthefeaturesandstateofaclassatruntimeanddynamicallymanipulateatruntime.
ThisissupportedusingReflectionAPIwithbuiltinclasseslikeClass,Method,Fields,Constructorsetc.
Example:UsingJavaReflectionAPIwecangettheclassname,byusingthegetNamemethod.
Rajeev1122201104:07AM
Javainterviewquestionsandanswers
ExplaintheimportanceofJavaVirtualMachine(JVM).
Itconverts.javafileinto.classfilebyusingCompilerandInterpreterreadsbytecodes.
ExplainthedifferenttypesofaccessmodifiersinJava.
Theydeterminethetypeofaccesstothememberofaclass.
Types:
Public:accessibletoallclasses
Protected:accessibletotheclasseswithinthesamepackageandanysubclasses.
Private:accessibleonlytotheclasstowhichtheybelong
Default:accessibletotheclasstowhichtheybelongandtosubclasseswithinthesamepackage
WhytherearenoglobalvariablesinJava?
Globalvariablesaregloballyaccessibleandhencecancreatecollisionsinnamespace.
WhatistheJavaAPI?
Italargecollectionofsoftwarecomponentsthatprovidecapabilities,suchasgraphicaluserinterface(GUI)widgets.
Rajeev1122201103:48AM
Javainterviewquestionsandanswers
ExplainStringTokenizer.
Itisutilityclassthatareusedtobreakupstring.
Example:
StringTokenizerstr=newStringTokenizer(Welcome)
while(str.hasMoreTokens()){
System.out.println(st.nextToken())
}
Nadeem1122201103:42AM
Javainterviewquestionsandanswers
Differencebetweentheboolean&operatorandthe&&operator.
Whenboolean&operatorisevaluated,bothoperandsareevaluated
&&operatorisashortcutoperator.
http://www.careerride.com/JavaInterviewQuestions.aspx
11/15
2/23/2015
700JavainterviewquestionsandanswersJavaFAQPDF
When&&operatorisevaluated,thefirstoperandisevaluated.
Whenfirstoperandreturnsavalueoftruethenthesecondoperandisevaluated.
Whenfirstoperandevaluatestofalse,theevaluationofthesecondoperandisskipped.
Nadeem1122201103:40AM
Javainterviewquestions
DoesJavasupportpointers?
Javadoesn'tsupporttheusageofpointers.Improperhandlingofpointersleadstomemoryleakswhichiswhypointerconcepthasn't
foundplaceinJava.
SwingandAwt
AWTareheavyweightcomponenets.
SwingsarelightweightcomponentsandthisisreasonwhyswingworksfasterthanAWT.
Passbyreferenceandpassbyvalue
PassByReferenceisthepassingtheaddressitselfratherthanpassingthevalue.
PassbyValueispassingacopyofthevaluetobepassed.
RakeshS114201101:26AM
Javainterviewquestions
Abstractclass
Itmustbeextendedorsubclassed.
Itactsasatemplate.
Itmaycontainstaticdata.
Aclassmaybedeclaredabstractevenifithasnoabstractmethodsandthispreventsitfrombeinginstantiated.
Annie114201101:21AM
JavainterviewquestionsandanswersApril18,2011
Whatisanabstractmethod?
Anabstractmethodisamethodwhichdoesnthaveabody,justdeclaredwithmodifierabstract.
Explaintheuseofthefinallyblock.
Finallyblockisablockwhichalwaysexecutes.Theblockexecutesevenwhenanexceptionisoccurred.Theblockwon'texecuteonlywhen
theusercallsSystem.exit()
Whatistheinitialstateofathread?
Itisinareadystate.
Whatistimeslicing?
Intimeslicing,thetaskcontinuesitsexecutionforapredefinedperiodoftimeandreentersthepoolofreadytasks.
http://www.careerride.com/JavaInterviewQuestions.aspx
12/15
2/23/2015
700JavainterviewquestionsandanswersJavaFAQPDF
WhatareWrapperClasses?
WrapperClassesallowtoaccessprimitivesasobjects.
WhatisListinterface?
Listisanorderedcollectionofobjects.
Canyouexplaintransientvariablesinjava?
Theyarethevariablesthatcannotbeserialized.
Whatissynchronization?
Synchronizationensuresonlyonethreadtoaccessasharedresource,thuscontrolstheaccessofmultiplethreadstosharedresources.
Whatisserialization?
Serializationhelpstoconvertthestateofanobjectintoabytestream.
WhatisHashMapandMap?
MapisInterfaceandHashmapisclassthatimplementsthat.
JavainterviewquestionsandanswersApril20,2011
WhatisStringBufferclass?
StringBufferclassissameasStringclasswiththeexceptionthatitismutable.Itallowschangeanddoesntcreateanewinstanceon
changeofvalue.
Howcanyouforcegarbagecollection?
ItisnotpossibletoforceGC.WecanjustrequestitbycallingSystem.gc().
Isitpossibleanexceptiontoberethrown?
Yes,anexceptioncanberethrown.
Whatisthereturntypeofaprogramsmain()method?
Aprogramsmain()methodhasavoidreturntype.
Whichpackageisalwaysimportedbydefault?
Thejava.langpackageisalwaysimportedbydefault.
WhatisaClass?
Aclassimplementsthebehaviorofmemberobjectsbydescribingalltheattributesofobjectsandthemethods.
WhatisanObject?
Anobjectisthemembersofaclass.Itisthebasicunitofasystem.Ithasattributes,behaviorandidentity.
Explaintheuseof"instanceOf"keyword.
"instanceOf"keywordisusedtocheckthetypeofobject.
Howdoyourefertoacurrentinstanceofobject?
Youcanreferthecurrentinstanceofobjectusing"this"keyword.
WhatistheuseofJAVAPtool?
JAVAPisusedtodisassemblecompiledJavafiles.Thisoptionisusefulwhenoriginalsourcecodeisnotavailable.
Inwhichpackageistheappletclasslocated?
Appletclassesarelocatedin"java.applet"package.
Javaarrayvs.ArrayListclass.
ArrayListisadynamicarraythatcangrowdependingondemandwhereasJavaarraysarefixedlength.
ExplainEnumerationInterface.
Itdefinesthemethodsusingwhichwecanenumeratetheelementsinacollectionofobjects.
Whatareaccessmodifiers?
Accessmodifiersdetermineifamethodoradatavariablecanbeaccessedbyanothermethodinanotherclass.
http://www.careerride.com/JavaInterviewQuestions.aspx
13/15
2/23/2015
700JavainterviewquestionsandanswersJavaFAQPDF
Explaintheimpactofprivateconstructor.
Privateconstructorpreventsaclassfrombeingexplicitlyinstantiatedbycallers.
Whatisanexception?
Anexceptionisanabnormalconditionthatarisesinacodesequenceatruntime
JavainterviewquestionsandanswersApril21,2011
Whatarewaystocreatethreads?
Therearetwowaystocreateathread:
extendthejava.lang.Threadclass
implementthejava.lang.Runnableinterface
Howcanwestopathreadprogrammatically?
thread.stop
Whataredaemonthreads?
Daemonthreadsaredesignedtoruninbackground.Anexampleofsuchthreadisgarbagecollectorthread.
WhatarethedifferenttypesoflocksinJDBC?
TherearefourtypesofmajorlocksinJDBC:
Exclusivelocks
Sharedlocks
Readlocks
Updatelocks
WhatareServlets?
Servletsareprogramthatrununderwebserverenvironments.
Whatarethedifferentwaystomaintainstatebetweenrequests?
Therearefourdifferentways:
URLrewriting
Cookies
Hiddenfields
Sessions
Whatarewrapperclasses?
InJavawehaveclassesforeachprimitivedatatypes.Theseclassesarecalledaswrapperclass.Forexample,Integer,Character,Double
etc.
Whatarecheckedexceptions?
ThereareexceptionsthatareforcedtocatchbyJavacompiler,e.gIOException.Thoseexceptionsarecalledcheckedexceptions.
WhatistheLocaleclass?
Localeclassisaclassthatconvertstheprogramoutputtoaparticulargeographic,political,orculturalregion
IsmainakeywordinJava?
No,mainisnotakeywordinJava.
WhatisthemostimportantfeatureofJava?
PlatformindependencymakesJavaapremiumlanguage.
WhatisaJVM?
JVMisJavaVirtualMachinewhichisaruntimeenvironmentforthecompiledjavaclassfiles.
DoesJavasupportmultipleinheritances?
No,Javadoesn'tsupportmultipleinheritances.
Whatisthebaseclassofallclasses?
java.lang.Object
Canaclassbedeclaredasprotected?
Aclasscan'tbedeclaredasprotected.Onlymethodscanbedeclaredasprotected.
http://www.careerride.com/JavaInterviewQuestions.aspx
14/15
2/23/2015
700JavainterviewquestionsandanswersJavaFAQPDF
Cananabstractclassbedeclaredfinal?
No,sinceitisobviousthatanabstractclasswithoutbeinginheritedisofnouse.
JavainterviewquestionsandanswersApril22,2011
Canwedeclareavariableasabstract?
Variablescan'tbedeclaredasabstract.Onlyclassesandmethodscanbedeclaredasabstract.
DefineMarkerInterface.
AnInterfacewhichdoesn'thaveanydeclarationinsidebutstillenforcesamechanism.
Whatisanabstractmethod?
Anabstractmethodisamethodwhoseimplementationisdeferredtoasubclass.
Whencananobjectreferencebecasttoaninterfacereference?
Anobjectreferenceiscasttoaninterfacereferencewhentheobjectimplementsthereferencedinterface.
Whichclassisextendedbyallotherclasses?
TheObjectclassisextendedbyallotherclasses.
Whatisthereturntypeofaprogram'smain()method?
void.
WhataretheeightprimitiveJavatypes?
Theeightprimitivetypesarebyte,char,short,int,long,float,double,andboolean.
Differencebetweenapublicandanonpublicclass.
Apublicclassmaybeaccessedoutsideofitspackage.Anonpublicclassmaynotbeaccessedoutsideofitspackage.
WhichJavaoperatorisrightassociative?
The=operatorisrightassociative.
Whatisatransientvariable?
Transientvariableisavariablethatmaynotbeserialized.
1|2|3|4|5|6|7|8|9|10|11|12|13|14|15
Oracle
Database
Designanalysis
Networking
Programming
Web
Applicationserver
Mainframe
Datacommunicationandbroadband
MobileApplication
Oracleapps
SAP
Microsoft
Operatingsystem
Testing
Programminglanguage
UIDesigner
Peoplesoft
Java
Datawarehousing
Managementaccounting
Wirelesscommunication
EmbeddedSystems
Financialmanagement
Naukri.comRegisterNow
GetHeadhuntedbyBestRecruitersinIndia.TopProfilesHighCTC
Home| WantaJob?SubmitKeySkills | Mykeyskills | Aboutus | Sitemap| Contactus
Copyright20082013CareerRide.com.Allrightsreserved. Termsofuse |FollowusonFacebook!
Bookm arkto:
http://www.careerride.com/JavaInterviewQuestions.aspx
15/15