Top 100 Java Interview Ques & Ans
Top 100 Java Interview Ques & Ans
Answer: Java encapsulates the codes in various classes which define new data types.These new data
types are used to create objects.
2. What is a JVM?
Answer: JVM is Java Virtual Machine which isa run time environment for the compiled java class files.
Answer: BigDecimal, if memory is not a concern and Performance, is not critical, otherwise double with
predefined precision.
Interpreted
Multi-threaded
8. What restrictions are placed on the location of a package statement within a source code file?
Answer: Apackage statement must appear asthe first line in a source code file (eliminatingblank lines
and comments).
a container's layout? layout.
used to specify
is specify
a container's
9. What method used to
method is
The setLayout()
Answer:
class?
of the Applet class.
superclass of the Applet
the immediate
10. What is
the immediate
superclass
is
class
Answer: The
Panel
no
the default one
identifier
in Java?
are the access modifiers and private, and
11.What protected
modifiers. Public, explicitly.
There are 3access specify the friendly identifier
Answer: cannot
friendly,
but programmer
is called
is specified
and
are packages? access protection
12. What is
and interfaces providing
is a collection of related classes
Answer: A package
namespacemanagement.
initialized?
15.what value is a variable of the String type automatically
Answer: The Panel and Applet classes use the Flow Layout astheir default layout.
2)If the constant name is a combination of two words it should be separated by an underscore.
3)Constant names are usually nouns.
Ex:MAX_ VALUE, MIN_VALUE, MAX_PRIORITY, MIN PRIORITY
resources. And it is importantbecause, without it, it is not possible for one thread to modify a shared
object while anotherthread is in the process of using or updating that object's value. This often leads to
major errors.
deliberately incomplete.
event handling?
interfaces support
uticlasses and
processing.
support event
26. Which jave: the Event Listener interface
Object class and
Answer: The Event
capablebrowser
31. What's new with the stop(), suspend() and resume() methods in JDK 1.2 ?
Answer:
33. What is the difference between the >> and >>> operators?
Answer: The >> operator carries the SIgn bit when shiting right while the >>> zero-fills bits that have
been shifted out.
34. What is the difference betweenthis() and super()?
be used to
whereas super() can
constructor of thesame
class
constructor.
invoke a super class
What is method?
a native
a language other than
35. Java.
method that is applied in
Answer: A native method is a
(GUI)widgets.
usefulcapabilities,
such as graphical user interface
variables in Java?
38. Why there are no global variables due
not support globally accessible
accessible.Java does
variables are globally
Answer:Global
to following reasons:
transparency
The global variables breaks the
referential
collisions in namespace.
Global variables creates
it
a
Iterators let elements of
to go through all the
Iterators are a generic way
Stream?
Reader/Writer and InputStream/Output
42. What isthe difference between
class is hto
class is character-oriented
and the Inputstream/OutputStream
Answer: The Reader/Writer
oriented.
44.What is clipping?
Answer: Clipping is the process of confining paint operations to a limited area or shape.
A memory leak is where an unreferenced object that will never be used again still hangs around in
memory and doesnt get garbage collected.
:
Ex toString()
uppercase letter.
Ex :getCarName(),getCarNumber()
4S. Why Java is not a pure Object Oriented language?
Answer: Java supports primitive types such as int, byte, short, long,etc that why it is not said to be a
pure object-oriented language.
Answer: It contains the executable body that can be applied to the specific object of the class.
The method includes method name, parameters or arguments and return type and a body of executable
code.
methods can have multiple arguments. Separate with commas when we have multiple arguments.
Answer:
done the following conditions are met:
Java automatic type conversion is if
assigned to long
to long .Automatic type conversion takes place
if int is
Int can be assigneddirectly
53.What is the difference betweenthe prefix and postfix forms of the ++ operator?
Example: Employeeemployee;
In the above example employee obiect is not instantiate so it is pointed nowhere.
57.Define How many objects are created in the following piece of code?
MyClass c1, c2, c3;
c1 =new MyClass();
c3 =new MyClass();
Answer: Only 2 objects are created, c1 and c3. The reference c2 is only declared and not initialized.
58.What is JSP?
Answer: JSP is a technology that returns dynamic content to the Web client
JAVAelements.
JSP page looks
using HTML, XML and
like a HTML page but is a servlet. It contains Presentation logic
andbusiness logic of. aweb application.
60.Explain where
variables are created
in memory?
Answer: When we
declare variables are
created in the
variables get garbage stack. So when
collected. the variable is out of scope tno
we use catch statement for checked exceptions?
61. Can
our code then we can't declare catch block for
there is no chance of raising an exception in
Answer: If
63.Whatis UNICODE?
and it uses 16 bits to
used for internal representation of characters and strings
Answer:Unicode is
in java?
64. Explain aboutthe main() method
point of execution for all java applications.
Answer: The main ()method is the starting
public static void main(String[] args) {}
command line arguments.
we need to pass from
String args[] are an array of string objects
must have at least one main method.
Every Java application
Default Constructor
Parameterized Constructor
of an object on
the heap?
the size
the heap.
68. How can we find
actual
size of an object on
no way to find out the actual
In Java, there is
Answer:
can't be static as
Answer: No avariable
methods in an Interface?
70. Can we have static
in an interface are by
be overridden in any class while any methods
methods can't
being implementing the interface.
Answer: Static
implemented in the classes
default and are supposed to be
abstract
methods in an interface in Java.
Soit makes no sense to have static
java?
71. In how rary wayswecardosyncronization in
Answer:
in java:
There are two ways to do synchronization
1) Synchronized methods
2)Synchronized blocks
To do synchronization we use the synchronized keyword.
blocks?
72. When use synchronized blocks and advantages of using synchronized
do we
then it is recommended to use synchronized
Answer: If very few lines of code require synchronization
73. What is the difference between access specifiers and access modifiers in java?
Answer: In C++ we have access specifiers as public, private, protected and default and access modifiers
as static, final. But there is no such division of access specifiers and access modifiers in java. In Java, we
have access to modifiers and nonaccess modifiers.
Answer: In java, each object when created gets a memory space from a heap. When an object is
destroyed by a garbage collector, the space allocated to it from the heap is re-allocated to the heap and
becomes available for any new objects.
75. What access modifiers can be used for class?
Answer: We can use only two access modifiersfor class public and default.
default: class
A with default modifier can be accessed
Answer:
that extends it. In such a case,
the methods in a class. We want to leave
the implementation to a class
implementation.
classes are:
The important features of abstract
a constructor in
Answer:We can create
class.
forabstract
when we cannot a constructor
is nouse in creating
class there
instan tiate
String andStringBuffer
Can we compare
in
String objects.
both represent
78. String and 1 StringBuffer
threads in java?
many ways we can create
79. In how
Answer:
:
java by any of the two ways
We can create threads in
block executeswith no exceptionsthen finally is called after try block without executing catch block. If
exception is thrown, finally block will be executed even if the no catch block handles the exception.
handling reduces
java?
86.What are abstract methods
in
method declared
doesn't have anybody. An
is
abstract
is a method which
Answer: An abstractmethod
in place of the method
body.
withkeyword abstractand semicolon
Signature :public abstractvoid ();
java?
where exceptions may arise in
87.Statesomesituations
Answer:
not exist in the array.
1)Accessing an element that does
toa number.
of number to string and
string
<) Invalid conversion
(NumberFormat Exception)
3)The invalid casting of class
(Class cast Exception)
class
for interfaceor abstract
)Irying to create an object
(Instantiation Exception)
in java?
88. What isan exception
arise in our program.
Answer:
when abnormal situations
Exceptions are created
classes are defined
is an object. in
In java,an exception code. All Exception
by our application
can be created by JVM or
Exceptions
we can say Exception as a run time
error.
handling in java?
90. What are the advantages of Exception
Answer:
termination of the program.
handling code to avoid abnormal
1)Separating normal code from exception
handling all exceptions with
2) Categorizing into different
types of Exceptions so that rather than
specific exceptions. It is recommended
to handle exceptions
Exception root class we can handle with
Exception root class.
with specific Exception instead of handling with
a meth od throws an exception and it is not handled immediately, then that
3) Call stack mechanism: If
Answer: Constructors must have the same name as the class and can not return a value. They are only
called once while regular methodscould be called many times.
Answer: Private constructor isused if youdo not want other classes to instantiate the obiect
prevent subclassing. andto
casting?
94. What is type
Type casting means treating a variable of one type as though it is another type.
Answer:
shifted
out.
access modifier of the inner class is static, then it becomes nested class.
syntax.
Answer:Yes, use this()
classes?
98. Why do we need wrapper
also
expects an object. It
java, example:06
leading zero in
Answer:Octal Numbers are denoted by