0% found this document useful (0 votes)
51 views

Core Java Interview Questions

The document summarizes core Java interview questions related to Java fundamentals like JDK, JRE, JVM, memory areas, JIT compiler, platforms, classloaders, constructors, static keyword, inheritance, polymorphism, abstraction, and encapsulation. Some key points are: - JVM runs Java bytecode and exists on various hardware/software platforms. JRE includes JVM + runtime libraries while JDK includes JRE + development tools like compilers. - JIT compiler improves performance by compiling bytecode parts with similar functionality together. - Constructors initialize object state and are invoked during object creation but cannot return a value or be inherited. - Static methods belong to the class and can access

Uploaded by

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

Core Java Interview Questions

The document summarizes core Java interview questions related to Java fundamentals like JDK, JRE, JVM, memory areas, JIT compiler, platforms, classloaders, constructors, static keyword, inheritance, polymorphism, abstraction, and encapsulation. Some key points are: - JVM runs Java bytecode and exists on various hardware/software platforms. JRE includes JVM + runtime libraries while JDK includes JRE + development tools like compilers. - JIT compiler improves performance by compiling bytecode parts with similar functionality together. - Constructors initialize object state and are invoked during object creation but cannot return a value or be inherited. - Static methods belong to the class and can access

Uploaded by

linktoanu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

CoreJavaInterviewQuestions

CoreJava:BasicsofJavaInterviewQuestions
1)WhatisdifferencebetweenJDK,JREandJVM?
JVM
JVMisanacronymforJavaVirtualMachine,itisanabstractmachinewhichprovidestheruntimeenvironmentin
whichjavabytecodecanbeexecuted.JVMsareavailableformanyhardwareandsoftwareplatforms(soJVMis
plateformdependent).
JRE
JREstandsforJavaRuntimeEnvironment.ItistheimplementationofJVMandphysicallyexists.
JDK
JDKisanacronymforJavaDevelopmentKit.Itphysicallyexists.ItcontainsJRE+developmenttools.
2)HowmanytypesofmemoryareasareallocatedbyJVM?
ManyTypes:
1.Class(Method)Area
2.Heap
3.Stack
4.ProgramCounterRegister
5.NativeMethodStack
3)WhatisJITcompiler?
JustInTime(JIT)compiler:Itisusedtoimprovetheperformance.JITcompilespartsofthebytecodethathave
similarfunctionalityatthesametime,andhencereducestheamountoftimeneededforcompilation.Heretheterm
compilerreferstoatranslatorfromtheinstructionsetofaJavavirtualmachine(JVM)totheinstructionset
ofaspecificCPU.
4)Whatisplatform?
Aplatformisbasicallythehardwareorsoftwareenvironmentinwhichaprogramruns.Therearetwotypesof
platformssoftwarebasedandhardwarebased.Javaprovidessoftwarebasedplatform.
5)WhatisthemaindifferencebetweenJavaplatformandotherplatforms?
TheJavaplatformdiffersfrommostotherplatformsinthesensethatit'sasoftwarebasedplatformthatrunson
topofotherhardwarebasedplatforms.Ithastwocomponents:
1.RuntimeEnvironment
2.API(ApplicationProgrammingInterface)
6)WhatgivesJavaits'writeonceandrunanywhere'nature?
Thebytecode.Javaiscompiledtobeabytecodewhichistheintermediatelanguagebetweensourcecodeand
machinecode.Thisbytecodeisnotplatformspecificandhencecanbefedtoanyplatform.
7)Whatisclassloader?
TheclassloaderisasubsystemofJVMthatisusedtoloadclassesandinterfaces.Therearemanytypesof
classloaderse.g.Bootstrapclassloader,Extensionclassloader,Systemclassloader,Pluginclassloaderetc.
8)IsEmpty.javafilenameavalidsourcefilename?
Yes,saveyourjavafileby.javaonly,compileitbyjavac.javaandrunbyjavayourclassnameLet'stakea
simpleexample:
//saveby.javaonly
classA
{
publicstaticvoidmain(Stringargs[])
{
System.out.println("HelloJava!...");
}
}
//compilebyjavac.java
//runbyjavaA
compileitbyjavac.java
runitbyjavaA
9)Isdelete,next,main,exitornullkeywordinjava?
No.
10)IfIdon'tprovideanyargumentsonthecommandline,thentheStringarrayofMainmethodwillbeemptyor
null?
Itisempty.Butnotnull.
11)WhatifIwritestaticpublicvoidinsteadofpublicstaticvoid?
Programcompilesandrunsproperly.
12)Whatisthedefaultvalueofthelocalvariables?
Thelocalvariablesarenotinitializedtoanydefaultvalue,neitherprimitivesnorobjectreferences.
CoreJavaOOPsConcepts:InitialOOPsInterviewQuestions
13)Whatisdifferencebetweenobjectorientedprogramminglanguageandobjectbasedprogramminglanguage?
ObjectbasedprogramminglanguagesfollowallthefeaturesofOOPsexceptInheritance.Examplesofobjectbased
programminglanguagesareJavaScript,VBScriptetc.
14)Whatwillbetheinitialvalueofanobjectreferencewhichisdefinedasaninstancevariable?
TheobjectreferencesareallinitializedtonullinJava.
CoreJavaOOPsConcepts:ConstructorInterviewQuestions
15)Whatisconstructor?
Constructorisjustlikeamethodthatisusedtoinitializethestateofanobject.Itisinvokedatthetimeof
objectcreation.
16)Whatisthepurposeofdefaultconstructor?
Thedefaultconstructorprovidesthedefaultvaluestotheobjects.Thejavacompilercreatesadefault
constructoronlyifthereisnoconstructorintheclass.
17)Doesconstructorreturnanyvalue?
Ans:yes,thatiscurrentinstance(Youcannotusereturntypeyetitreturnsavalue).
18)Isconstructorinherited?
No,constructorisnotinherited.
19)Canyoumakeaconstructorfinal?
No,constructorcan'tbefinal.

