Anda di halaman 1dari 13

7/18/2016

201 Core Java Interview Questions | OOPs interview questions javatpoint

ContentMenu

201 Core
Questions

Java

Interview

90%assuranceofinterviewquestions

Thereisthelistof201corejavainterviewquestions.Ifthereis
any core java interview question that have been asked to you,
kindly post it in the ask question section. We assure that you
will get here the 90% frequently asked interview questions and
answers.
The answers of the core java interview questions are short and
to 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

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.
JVMs are available for many hardware and software platforms
(soJVMisplatformdependent).

JRE
JRE stands for Java Runtime Environment. It is the
implementationofJVM.
http://www.javatpoint.com/corejavainterviewquestions

1/13

7/18/2016

201 Core Java Interview Questions | OOPs interview questions javatpoint

JDK
JDK is an acronym for Java Development Kit. It physically
exists.ItcontainsJRE+developmenttools.
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
amountoftimeneededforcompilation.Herethetermcompiler
refers to a translator from the instruction set of a Java virtual
machine(JVM)totheinstructionsetofaspecificCPU.

4)Whatisplatform?
Aplatformisbasicallythehardwareorsoftwareenvironmentin
which a program runs. There are two types of platforms
softwarebased and hardwarebased. Java provides software
basedplatform.

5) What is the main difference between Java


platformandotherplatforms?

http://www.javatpoint.com/corejavainterviewquestions

2/13

7/18/2016

201 Core Java Interview Questions | OOPs interview questions javatpoint

The Java platform differs from most other platforms in the


sense that it's a softwarebased platform that runs on top of
otherhardwarebasedplatforms.Ithastwocomponents:
1. RuntimeEnvironment
2. API(ApplicationProgrammingInterface)

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?
The classloader is a subsystem of JVM that is used to load
classesandinterfaces.Therearemanytypesofclassloaderse.g.
Bootstrap

classloader,

Extension

classloader,

System

classloader,Pluginclassloaderetc.

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


name?
Yes,saveyourjavafileby.javaonly,compileitbyjavac.java
andrunbyjavayourclassnameLet'stakeasimpleexample:
.

//saveby.javaonly

classA{

publicstaticvoidmain(Stringargs[]){

System.out.println("Hellojava")

//compilebyjavac.java

//runbyjavaA
compileitbyjavac.java
runitbyjavaA

http://www.javatpoint.com/corejavainterviewquestions

3/13

7/18/2016

201 Core Java Interview Questions | OOPs interview questions javatpoint

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


java?
No.

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


command line, then the String array of Main
methodwillbeemptyornull?
Itisempty.Butnotnull.

11)WhatifIwritestaticpublicvoidinsteadof
publicstaticvoid?
Programcompilesandrunsproperly.

12) What is the default value of the local


variables?
The local variables are not initialized to any default value,
neitherprimitivesnorobjectreferences.

CoreJavaOOPsConcepts:InitialOOPs
InterviewQuestions
There

is

given

more

than

50

OOPs

(ObjectOriented

Programming and System) interview questions. But they have


beencategorizedinmanysectionssuchasconstructorinterview
questions, static interview questions, Inheritance Interview
questions,

Abstraction

interview

question,

Polymorphism

interviewquestionsetc.forbetterunderstanding.

13)Whatisdifferencebetweenobjectoriented
programming language and object based
programminglanguage?
http://www.javatpoint.com/corejavainterviewquestions

4/13

7/18/2016

201 Core Java Interview Questions | OOPs interview questions javatpoint

Object based programming languages follow all the features of


OOPs

except

Inheritance.

Examples

of

object

based

programminglanguagesareJavaScript,VBScriptetc.

14) What will be the initial value of an object


reference which is defined as an instance
variable?
TheobjectreferencesareallinitializedtonullinJava.

CoreJavaOOPsConcepts:Constructor
InterviewQuestions

15)Whatisconstructor?
Constructor is just like a method that is used to initialize
the 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. The java compiler creates a default constructor
onlyifthereisnoconstructorintheclass.moredetails...

17)Doesconstructorreturnanyvalue?
Ans:yes, that is current instance (You cannot use return type
yetitreturnsavalue).moredetails...

18)Isconstructorinherited?
No,constructorisnotinherited.

19)Canyoumakeaconstructorfinal?
http://www.javatpoint.com/corejavainterviewquestions

5/13

7/18/2016

201 Core Java Interview Questions | OOPs interview questions javatpoint

No,constructorcan'tbefinal.

CoreJavaOOPsConcepts:statickeyword
InterviewQuestions

20)Whatisstaticvariable?
staticvariableisusedtoreferthecommonpropertyofall
objects (that is not unique for each object) e.g. company
nameofemployees,collegenameofstudentsetc.
staticvariablegetsmemoryonlyonceinclassareaatthe
timeofclassloading.
moredetails...

21)Whatisstaticmethod?
A static method belongs to the class rather than object of
aclass.
A static method can be invoked without the need for
creatinganinstanceofaclass.
static method can access static data member and can
changethevalueofit.
moredetails...

22)Whymainmethodisstatic?
because object is not required to call static method if It were
nonstatic method,jvm creats object first then call main()
method that will lead to the problem of extra memory
allocation.moredetails...

