CoreJavaInterviewQuestions
CoreJava:BasicsofJavaInterviewQuestions
1)WhatisdifferencebetweenJDK,JREandJVM?
JVM
JVMisanacronymforJavaVirtualMachine,itisanabstractmachinewhichprovidestheruntimeenvironmentin
[Link](soJVMis
plateformdependent).
JRE
[Link].
JDK
[Link]+developmenttools.
2)HowmanytypesofmemoryareasareallocatedbyJVM?
ManyTypes:
[Link](Method)Area
[Link]
[Link]
[Link]
[Link]
3)WhatisJITcompiler?
JustInTime(JIT)compiler:[Link]
similarfunctionalityatthesametime,[Link]
compilerreferstoatranslatorfromtheinstructionsetofaJavavirtualmachine(JVM)totheinstructionset
ofaspecificCPU.
4)Whatisplatform?
[Link]
[Link].
5)WhatisthemaindifferencebetweenJavaplatformandotherplatforms?
TheJavaplatformdiffersfrommostotherplatformsinthesensethatit'sasoftwarebasedplatformthatrunson
[Link]:
[Link]
[Link](ApplicationProgrammingInterface)
6)WhatgivesJavaits'writeonceandrunanywhere'nature?
[Link]
[Link].
7)Whatisclassloader?
[Link]
[Link],Extensionclassloader,Systemclassloader,Pluginclassloaderetc.
8)[Link]?
Yes,[Link],[Link]'stakea
simpleexample:
//[Link]
classA
{
publicstaticvoidmain(Stringargs[])
{
[Link]("HelloJava!...");
}
}
//[Link]
//runbyjavaA
[Link]
runitbyjavaA
9)Isdelete,next,main,exitornullkeywordinjava?
No.
10)IfIdon'tprovideanyargumentsonthecommandline,thentheStringarrayofMainmethodwillbeemptyor
null?
[Link].
11)WhatifIwritestaticpublicvoidinsteadofpublicstaticvoid?
Programcompilesandrunsproperly.
12)Whatisthedefaultvalueofthelocalvariables?
Thelocalvariablesarenotinitializedtoanydefaultvalue,neitherprimitivesnorobjectreferences.
CoreJavaOOPsConcepts:InitialOOPsInterviewQuestions
13)Whatisdifferencebetweenobjectorientedprogramminglanguageandobjectbasedprogramminglanguage?
[Link]
programminglanguagesareJavaScript,VBScriptetc.
14)Whatwillbetheinitialvalueofanobjectreferencewhichisdefinedasaninstancevariable?
TheobjectreferencesareallinitializedtonullinJava.
CoreJavaOOPsConcepts:ConstructorInterviewQuestions
15)Whatisconstructor?
[Link]
objectcreation.
16)Whatisthepurposeofdefaultconstructor?
[Link]
constructoronlyifthereisnoconstructorintheclass.
17)Doesconstructorreturnanyvalue?
Ans:yes,thatiscurrentinstance(Youcannotusereturntypeyetitreturnsavalue).
18)Isconstructorinherited?
No,constructorisnotinherited.
19)Canyoumakeaconstructorfinal?
No,constructorcan'tbefinal.
CoreJavaOOPsConcepts:statickeywordInterviewQuestions
20)Whatisstaticvariable?
[Link](thatisnotuniqueforeachobject)e.g.
companynameofemployees,collegenameofstudentsetc.
[Link].
21)Whatisstaticmethod?
[Link].
[Link].
[Link].
22)Whymainmethodisstatic?
BecauseobjectisnotrequiredtocallstaticmethodifItwerenonstaticmethod,jvmcreatsobjectfirstthen
callmain()methodthatwillleadtotheproblemofextramemoryallocation.
23)Whatisstaticblock?
[Link].
[Link].
24)Canweexecuteaprogramwithoutmain()method?
Ans)Yes,oneofthewayisstaticblock.
25)Whatifthestaticmodifierisremovedfromthesignatureofthemainmethod?
[Link]"NoSuchMethodError".
26)Whatisdifferencebetweenstatic(class)methodandinstancemethod?
staticorclassmethod
instancemethod
1)[Link]
method.
[Link]
instancemethod.
2)Objectisnotrequiredtocallstaticmethod.
Objectisrequiredtocallinstancemethods.
3)Nonstatic(instance)memberscannotbeaccessedin
staticcontext(staticmethod,staticblockandstatic
nestedclass)directly.
staticandnonstaticvariablesbothcanbeaccessedin
instancemethods.
4)Forexample:publicstaticintcube(intn){return
n*n*n;}
Forexample:publicvoidmsg(){...}.
27)Whatisthisinjava?
Itisakeywordthatthatreferstothecurrentobject.
28)WhatisInheritance?
Inheritanceisamechanisminwhichoneobjectacquiresallthepropertiesandbehaviourofanotherobjectof
[Link].
29)Whichclassisthesuperclassforeveryclass?
Objectclass.
30)Whymultipleinheritanceisnotsupportedinjava?
Toreducethecomplexityandsimplifythelanguage,multipleinheritanceisnotsupportedinjavaincaseof
class.
31)Whatiscomposition?
Holdingthereferenceoftheotherclasswithinsomeotherclassisknownascomposition.
32)Whatisdifferencebetweenaggregationandcomposition?
[Link]:bikehas
anindicator(aggregation)butbikehasanengine(compostion).
33)WhyJavadoesnotsupportpointers?
[Link]
unsafe(unsecured)andcomplextounderstand.
34)Whatissuperinjava?
Itisakeywordthatreferstotheimmediateparentclassobject.
35)Canyouusethis()andsuper()bothinaconstructor?
[Link]()orthis()mustbethefirststatement.
36)Whatisobjectcloning?
Theobjectcloningisusedtocreatetheexactcopyofanobject.