0% found this document useful (0 votes)
445 views18 pages

Java Interview Questions - Tutorialspoint

All Java interview Question...

Uploaded by

Rohit Rasal
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)
445 views18 pages

Java Interview Questions - Tutorialspoint

All Java interview Question...

Uploaded by

Rohit Rasal
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

10/2/2016

JavaInterviewQuestionstutorialspoint

JavaInterviewQuestions
[Link]
[Link]
Dearreaders,theseJavaInterviewQuestionshavebeendesignedespeciallytogetyouacquaintedwiththe
natureofquestionsyoumayencounterduringyourinterviewforthesubjectofJavaProgrammingLanguage.
Aspermyexperience,goodinterviewershardlyplannedtoaskanyparticularquestionduringyourinterview,
normallyquestionsstartwithsomebasicconceptofthesubjectandlatertheycontinuebasedonfurther
discussionandwhatyouanswer
WhatdoyouknowaboutJava?
JavaisahighlevelprogramminglanguageoriginallydevelopedbySunMicrosystemsandreleasedin1995.
Javarunsonavarietyofplatforms,suchasWindows,MacOS,andthevariousversionsofUNIX.
WhatarethesupportedplatformsbyJavaProgrammingLanguage?
Javarunsonavarietyofplatforms,suchasWindows,MacOS,andthevariousversionsofUNIX/Linuxlike
HPUnix,SunSolaris,RedhatLinux,Ubuntu,CentOS,etc.
ListanyfivefeaturesofJava?
SomefeaturesincludeObjectOriented,PlatformIndependent,Robust,Interpreted,Multithreaded
WhyisJavaArchitecturalNeutral?
Itscompilergeneratesanarchitectureneutralobjectfileformat,whichmakesthecompiledcodetobe
executableonmanyprocessors,withthepresenceofJavaruntimesystem.
HowJavaenabledHighPerformance?
[Link]
bytecode,whichisaprogramthatcontainsinstructionsthatmustbeinterpretedintoinstructionsthatcanbesent
directlytotheprocessor.
WhyJavaisconsidereddynamic?
[Link]
informationthatcanbeusedtoverifyandresolveaccessestoobjectsonruntime.
WhatisJavaVirtualMachineandhowitisconsideredincontextofJavasplatformindependentfeature?
WhenJavaiscompiled,itisnotcompiledintoplatformspecificmachine,ratherintoplatformindependentbyte
[Link](JVM)onwhichever
platformitisbeingrun.
ListtwoJavaIDEs?
Netbeans,Eclipse,etc.
ListsomeJavakeywords(unlikeC,C++keywords)?
[Link]

1/18

10/2/2016

JavaInterviewQuestionstutorialspoint

SomeJavakeywordsareimport,super,finally,etc.
WhatdoyoumeanbyObject?
[Link]
onanobject'sinternalstateandserveastheprimarymechanismforobjecttoobjectcommunication.
Defineclass?
[Link]
describethebehaviorofanobject.
Whatkindofvariablesaclasscanconsistof?
AclassconsistofLocalvariable,instancevariablesandclassvariables.
WhatisaLocalVariable?
Variablesdefinedinsidemethods,[Link]
andinitializedwithinthemethodanditwillbedestroyedwhenthemethodhascompleted.
WhatisaInstanceVariable?
[Link]
classisloaded.
WhatisaClassVariable?
Thesearevariablesdeclaredwithinaclass,outsideanymethod,withthestatickeyword.
WhatisSingletonclass?
Singletonclasscontrolobjectcreation,limitingthenumbertoonebutallowingtheflexibilitytocreatemore
objectsifthesituationchanges.
WhatdoyoumeanbyConstructor?
[Link]
writeaconstructorforaclassthejavacompilerbuildsadefaultconstructorforthatclass.
ListthethreestepsforcreatinganObjectforaclass?
AnObjectisfirstdeclared,theninstantiatedandthenitisinitialized.
WhatisthedefaultvalueofbytedatatypeinJava?
Defaultvalueofbytedatatypeis0.
WhatisthedefaultvalueoffloatanddoubledatatypeinJava?
DefaultvalueoffloatanddoubledatatypeindifferentascomparedtoC/C++.Forfloatits0.0fandfordouble
its0.0d
Whenabytedatatypeisused?
Thisdatatypeisusedtosavespaceinlargearrays,mainlyinplaceofintegers,sinceabyteisfourtimessmaller
thananint.
[Link]