23)Whatisstaticblock?
Isusedtoinitializethestaticdatamember.
It is excuted before main method at the time of
classloading.
moredetails...
http://www.javatpoint.com/corejavainterviewquestions

6/13

7/18/2016

201 Core Java Interview Questions | OOPs interview questions javatpoint

24)Canweexecuteaprogramwithoutmain()
method?
Ans)Yes,oneofthewayisstaticblock.moredetails...

25)Whatifthestaticmodifierisremovedfrom
thesignatureofthemainmethod?
Program

compiles.

But

at

runtime

throws

an

error

"NoSuchMethodError".

26) What is difference between static (class)


methodandinstancemethod?
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.

call

instance

methods.
3)Nonstatic

(instance)

members static and nonstatic

cannot be accessed in static context variables both can be


(static method, static block and static accessed in instance
nestedclass)directly.
4)For

example:

public

methods.
static

cube(intn){returnn*n*n}

int For example: public


voidmsg(){...}.

CoreJavaOOPsConcepts:Inheritance
InterviewQuestions

27)Whatisthisinjava?

http://www.javatpoint.com/corejavainterviewquestions

7/13

7/18/2016

201 Core Java Interview Questions | OOPs interview questions javatpoint

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
representsISArelationship.ItisusedforCodeResusabilityand
MethodOverriding.
moredetails...

29) Which class is the superclass for every


class.
Objectclass.

30) Why multiple inheritance is not supported


injava?
To reduce the complexity and simplify the language,
multiple inheritance is not supported in java in case of
class.moredetails...

31)Whatiscomposition?
Holdingthereferenceoftheotherclasswithinsomeotherclass
isknownascomposition.

32) What is difference between aggregation


andcomposition?
Aggregation represents weak relationship whereas composition
represents strong relationship. For example: bike has an
indicator(aggregation)butbikehasanengine(compostion).

33)WhyJavadoesnotsupportpointers?
http://www.javatpoint.com/corejavainterviewquestions

8/13

7/18/2016

201 Core Java Interview Questions | OOPs interview questions javatpoint

Pointer is a variable that refers to the memory address. They


are not used in java because they are unsafe(unsecured) and
complextounderstand.

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?
Theobjectcloningisusedtocreatetheexactcopyofanobject.
moredetails...

CoreJavaOOPsConcepts:Method
OverloadingInterviewQuestions

37)Whatismethodoverloading?
If a class have multiple methods by same name but different
parameters,itisknownasMethodOverloading.Itincreasesthe
readabilityoftheprogram.moredetails...

38)Whymethodoverloadingisnotpossibleby
changingthereturntypeinjava?
Becauseofambiguity.moredetails...

39)Canweoverloadmain()method?

http://www.javatpoint.com/corejavainterviewquestions

9/13

7/18/2016

201 Core Java Interview Questions | OOPs interview questions javatpoint

Yes, You can have many main() methods in a class by


overloadingthemainmethod.
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 the specific implementation of the method.more
details...

41)Canweoverridestaticmethod?
No, you can't override the static method because they are the
partofclassnotobject.

42)Whywecannotoverridestaticmethod?
It is because the static method is the part of class and it is
bound with class whereas instance method is bound with object
andstaticgetsmemoryinclassareaandinstancegetsmemory
inheap.

43)Canweoverridetheoverloadedmethod?
Yes.

44) Difference between method Overloading


andOverriding.
Method
Overloading

MethodOverriding

http://www.javatpoint.com/corejavainterviewquestions

10/13

7/18/2016

201 Core Java Interview Questions | OOPs interview questions javatpoint

1)

Method Methodoverridingprovidesthespecific

overloading increases implementation of the method that is


the readability of the alreadyprovidedbyitssuperclass.
program.
2)

method Method

overriding

occurs

in

two

overlaoding is occurs classesthathaveISArelationship.


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?
If you make any variable as final, you cannot change the value
offinalvariable(Itwillbeconstant).moredetails...

48)Whatisfinalmethod?
Finalmethodscan'tbeoverriden.moredetails...

49)Whatisfinalclass?
http://www.javatpoint.com/corejavainterviewquestions

11/13

7/18/2016

201 Core Java Interview Questions | OOPs interview questions javatpoint

Finalclasscan'tbeinherited.moredetails...

50)Whatisblankfinalvariable?
A final variable, not initalized at the time of declaration, is
knownasblankfinalvariable.moredetails...

51)Canweintializeblankfinalvariable?
Yes, only in constructor if it is nonstatic. If it is static blank
final variable, it can be initialized only in the static block.more
details...

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

next
1

Java

Basics

InterviewQuestions
Java

Java

Servlet

Spring

JDBC

Interview

Questions
JSP

Interview

Interview

Hibernate

Interview

Questions
Interview

Questions
Oracle

InterviewQuestions

Questions

Questions
PL/SQL

JavaString&Exception

Interview

Questions

Questions

Collection

InterviewQuestions

Java OOPs Interview

Multithreading

InterviewQuestions

SQL

Interview

Questions
Interview

http://www.javatpoint.com/corejavainterviewquestions

Android

Interview
12/13

7/18/2016

201 Core Java Interview Questions | OOPs interview questions javatpoint

Questions

Questions

SQL Server Interview


Questions

MySQL

Interview

Questions

http://www.javatpoint.com/corejavainterviewquestions

13/13

Anda mungkin juga menyukai