Java Interview Q&A
Java Interview Q&A
com
9123820085
JAVA INTERVIEW
QNAS
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
2. What is a JVM?
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
Answer: When a Java program contains more than one methods with
the same name but different properties, then it is called method
overloading.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
Answer: Yes, we can rethrow the same exception from our catch
handler. If we want to rethrow checked exception from a catch block we
need to declare that exception.
Answer: The Panel and Applet classes use the Flow Layout as their
default layout.
Answer: Constants in java are created using static and final keywords.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
4) If there are multiple words every inner world should start with
Uppercase character. Ex : string,value,empName,MEP salary
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
25. What modifiers may be used with an inner class that is a member of
an outer class?
26. Which java. util classes and interfaces support event handling?
Answer: The Event Object class and the Event Listener interface support
event processing.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
31. What’s new with the stop(), suspend() and resume() methods in JDK
1.2 ?
Answer: These methods have been deprecated in JDK 1.2.
33. What is the difference between the >> and >>> operators?
Answer: The >> operator carries the sign bit when shifting right while the
>>> zero-fills bits that have been shifted out.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
36. What value does read Line() return when it has reached the end of a
file?
Answer: The readLine() method returns null when it has reached the
end of a file.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
They do not have return types, not even void and therefore they cannot
return values. They cannot be inherited, though a derived class can call
the base class constructor.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
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.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
53. What is the difference between the prefix and postfix forms of the ++
operator?
Answer: The prefix form performs the increment operation and returns
the value of the increment operation. The postfix form returns the
current value all of the expression and then performs the increment
operation on that value.
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.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
Answer: The main () method is the starting point of execution for all
java applications. public static void main(String[] args) {}
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
68. How can we find the actual size of an object on the heap?
Answer: In Java, there is no way to find out the actual size of an object
on the heap.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
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.
Answer: We can use only two access modifiers for class public and
default. public: A class with a public modifier can be visible
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
when we cannot
Run is the starting point for execution for another thread within our
program. Example :
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
82. Can we cast any other type to Boolean Type with type casting?
Answer: No, we can neither cast any other primitive type to Boolean
data type nor can cast Boolean data typeto any other primitive data
type.
85. Can we catch more than one exception in a single catch block?
Answer: From Java 7, we can catch more than one exception with a
single catch block. This type of handling reduces the code duplication.
Note: When we catch more than one exception in a single catch block,
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
Ex : catch(ArrayIndexOutOfBoundsException || ArithmeticException e)
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
Answer: Constructors must have the same name as the class and can
not return a value. They are only called once while regular methods
could be called many times.
Answer: Yes, since inheritance inherits everything from the super class
and interface, it may make the subclass too clustering and sometimes
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
95. What is the difference between the >> and >>> operators?
Answer: The >> operator carries the sign bit when shifting right. The >>>
zero-fills bits that have been shifted out.
96. What is the difference between inner class and nested class?
97. Can you call one constructor from another if a class has multiple
constructors?
Answer: Yes, use this() syntax.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
9123820085
hr@kasperanalytics.com
kasper-analytics