2/18

10/2/2016

JavaInterviewQuestionstutorialspoint

Whatisastaticvariable?
Classvariablesalsoknownasstaticvariablesaredeclaredwiththestatickeywordinaclass,butoutsidea
method,constructororablock.
WhatdoyoumeanbyAccessModifier?
Javaprovidesaccessmodifierstosetaccesslevelsforclasses,variables,[Link]
haspackageordefaultaccessibilitywhennoaccessibilitymodifierisspecified.
Whatisprotectedaccessmodifier?
Variables,methodsandconstructorswhicharedeclaredprotectedinasuperclasscanbeaccessedonlybythe
subclassesinotherpackageoranyclasswithinthepackageoftheprotectedmembers'class.
WhatdoyoumeanbysynchronizedNonAccessModifier?
JavaprovidesthesemodifiersforprovidingfunctionalitiesotherthanAccessModifiers,synchronizedusedto
indicatethatamethodcanbeaccessedbyonlyonethreadatatime.
AccordingtoJavaOperatorprecedence,whichoperatorisconsideredtobewithhighestprecedence?
Postfixoperatorsi.e()[].isatthehighestprecedence.
Variablesusedinaswitchstatementcanbeusedwithwhichdatatypes?
Variablesusedinaswitchstatementcanonlybeastring,enum,byte,short,int,orchar.
WhenparseInt()methodcanbeused?
ThismethodisusedtogettheprimitivedatatypeofacertainString.
WhyisStringclassconsideredimmutable?
TheStringclassisimmutable,[Link]
immutableitcansafelybesharedbetweenmanythreads,whichisconsideredveryimportantformultithreaded
programming.
WhyisStringBuffercalledmutable?
TheStringclassisconsideredasimmutable,[Link]
isanecessitytomakealotofmodificationstoStringsofcharactersthenStringBuffershouldbeused.
WhatisthedifferencebetweenStringBufferandStringBuilderclass?
[Link],ifthreadsafetyisnecessary
thenuseStringBufferobjects.
Whichpackageisusedforpatternmatchingwithregularexpressions?
[Link].
[Link]?
[Link],MatcherclassandPatternSyntaxExceptionclass.
[Link]

3/18

10/2/2016

JavaInterviewQuestionstutorialspoint

Whatisfinalize()method?
Itispossibletodefineamethodthatwillbecalledjustbeforeanobject'sfinaldestructionbythegarbage
[Link](),anditcanbeusedtoensurethatanobjectterminatescleanly.
WhatisanException?
[Link]
positionedalongthethread'smethodinvocationstack.
WhatdoyoumeanbyCheckedExceptions?
[Link]
example,ifafileistobeopened,butthefilecannotbefound,[Link]
simplybeignoredatthetimeofcompilation.
ExplainRuntimeExceptions?
[Link]
exceptions,runtimeexceptionsareignoredatthetimeofcompliation.
WhicharethetwosubclassesunderExceptionclass?
TheExceptionclasshastwomainsubclasses:IOExceptionclassandRuntimeExceptionClass.
Whenthrowskeywordisused?
Ifamethoddoesnothandleacheckedexception,[Link]
throwskeywordappearsattheendofamethod'ssignature.
Whenthrowkeywordisused?
Anexceptioncanbethrown,eitheranewlyinstantiatedoneoranexceptionthatyoujustcaught,byusingthrow
keyword.
HowfinallyusedunderExceptionHandling?
[Link]
executes,whetherornotanexceptionhasoccurred.
WhatthingsshouldbekeptinmindwhilecreatingyourownexceptionsinJava?
Whilecreatingyourownexception
AllexceptionsmustbeachildofThrowable.
IfyouwanttowriteacheckedexceptionthatisautomaticallyenforcedbytheHandleorDeclareRule,
youneedtoextendtheExceptionclass.
Youwanttowritearuntimeexception,youneedtoextendtheRuntimeExceptionclass.
DefineInheritance?
[Link]
ismademanageableinahierarchicalorder.
[Link]

4/18

10/2/2016

JavaInterviewQuestionstutorialspoint

