Sie sind auf Seite 1von 12

2/10/2017 201CoreJavaInterviewQuestions|OOPsinterviewquestionsjavatpoint

201 Core Java Interview


Questions
90%assuranceofinterviewquestions

There is the list of 201 core java interview questions. If there is


any core java interview question that have been asked to you,
kindlypostitintheaskquestionsection.Weassurethatyouwill
get here the 90% frequently asked interview questions and
answers.

Theanswersofthecorejavainterviewquestionsareshortandto
the point. The core java interview questions are categorized in
Basics of java interview questions, OOPs interview questions,
String Handling interview questions, Multithreading interview
questions, collection interview questions, JDBC interview
questionsetc.

1 2 3 4 5 6 7 8

CoreJava:BasicsofJavaInterviewQuestions

1) What is difference between JDK,JRE and


JVM?

JVM

JVM is an acronym for Java Virtual Machine, it is an abstract


machine which provides the runtime environment in which java
bytecodecanbeexecuted.Itisaspecification.

JVMsareavailableformanyhardwareandsoftwareplatforms(so
JVMisplatformdependent).

JRE

JRE stands for Java Runtime Environment. It is the


implementationofJVM.

JDK

JDK is an acronym for Java Development Kit. It physically exists.


ItcontainsJRE+developmenttools.

http://www.javatpoint.com/corejavainterviewquestions 1/12
2/10/2017 201CoreJavaInterviewQuestions|OOPsinterviewquestionsjavatpoint

moredetails...

2) How many types of memory areas are


allocatedbyJVM?

Manytypes:

1.Class(Method)Area

2.Heap

3.Stack

4.ProgramCounterRegister

5.NativeMethodStack

moredetails...

3)WhatisJITcompiler?

JustInTime(JIT) compiler:It is used to improve the


performance. JIT compiles parts of the byte code that have
similar functionality at the same time, and hence reduces the
amount of time needed for compilation.Here the term compiler
refers to a translator from the instruction set of a Java virtual
machine(JVM)totheinstructionsetofaspecificCPU.

4)Whatisplatform?

A platform is basically the hardware or software environment in


whichaprogramruns.Therearetwotypesofplatformssoftware
based and hardwarebased. Java provides softwarebased
platform.

5) What is the main difference between Java


platformandotherplatforms?

The Java platform differs from most other platforms in the sense
that it's a softwarebased platform that runs on top of other
hardwarebasedplatforms.Ithastwocomponents:

1.RuntimeEnvironment

2.API(ApplicationProgrammingInterface)

http://www.javatpoint.com/corejavainterviewquestions 2/12
2/10/2017 201CoreJavaInterviewQuestions|OOPsinterviewquestionsjavatpoint

6) What gives Java its 'write once and run


anywhere'nature?

The bytecode. Java is compiled to be a byte code which is the


intermediate language between source code and machine code.
This byte code is not platform specific and hence can be fed to
anyplatform.

7)Whatisclassloader?

TheclassloaderisasubsystemofJVMthatisusedtoloadclasses
and interfaces.There are many types of classloaders e.g.
Bootstrap classloader, Extension classloader, System classloader,
Pluginclassloaderetc.

8) Is Empty .java file name a valid source file


name?

Yes, save your java file by .java only, compile it by javac .java
andrunbyjavayourclassnameLet'stakeasimpleexample:

1. //saveby.javaonly

2. classA{

3. publicstaticvoidmain(Stringargs[]){

4. System.out.println("Hellojava")

5. }

6. }

7. //compilebyjavac.java

8. //runbyjavaA

compileitbyjavac.java

runitbyjavaA

9) Is delete,next,main,exit or null keyword in


java?

No.

http://www.javatpoint.com/corejavainterviewquestions 3/12
2/10/2017 201CoreJavaInterviewQuestions|OOPsinterviewquestionsjavatpoint

10) If I don't provide any arguments on the


command line, then the String array of Main
methodwillbeemptyornull?

Itisempty.Butnotnull.

11) What if I write static public void instead of


publicstaticvoid?

Programcompilesandrunsproperly.

12) What is the default value of the local


variables?

Thelocalvariablesarenotinitializedtoanydefaultvalue,neither
primitivesnorobjectreferences.

CoreJavaOOPsConcepts:InitialOOPs
InterviewQuestions

There is given more than 50 OOPs (ObjectOriented Programming


and System) interview questions. But they have been categorized
in many sections such as constructor interview questions, static
interview questions, Inheritance Interview questions, Abstraction
interview question, Polymorphism interview questions etc. for
betterunderstanding.