CoreJavaOOPsConcepts:statickeywordInterviewQuestions
20)Whatisstaticvariable?
1.staticvariableisusedtoreferthecommonpropertyofallobjects(thatisnotuniqueforeachobject)e.g.
companynameofemployees,collegenameofstudentsetc.
2.staticvariablegetsmemoryonlyonceinclassareaatthetimeofclassloading.
21)Whatisstaticmethod?
1.Astaticmethodbelongstotheclassratherthanobjectofaclass.
2.Astaticmethodcanbeinvokedwithouttheneedforcreatinganinstanceofaclass.
3.staticmethodcanaccessstaticdatamemberandcanchangethevalueofit.
22)Whymainmethodisstatic?
BecauseobjectisnotrequiredtocallstaticmethodifItwerenonstaticmethod,jvmcreatsobjectfirstthen
callmain()methodthatwillleadtotheproblemofextramemoryallocation.
23)Whatisstaticblock?
1.ItIsusedtoinitializethestaticdatamember.
2.Itisexcutedbeforemainmethodatthetimeofclassloading.
24)Canweexecuteaprogramwithoutmain()method?
Ans)Yes,oneofthewayisstaticblock.
25)Whatifthestaticmodifierisremovedfromthesignatureofthemainmethod?
Programcompiles.Butatruntimethrowsanerror"NoSuchMethodError".
26)Whatisdifferencebetweenstatic(class)methodandinstancemethod?
staticorclassmethod

instancemethod

1)Amethodi.e.declaredasstaticisknownasstatic
method.

Amethodi.e.notdeclaredasstaticisknownas
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
anotherclass.ItrepresentsISArelationship.ItisusedforCodeResusabilityandMethodOverriding.
29)Whichclassisthesuperclassforeveryclass?
Objectclass.
30)Whymultipleinheritanceisnotsupportedinjava?
Toreducethecomplexityandsimplifythelanguage,multipleinheritanceisnotsupportedinjavaincaseof
class.
31)Whatiscomposition?
Holdingthereferenceoftheotherclasswithinsomeotherclassisknownascomposition.
32)Whatisdifferencebetweenaggregationandcomposition?
Aggregationrepresentsweakrelationshipwhereascompositionrepresentsstrongrelationship.Forexample:bikehas
anindicator(aggregation)butbikehasanengine(compostion).
33)WhyJavadoesnotsupportpointers?
Pointerisavariablethatreferstothememoryaddress.Theyarenotusedinjavabecausetheyare
unsafe(unsecured)andcomplextounderstand.
34)Whatissuperinjava?
Itisakeywordthatreferstotheimmediateparentclassobject.
35)Canyouusethis()andsuper()bothinaconstructor?
No.Becausesuper()orthis()mustbethefirststatement.
36)Whatisobjectcloning?
Theobjectcloningisusedtocreatetheexactcopyofanobject.

You might also like