Whensuperkeywordisused?
Ifthemethodoverridesoneofitssuperclass'smethods,overriddenmethodcanbeinvokedthroughtheuseof
[Link].
WhatisPolymorphism?
[Link]
OOPoccurswhenaparentclassreferenceisusedtorefertoachildclassobject.
WhatisAbstraction?
[Link]
maintainabilityofthesystem.
WhatisAbstractclass?
[Link]
containsoneormoreabstractmethodswhicharesimplymethoddeclarationswithoutabody.
WhenAbstractmethodsareused?
Ifyouwantaclasstocontainaparticularmethodbutyouwanttheactualimplementationofthatmethodtobe
determinedbychildclasses,youcandeclarethemethodintheparentclassasabstract.
WhatisEncapsulation?
[Link]
afieldisdeclaredprivate,itcannotbeaccessedbyanyoneoutsidetheclass,therebyhidingthefieldswithinthe
[Link].
WhatistheprimarybenefitofEncapsulation?
Themainbenefitofencapsulationistheabilitytomodifyourimplementedcodewithoutbreakingthecodeof
[Link],flexibilityandextensibilitytoourcode.
WhatisanInterface?
[Link],therebyinheritingtheabstract
methodsoftheinterface.
GivesomefeaturesofInterface?
Itincludes
Interfacecannotbeinstantiated
Aninterfacedoesnotcontainanyconstructors.
Allofthemethodsinaninterfaceareabstract.
DefinePackagesinJava?
APackagecanbedefinedasagroupingofrelatedtypes(classes,interfaces,enumerationsandannotations)
providingaccessprotectionandnamespacemanagement.
[Link]

5/18

10/2/2016

JavaInterviewQuestionstutorialspoint

WhyPackagesareused?
PackagesareusedinJavainordertopreventnamingconflicts,tocontrolaccess,tomakesearching/locatingand
usageofclasses,interfaces,enumerationsandannotations,etc.,easier.
WhatdoyoumeanbyMultithreadedprogram?
[Link]
calledathread,andeachthreaddefinesaseparatepathofexecution.
WhatarethetwowaysinwhichThreadcanbecreated?
Threadcanbecreatedby:implementingRunnableinterface,extendingtheThreadclass.
Whatisanapplet?
[Link]
becauseithastheentireJavaAPIatitsdisposal.
Anappletextendwhichclass?
[Link].
ExplaingarbagecollectioninJava?
[Link]
program.
Defineimmutableobject?
Animmutableobjectcantbechangedonceitiscreated.
Explaintheusageofthis()withconstructors?
Itisusedwithvariablesormethodsandusedtocallconstructerofsameclass.
ExplainSetInterface?
[Link]
inheritedfromCollectionandaddstherestrictionthatduplicateelementsareprohibited.
ExplainTreeSet?
ItisaSetimplementedwhenwewantelementsinasortedorder.
WhatisComparableInterface?
[Link]()[Link]
classimplementingtheComparableinterfacecanbeordered.
Differencebetweenthrowandthrows?
Itincludes:
Throwisusedtotriggeranexceptionwhereasthrowsisusedindeclarationofexception.

[Link]

6/18

10/2/2016

JavaInterviewQuestionstutorialspoint

Withoutthrows,Checkedexceptioncannotbehandledwhereascheckedexceptioncanbepropagated
withthrows.
ExplainthefollowinglineusedunderJavaProgram
publicstaticvoidmain(Stringargs[])
Thefollowingshowstheexplanationindividually
publicitistheaccessspecifier.
staticitallowsmain()tobecalledwithoutinstantiatingaparticularinstanceofaclass.
voiditaffirnsthecompilerthatnovalueisreturnedbymain().
main()thismethodiscalledatthebeginningofaJavaprogram.
Stringargs[]argsparameterisaninstancearrayofclassString
[Link]?
[Link]
providestheminimumrequirementsforexecutingaJavaapplication
WhatisJARfile?
[Link]
[Link].
WhatisaWARfile?
ThisisWebArchiveFileandusedtostoreXML,javaclasses,[Link]
acollectionofJavaServerPages,JavaServlets,Javaclasses,XMLfiles,staticWebpagesetc.
DefineJITcompiler?
Itimprovestheruntimeperformanceofcomputerprogramsbasedonbytecode.
Whatisthedifferencebetweenobjectorientedprogramminglanguageandobjectbasedprogramminglanguage?
[Link]
exampleofobjectbasedprogramminglanguages.
Whatisthepurposeofdefaultconstructor?
Thejavacompilercreatesadefaultconstructoronlyifthereisnoconstructorintheclass.
Canaconstructorbemadefinal?
No,thisisnotpossible.
Whatisstaticblock?
Itisusedtoinitializethestaticdatamember,Itisexcutedbeforemainmethodatthetimeofclassloading.
Definecomposition?
[Link]