13) What is difference between object oriented


programming language and object based
programminglanguage?

Object based programming languages follow all the features of


OOPs except Inheritance. Examples of object based programming
languagesareJavaScript,VBScriptetc.

14) What will be the initial value of an object


reference which is defined as an instance
variable?

TheobjectreferencesareallinitializedtonullinJava.

http://www.javatpoint.com/corejavainterviewquestions 4/12
2/10/2017 201CoreJavaInterviewQuestions|OOPsinterviewquestionsjavatpoint

CoreJavaOOPsConcepts:Constructor
InterviewQuestions

15)Whatisconstructor?

Constructorisjustlikeamethodthatisusedtoinitializethe
state of an object. It is invoked at the time of object
creation.

moredetails...

16)Whatisthepurposeofdefaultconstructor?

The default constructor provides the default values to the


objects.Thejavacompilercreatesadefaultconstructoronly
ifthereisnoconstructorintheclass.moredetails...

17)Doesconstructorreturnanyvalue?

Ans:yes, that is current instance (You cannot use return type yet
itreturnsavalue).moredetails...

18)Isconstructorinherited?

No,constructorisnotinherited.

19)Canyoumakeaconstructorfinal?

No,constructorcan'tbefinal.

CoreJavaOOPsConcepts:statickeyword
InterviewQuestions

20)Whatisstaticvariable?

static variable is used to refer the common property of all


objects (that is not unique for each object) e.g. company
nameofemployees,collegenameofstudentsetc.

static variable gets memory only once in class area at the


timeofclassloading.

http://www.javatpoint.com/corejavainterviewquestions 5/12
2/10/2017 201CoreJavaInterviewQuestions|OOPsinterviewquestionsjavatpoint

moredetails...

21)Whatisstaticmethod?

A static method belongs to the class rather than object of a


class.

A static method can be invoked without the need for


creatinganinstanceofaclass.

static method can access static data member and can


changethevalueofit.

moredetails...

22)Whymainmethodisstatic?

becauseobjectisnotrequiredtocallstaticmethodifItwere non
staticmethod,jvmcreatsobjectfirstthencallmain()methodthat
will lead to the problem of extra memory allocation.more
details...

23)Whatisstaticblock?

Isusedtoinitializethestaticdatamember.

It is excuted before main method at the time of


classloading.

moredetails...

24) Can we execute a program without main()


method?

Ans)Yes,oneofthewayisstaticblock.moredetails...

25) What if the static modifier is removed from


thesignatureofthemainmethod?

Program compiles. But at runtime throws an error


"NoSuchMethodError".

26) What is difference between static (class)


methodandinstancemethod?

http://www.javatpoint.com/corejavainterviewquestions 6/12
2/10/2017 201CoreJavaInterviewQuestions|OOPsinterviewquestionsjavatpoint

staticorclassmethod instancemethod
1)A method i.e. declared as static is A method i.e. not
knownasstaticmethod. declared as static is
known as instance
method.

2)Object is not required to call static Object is required to


method. callinstancemethods.

3)Nonstatic (instance) members cannot static and nonstatic


be accessed in static context (static variables both can be
method, static block and static nested accessed in instance
class)directly. methods.

4)For example: public static int cube(int For example: public


n){returnn*n*n} voidmsg(){...}.

CoreJavaOOPsConcepts:InheritanceInterview
Questions

27)Whatisthisinjava?

It is a keyword that that refers to the current object.more


details...

28)WhatisInheritance?

Inheritance is a mechanism in which one object acquires all the


properties and behaviour of another object of another class. It
represents ISA relationship. It is used for Code Resusability and
MethodOverriding.

moredetails...

29) Which class is the superclass for every


class.

Objectclass.

30)Whymultipleinheritanceisnotsupportedin
java?

http://www.javatpoint.com/corejavainterviewquestions 7/12
2/10/2017 201CoreJavaInterviewQuestions|OOPsinterviewquestionsjavatpoint

To reduce the complexity and simplify the language,


multiple inheritance is not supported in java in case of
class.moredetails...

31)Whatiscomposition?

Holdingthereferenceoftheotherclasswithinsomeotherclassis
knownascomposition.

32) What is difference between aggregation


andcomposition?

Aggregation represents weak relationship whereas composition


representsstrongrelationship.Forexample:bikehasanindicator
(aggregation)butbikehasanengine(compostion).

33)WhyJavadoesnotsupportpointers?

Pointerisavariablethatreferstothememoryaddress.Theyare
notusedinjavabecausetheyareunsafe(unsecured)andcomplex
tounderstand.

