Select Category 
 

Java Interview Questions Answers

Java Interview Question - 1 : -

What is the difference between shallow copy and deep copy?

Java Interview Answer - 1 : -

Shallow copy shares the same reference with the original object like cloning, whereas the deep copy get a duplicate instance of the original object. If the shallow copy has been changed, the original object will be reflected and vice versa.
 

Java Interview Question - 2 : -

What is the Locale class?

Java Interview Answer - 2 : -

The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.
 

Java Interview Question - 3 : -

Can an inner class declared inside of a method access local variables of this method?

Java Interview Answer - 3 : -

It's possible if these variables are final.
 

Java Interview Question - 4 : -

What is clipping?

Java Interview Answer - 4 : -

Clipping is the process of confining paint operations to a limited area or shape.
 

Java Interview Question - 5 : -

What is the immediate superclass of the Dialog class?

Java Interview Answer - 5 : -

Window.
 

Java Interview Question - 6 : -

What is more advisable to create a thread, by implementing a Runnable interface or by extending Thread class?

Java Interview Answer - 6 : -

Strategically speaking, threads created by implementing Runnable interface are more advisable. If you create a thread by extending a thread class, you cannot extend any other class. If you create a thread by implementing Runnable interface, you save a space for your class to extend another class now or in future.
 

Java Interview Question - 7 : -

What  is Java?

Java Interview Answer - 7 : -

Java is an object-oriented programming language developed initially by James Gosling and colleagues at Sun Microsystems. The language, initially called Oak (named after the oak trees outside Gosling's office), was intended to replace C++, although the feature set better resembles that of Objective C. Java should not be confused with JavaScript, which shares only the name and a similar C-like syntax. Sun Microsystems currently maintains and updates Java regularly.
 

Java Interview Question - 8 : -

Can you write a Java class that could be used both as an applet as well as an application?

Java Interview Answer - 8 : -

A. Yes. Add a main() method to the applet.
 

Java Interview Question - 9 : -

When a thread blocks on I/O, what state does it enter?

Java Interview Answer - 9 : -

A thread enters the waiting state when it blocks on I/O.
 

Java Interview Question - 10 : -

What is an abstract method?

Java Interview Answer - 10 : -

An abstract method is a method whose implementation is deferred to a subclass. Or, a method that has no implementation.
 

Java Interview Question - 11 : -

What is the purpose of the finally clause of a try-catch-finally statement?

Java Interview Answer - 11 : -

The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.
 

Java Interview Question - 12 : -

Can a private method of a superclass be declared within a subclass?

Java Interview Answer - 12 : -

Sure. A private field or method or inner class belongs to its declared class and hides from its subclasses. There is no way for private stuff to have a runtime overloading or overriding (polymorphism) features.
 

Java Interview Question - 13 : -

How does Java handle integer overflows and underflows?

Java Interview Answer - 13 : -

It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.
 

Java Interview Question - 14 : -

What is a transient variable?

Java Interview Answer - 14 : -

A transient variable is a variable that may not be serialized.
 

Java Interview Question - 15 : -

What is an object's lock and which object's have locks?

Java Interview Answer - 15 : -

An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock. All objects and classes have locks. A class's lock is acquired on the class's Class object.