7/18

10/2/2016

JavaInterviewQuestionstutorialspoint

Holdingthereferenceoftheotherclasswithinsomeotherclassisknownascomposition.
Whatisfunctionoverloading?
Ifaclasshasmultiplefunctionsbysamenamebutdifferentparameters,itisknownasMethodOverloading.
Whatisfunctionoverriding?
Ifasubclassprovidesaspecificimplementationofamethodthatisalreadyprovidedbyitsparentclass,itis
knownasMethodOverriding.
DifferencebetweenOverloadingandOverriding?
[Link]
implementationofthemethodthatisalreadyprovidedbyitssuperclassparametermustbedifferentincaseof
overloading,parametermustbesameincaseofoverriding.
Whatisfinalclass?
[Link].
WhatisNullPointerException?
ANullPointerExceptionisthrownwhencallingtheinstancemethodofanullobject,accessingormodifyingthe
fieldofanullobjectetc.
Whatarethewaysinwhichathreadcanenterthewaitingstate?
Athreadcanenterthewaitingstatebyinvokingitssleep()method,byblockingonIO,byunsuccessfully
attemptingtoacquireanobject'slock,orbyinvokinganobject'swait()[Link]
statebyinvokingits(deprecated)suspend()method.
HowdoesmultithreadingtakeplaceonacomputerwithasingleCPU?
Theoperatingsystem'[Link]
executingtasks,itcreatestheimpressionthattasksexecutesequentially.
Whatinvokesathread'srun()method?
Afterathreadisstarted,viaitsstart()methodoftheThreadclass,theJVMinvokesthethread'srun()method
whenthethreadisinitiallyexecuted.
DoesitmatterinwhatordercatchstatementsforFileNotFoundExceptionandIOExceptionarewritten?
Yes,[Link]'ssubclasseshavetobe
caughtfirst.
Whatisthedifferencebetweenyieldingandsleeping?
Whenataskinvokesitsyield()method,[Link]()method,it
returnstothewaitingstate.
WhyVectorclassisused?
[Link]
usefulifyoudon'tknowthesizeofthearrayinadvance,oryoujustneedonethatcanchangesizesoverthe
[Link]

8/18

10/2/2016

JavaInterviewQuestionstutorialspoint

lifetimeofaprogram.
HowmanybitsareusedtorepresentUnicode,ASCII,UTF16,andUTF8characters?
Unicoderequires16bitsandASCIIrequire7bits.AlthoughtheASCIIcharactersetusesonly7bits,itis
usuallyrepresentedas8bits.UTF8representscharactersusing8,16,and18bitpatterns.UTF16uses16bit
andlargerbitpatterns.
WhatareWrapperclasses?
[Link]:Integer,Character,Double,
Booleanetc.
WhatisthedifferencebetweenaWindowandaFrame?
TheFrameclassextendsWindowtodefineamainapplicationwindowthatcanhaveamenubar.
Whichpackagehaslightweightcomponents?
[Link],exceptJApplet,JDialog,JFrameandJWindowarelightweight
components.
Whatisthedifferencebetweenthepaint()andrepaint()methods?
Thepaint()[Link]()methodisusedtocausepaint()tobe
invokedbytheAWTpaintingthread.
WhatisthepurposeofFileclass?
Itisusedtocreateobjectsthatprovideaccesstothefilesanddirectoriesofalocalfilesystem.
WhatisthedifferencebetweentheReader/WriterclasshierarchyandtheInputStream/OutputStreamclass
hierarchy?
TheReader/Writerclasshierarchyischaracteroriented,andtheInputStream/OutputStreamclasshierarchyis
byteoriented.
Whichclassshouldyouusetoobtaindesigninformationaboutanobject?
TheClassclassisusedtoobtaininformationaboutanobject'[Link]
representclasses,interfacesinarunningJavaapplication.
Whatisthedifferencebetweenstaticandnonstaticvariables?
[Link]
variablestakeonuniquevalueswitheachobjectinstance.
WhatisSerializationanddeserialization?
[Link]
restoringtheseobjects.
Whatareusecases?
Itispartoftheanalysisofaprogramanddescribesasituationthataprogrammightencounterandwhat
behaviortheprogramshouldexhibitinthatcircumstance.
[Link]