34)Whatissuperinjava?

It is a keyword that refers to the immediate parent class


object.moredetails...

35) Can you use this() and super() both in a


constructor?

No.Becausesuper()orthis()mustbethefirststatement.

36)Whatisobjectcloning?

The object cloning is used to create the exact copy of an object.


moredetails...

CoreJavaOOPsConcepts:MethodOverloading
InterviewQuestions

http://www.javatpoint.com/corejavainterviewquestions 8/12
2/10/2017 201CoreJavaInterviewQuestions|OOPsinterviewquestionsjavatpoint

37)Whatismethodoverloading?

If a class have multiple methods by same name but different


parameters, it is known as Method Overloading. It increases the
readabilityoftheprogram.moredetails...

38)Whymethodoverloadingisnotpossibleby
changingthereturntypeinjava?

Becauseofambiguity.moredetails...

39)Canweoverloadmain()method?

Yes,Youcanhavemanymain()methodsinaclassbyoverloading
themainmethod.

moredetails...

CoreJavaOOPsConcepts:MethodOverriding
InterviewQuestions

40)Whatismethodoverriding:

If a subclass provides a specific implementation of a method that


is already provided by its parent class, it is known as Method
Overriding. It is used for runtime polymorphism and to provide
thespecificimplementationofthemethod.moredetails...

41)Canweoverridestaticmethod?

No,youcan'toverridethestaticmethodbecausetheyarethepart
ofclassnotobject.

42)Whywecannotoverridestaticmethod?

Itisbecausethestaticmethodisthepartofclassanditisbound
with class whereas instance method is bound with object and
static gets memory in class area and instance gets memory in
heap.

43)Canweoverridetheoverloadedmethod?
http://www.javatpoint.com/corejavainterviewquestions 9/12
2/10/2017 201CoreJavaInterviewQuestions|OOPsinterviewquestionsjavatpoint

Yes.

44) Difference between method Overloading


andOverriding.

Method MethodOverriding
Overloading
1)Methodoverloading Method overriding provides the specific
increases the implementation of the method that is
readability of the alreadyprovidedbyitssuperclass.
program.

2) method Method overriding occurs in two classes


overlaoding is occurs thathaveISArelationship.
withintheclass.

3) In this case, Inthiscase,parametermustbesame.


parameter must be
different.

45)CanyouhavevirtualfunctionsinJava?

Yes,allfunctionsinJavaarevirtualbydefault.

46)Whatiscovariantreturntype?

Now, since java5, it is possible to override any method by


changing the return type if the return type of the subclass
overriding method is subclass type. It is known as covariant
returntype.moredetails...

CoreJavaOOPsConcepts:finalkeyword
InterviewQuestions

47)Whatisfinalvariable?

Ifyoumakeanyvariableasfinal,youcannotchangethevalueof
finalvariable(Itwillbeconstant).moredetails...

48)Whatisfinalmethod?

http://www.javatpoint.com/corejavainterviewquestions 10/12
2/10/2017 201CoreJavaInterviewQuestions|OOPsinterviewquestionsjavatpoint

Finalmethodscan'tbeoverriden.moredetails...

49)Whatisfinalclass?

Finalclasscan'tbeinherited.moredetails...

50)Whatisblankfinalvariable?

Afinalvariable,notinitalizedatthetimeofdeclaration,isknown
asblankfinalvariable.moredetails...

51)Canweintializeblankfinalvariable?

Yes,onlyinconstructorifitisnonstatic.Ifitisstaticblankfinal
variable, it can be initialized only in the static block.more
details...

52)Canyoudeclarethemainmethodasfinal?

Yes,suchas,publicstaticfinalvoidmain(String[]args){}.

next

1 2 3 4 5 6 7 8

Java Basics Interview Java OOPs Interview


Questions Questions

Java Multithreading Java String & Exception


InterviewQuestions InterviewQuestions

Java Collection JDBC Interview


InterviewQuestions Questions

Servlet Interview JSPInterviewQuestions


Questions

Spring Interview Hibernate Interview


Questions Questions

PL/SQL Interview SQLInterviewQuestions


Questions

http://www.javatpoint.com/corejavainterviewquestions 11/12
2/10/2017 201CoreJavaInterviewQuestions|OOPsinterviewquestionsjavatpoint

Oracle Interview Android Interview


Questions Questions

SQL Server Interview MySQL Interview


Questions Questions

http://www.javatpoint.com/corejavainterviewquestions 12/12

Das könnte Ihnen auch gefallen