9/18

10/2/2016

JavaInterviewQuestionstutorialspoint

ExplaintheuseofsublassinaJavaprogram?
[Link]
modifiermethodsandtheirimplementation.
Howtoaddmenushortcuttomenuitem?
Ifthereisabuttoninstancecalledb1,[Link]('F'),sotheuser
maybeabletouseAlt+Ftoclickthebutton.
CanyouwriteaJavaclassthatcouldbeusedbothasanappletaswellasanapplication?
Yes,justaddamain()methodtotheapplet.
WhatisthedifferencebetweenSwingandAWTcomponents?
AWTcomponentsareheavyweight,[Link]
[Link],[Link],whenitis
runningontheJavaplatformforUnixplatform,itmapstoarealMotifbutton.
What'sthedifferencebetweenconstructorsandothermethods?
[Link]
regularmethodscouldbecalledmanytimes.
IsthereanylimitationofusingInheritance?
Yes,sinceinheritanceinheritseverythingfromthesuperclassandinterface,itmaymakethesubclasstoo
clusteringandsometimeserrorpronewhendynamicoverridingordynamicoverloadinginsomesituation.
WhenistheArrayStoreExceptionthrown?
Whencopyingelementsbetweendifferentarrays,ifthesourceordestinationargumentsarenotarraysortheir
typesarenotcompatible,anArrayStoreExceptionwillbethrown.
Canyoucalloneconstructorfromanotherifaclasshasmultipleconstructors?
Yes,usethis()syntax.
What'sthedifferencebetweenthemethodssleep()andwait()?
Thecodesleep(2000)[Link](2000),causesawaitofupto
[Link]()ornotifyAll()[Link]()is
definedintheclassObjectandthemethodsleep()isdefinedintheclassThread.
WhenArithmeticExceptionisthrown?
TheArithmeticExceptionisthrownwhenintegerisdividedbyzeroortakingtheremainderofanumberbyzero.
Itisneverthrowninfloatingpointoperations.
Whatisatransientvariable?
AtransientvariableisavariablethatmaynotbeserializedduringSerializationandwhichisinitializedbyits
defaultvalueduringdeserialization,
Whatissynchronization?
[Link]

10/18

10/2/2016

JavaInterviewQuestionstutorialspoint

[Link]
keywordinjavaprovideslockingwhichensuresmutualexclusiveaccessofsharedresourceandpreventdata
race.
WhatistheCollectionsAPI?
TheCollectionsAPIisasetofclassesandinterfacesthatsupportoperationsoncollectionsofobjects.
Doesgarbagecollectionguaranteethataprogramwillnotrunoutofmemory?
[Link]
[Link]
thatarenotsubjecttogarbagecollection.
TheimmediatesuperclassoftheAppletclass?
[Link]
component,includingotherpanels.
WhichJavaoperatorisrightassociative?
The=operatorisrightassociative.
Whatisthedifferencebetweenabreakstatementandacontinuestatement?
Abreakstatementresultsintheterminationofthestatementtowhichitapplies(switch,for,do,orwhile).A
continuestatementisusedtoendthecurrentloopiterationandreturncontroltotheloopstatement.
Ifavariableisdeclaredasprivate,wheremaythevariablebeaccessed?
Aprivatevariablemayonlybeaccessedwithintheclassinwhichitisdeclared.
WhatisthepurposeoftheSystemclass?
ThepurposeoftheSystemclassistoprovideaccesstosystemresources.
ListprimitiveJavatypes?
Theeightprimitivetypesarebyte,char,short,int,long,float,double,andboolean.
WhatistherelationshipbetweenclippingandrepaintingunderAWT?
WhenawindowisrepaintedbytheAWTpaintingthread,itsetstheclippingregionstotheareaofthewindow
thatrequiresrepainting.
WhichclassistheimmediatesuperclassoftheContainerclass?
Componentclassistheimmediatesuperclass.
WhatclassofexceptionsaregeneratedbytheJavaruntimesystem?
TheJavaruntimesystemgeneratesRuntimeExceptionandErrorexceptions.
Underwhatconditionsisanobject'sfinalize()methodinvokedbythegarbagecollector?
Thegarbagecollectorinvokesanobject'sfinalize()methodwhenitdetectsthattheobjecthasbecome
unreachable.
[Link]

11/18

10/2/2016

JavaInterviewQuestionstutorialspoint

Howcanadeadthreadberestarted?
Adeadthreadcannotberestarted.
WhicharithmeticoperationscanresultinthethrowingofanArithmeticException?
Integer/and%canresultinthethrowingofanArithmeticException.
Variableofthebooleantypeisautomaticallyinitializedas?
Thedefaultvalueofthebooleantypeisfalse.
Cantrystatementsbenested?
Yes
WhatareClassLoaders?
[Link].
WhatisthedifferencebetweenanInterfaceandanAbstractclass?
[Link]
constantsandinstancemethods,butcannotimplementdefaultbehaviorandallmethodsareimplicitlyabstract.
Aninterfacehasallpublicmembersandnoimplementation.
Whatwillhappenifstaticmodifierisremovedfromthesignatureofthemainmethod?
Programthrows"NoSuchMethodError"erroratruntime.
Whatisthedefaultvalueofanobjectreferencedeclaredasaninstancevariable?
Null,unlessitisdefinedexplicitly.
Canatoplevelclassbeprivateorprotected?
No,[Link]"public"ornomodifier.
Whydoweneedwrapperclasses?
[Link]
methods.
Whatisthedifferencebetweenerrorandanexception?
[Link]
[Link]
doesnotexist.
Isitnecessarythateachtryblockmustbefollowedbyacatchblock?
[Link]
blockorafinallyblock.
Whenathreadiscreatedandstarted,whatisitsinitialstate?
[Link]

12/18

10/2/2016

JavaInterviewQuestionstutorialspoint

Athreadisinthereadystateasinitialstateafterithasbeencreatedandstarted.
WhatistheLocaleclass?
TheLocaleclassisusedtotailorprogramoutputtotheconventionsofaparticulargeographic,political,or
culturalregion.
Whataresynchronizedmethodsandsynchronizedstatements?
[Link]
onlybeexecutedafterathreadhasacquiredthelockfortheobjectorclassreferencedinthesynchronized
statement.
Whatisruntimepolymorphismordynamicmethoddispatch?
Runtimepolymorphismordynamicmethoddispatchisaprocessinwhichacalltoanoverriddenmethodis
[Link],anoverriddenmethodiscalledthroughthe
referencevariableofasuperclass.
WhatisDynamicBinding(latebinding)?
[Link]
bindingmeansthatthecodeassociatedwithagivenprocedurecallisnotknownuntilthetimeofthecallatrun
time.
Canconstructorbeinherited?
No,constructorcannotbeinherited.
WhataretheadvantagesofArrayListoverarrays?
ArrayListcangrowdynamicallyandprovidesmorepowerfulinsertionandsearchmechanismsthanarrays.
WhydeletioninLinkedListisfastthanArrayList?
Deletioninlinkedlistisfastbecauseitinvolvesonlyupdatingthenextpointerinthenodebeforethedeleted
nodeandupdatingthepreviouspointerinthenodeafterthedeletednode.
HowdoyoudecidewhentouseArrayListandLinkedList?
Ifyouneedtofrequentlyaddandremoveelementsfromthemiddleofthelistandonlyaccessthelistelements
sequentially,[Link],withoutinsertingor
removingelementsfromanyplaceotherthantheend,thenArrayListshouldbeused.
WhatisaValuesCollectionView?
Itisacollectionreturnedbythevalues()methodoftheMapInterface,Itcontainsalltheobjectspresentas
valuesinthemap.
Whatisdotoperator?
Thedotoperator(.)[Link]
classesandsubpackagesfromapackage.
Whereandhowcanyouuseaprivateconstructor?
[Link]

13/18

10/2/2016

JavaInterviewQuestionstutorialspoint

Privateconstructorisusedifyoudonotwantotherclassestoinstantiatetheobjectandtopreventsubclassing.T
Whatistypecasting?
Typecastingmeanstreatingavariableofonetypeasthoughitisanothertype.
Describelifecycleofthread?
[Link]
Newbornstate
Runnablestate
Runningstate
Blockedstate
Deadstate
Whatisthedifferencebetweenthe>>and>>>operators?
The>>[Link]>>>zerofillsbitsthathavebeenshiftedout.
WhichmethodoftheComponentclassisusedtosetthepositionandsizeofacomponent?
setBounds()methodisusedforthispurpose.
Whatistherangeoftheshorttype?
Therangeoftheshorttypeis(2^15)to2^151.
WhatistheimmediatesuperclassofMenu?
MenuItemclass
DoesJavaallowDefaultArguments?
No,JavadoesnotallowDefaultArguments.
Whichnumberisdenotedbyleadingzeroinjava?
OctalNumbersaredenotedbyleadingzeroinjava,example:06
Whichnumberisdenotedbyleading0xor0Xinjava?
HexadecimalNumbersaredenotedbyleading0xor0Xinjava,example0XF
BreakstatementcanbeusedaslabelsinJava?
Yes,anexamplecanbebreakone
WhereimportstatementisusedinaJavaprogram?
Importstatementisallowedatthebeginningoftheprogramfileafterpackagestatement.
Explainsuspend()methodunderThreadclass>
Itisusedtopauseortemporarilystoptheexecutionofthethread.
ExplainisAlive()methodunderThreadclass?
[Link]

14/18

10/2/2016

JavaInterviewQuestionstutorialspoint

Itisusedtofindoutwhetherathreadisstillrunningornot.
WhatiscurrentThread()?
Itisapublicstaticmethodusedtoobtainareferencetothecurrentthread.
ExplainmainthreadunderThreadclassexecution?
[Link]
fromwhichallotherchildthreadsoriginate.
Lifecycleofanappletincludeswhichsteps?
Lifecycleinvolvesthefollowingsteps
Initialization
Starting
Stopping
Destroying
Painting
Whyistheroleofinit()methodunderapplets?
Itinitializestheappletandisthefirstmethodtobecalled.
WhichmethodiscalledbyAppletclasstoloadanimage?
getImage(URLobject,filename)isusedforthispurpose.
DefinecodeasanattributeofApplet?
Itisusedtospecifythenameoftheappletclass.
Definecanvas?
Itisasimpledrawingsurfacewhichareusedforpaintingimagesortoperformothergraphicaloperations.
DefineNetworkProgramming?
Itreferstowritingprogramsthatexecuteacrossmultipledevices(computers),inwhichthedevicesareall
connectedtoeachotherusinganetwork.
WhatisaSocket?
[Link]
socketonitsendofthecommunicationandattemptstoconnectthatsockettoaserver.
AdvantagesofJavaSockets?
[Link]
[Link].
DisadvantagesofJavaSockets?
[Link]

15/18

10/2/2016

JavaInterviewQuestionstutorialspoint

[Link]
andserversidehavetoprovidemechanismstomakethedatausefulinanyway.
Whichclassisusedbyserverapplicationstoobtainaportandlistenforclientrequests?
[Link]
Whichclassrepresentsthesocketthatboththeclientandserverusetocommunicatewitheachother?
[Link].
WhyGenericsareusedinJava?
[Link]
Genericmethodsandgenericclassesenableprogrammerstospecify,withasinglemethoddeclaration,asetof
relatedmethodsor,withasingleclassdeclaration,asetofrelatedtypes.
WhatenvironmentvariablesdoIneedtosetonmymachineinordertobeabletorunJavaprograms?
CLASSPATHandPATHarethetwovariables.
[Link]?
No,[Link].
WhatisNestedtoplevelclass?
Ifaclassisdeclaredwithinaclassandspecifythestaticmodifier,thecompilertreatstheclassjustlikeanyother
[Link].
WhatisExternalizableinterface?
[Link]
youacontrolovertheserializationmechanism.
[Link](0)iswrittenattheendofthetryblock,willthefinallyblockstillexecute?
[Link](0)thecontrolimmediately
goesoutoftheprogram,andthusfinallyneverexecutes.
Whatisdaemonthread?
Daemonthreadisalowprioritythread,whichrunsintermittentlyinthebackgrounddoingthegarbage
collectionoperationforthejavaruntimesystem.
Whichmethodisusedtocreatethedaemonthread?
setDaemonmethodisusedtocreateadaemonthread.
Whichmethodmustbeimplementedbyallthreads?
Alltasksmustimplementtherun()method
WhatistheGregorianCalendarclass?
TheGregorianCalendarprovidessupportfortraditionalWesterncalendars
[Link]

16/18

10/2/2016

JavaInterviewQuestionstutorialspoint

WhatistheSimpleTimeZoneclass?
TheSimpleTimeZoneclassprovidessupportforaGregoriancalendar.
WhatisthedifferencebetweenthesizeandcapacityofaVector?
Thesizeisthenumberofelementsactuallystoredinthevector,whilecapacityisthemaximumnumberof
elementsitcanstoreatagiveninstanceoftime.
Canavectorcontainheterogenousobjects?
[Link].
Whatisanenumeration?
Anenumerationisaninterfacecontainingmethodsforaccessingtheunderlyingdatastructurefromwhichthe
[Link].
WhatisdifferencebetweenPathandClasspath?
[Link]
theexecutables(.exe)[Link].
Canaclassdeclaredasprivatebeaccessedoutsideit'spackage?
No,it'snotpossibletoaccessedoutsideit'spackage.
Whataretherestrictionimposedonastaticmethodorastaticblockofcode?
Astaticmethodshouldnotrefertoinstancevariableswithoutcreatinganinstanceandcannotuse"this"operator
torefertheinstance.
CananInterfaceextendanotherInterface?
YesanInterfacecaninheritanotherInterface,forthatmatteranInterfacecanextendmorethanoneInterface.
WhichobjectorientedConceptisachievedbyusingoverloadingandoverriding?
Polymorphism
Whatisanobject'slockandwhichobject'shavelocks?
Anobject'slockisamechanismthatisusedbymultiplethreadstoobtainsynchronizedaccesstotheobject.A
threadmayexecuteasynchronizedmethodofanobjectonlyafterithasacquiredtheobject'slock.
WhatisDowncasting?
Itisthecastingfromageneraltoamorespecifictype,[Link].
Whatareorderofprecedenceandassociativityandhowaretheyused?
[Link]
determineswhetheranexpressionisevaluatedlefttorightorrighttoleft.
Ifamethodisdeclaredasprotected,wheremaythemethodbeaccessed?

[Link]

17/18

10/2/2016

JavaInterviewQuestionstutorialspoint

Aprotectedmethodmayonlybeaccessedbyclassesorinterfacesofthesamepackageorbysubclassesofthe
classinwhichitisdeclared.
Whatisthedifferencebetweeninnerclassandnestedclass?
Whenaclassisdefinedwithinascopeofanotherclass,[Link]
innerclassisstatic,thenitbecomesnestedclass.
Whatrestrictionsareplacedonmethodoverriding?
Overriddenmethodsmusthavethesamename,argumentlist,[Link]
limittheaccessofthemethoditoverrides.
WhatisconstructorchainingandhowisitachievedinJava?
[Link]
noargsconstructorasthefirststatement.
Canadoublevaluebecasttoabyte?
Yes,adoublevaluecanbecasttoabyte.
Howdoesatrystatementdeterminewhichcatchclauseshouldbeusedtohandleanexception?
Whenanexceptionisthrownwithinthebodyofatrystatement,thecatchclausesofthetrystatementare
[Link]
[Link].
Whatwillbethedefaultvaluesofalltheelementsofanarraydefinedasaninstancevariable?
Ifthearrayisanarrayofprimitivetypes,thenalltheelementsofthearraywillbeinitializedtothedefaultvalue
correspondingtothatprimitivetype.

WhatisNext?
Further,youcangothroughyourpastassignmentsyouhavedonewiththesubjectandmakesureyouareableto
[Link]
questions,ratheryouhavetomakeyourbasicsconceptsverystrong.
Seconditreallydoesn'tmattermuchifyoucouldnotanswerfewquestionsbutitmattersthatwhateveryou
answered,[Link]
tutorialspointwishyoubestlucktohaveagoodinterviewerandalltheverybestforyourfutureendeavor.
Cheers:)

[Link]

18/18

You might also like