Java Interview Questions

What does a default member mean?

A default member is one that does not have any of the modifiers like public, protected or private.

If a class contains more than one or more final methods must the class be declared final?

No, it not required to make the class final if it has any final methods. But if a class is final it is not necessary that the methods should be declared as final.

What is the difference between String class and StringBuffer class?

A String object is immutable which means the object cannot be changed. But in the case of StringBuffer class it provides the option of modifying String.

What does Java Sandbox term mean?

Sandbox is the term used to describe the security model used by java when running programs. This model provides an interface between a java application and operating

system resource that can be configured by end user.

What is a Thread?

Thread is a light weight process. In java thread is the current program in execution. JVM allows an application to have multiple threads of execution thus supporting


What are the two approaches for writing code that create a new Thread of control?

The two approaches are:

  1. Extend the Thread class in java.lang package and override the run() method
  2. Implement the Runnable interface and implement run() method

What method is used to start the execution of the thread?

start() method is used to start the execution of the thread. This inturn calls the run() method.

What is the purpose of synchronized keyword?

The keyword ‘synchronized’ provides a solution to protect object data from being accessed by more than one thread, which could make the object have an invalid state.

READ  Getting started with Java

What is collection?

A collection is a group of objects which will be treated as a single object.

What is an Iterator?

Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows us to walk through a collection of

objects, operating on each object in turn. Generally it is not advisable to modify the collection itself while traversing an Iterator.

Difference between hash map and hash table?

The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. (HashMap allows null values as key and value whereas

Hashtable does not allow). HashMap does not guarantee that the order of the map will remain constant over time. HashMap is unsynchronized and Hashtable is synchronized

What is serialization?

Serialization is a mechanism by which you can save the state of an object by converting it to a byte stream.

Difference between swing and AWT?

Both the AWT and swing supports GUI programming in Java. AWT are heavy-weight components as it has the native code called peer. Swings are light-weight components as

it does not have the native code but built entirely in java programming language. Hence swing works faster than AWT.

What is the difference between ServerSocket and DatagramSocket transport protocol?

DatagramSocket is used for UDP communication which is a connectionless protocol whereas ServerSocket is used for TCP communication which is a connection oriented


What are checked and unchecked Exception?

Checked exceptions are those which occur at compile time. Eg: IOException. Unchecked exceptions are those which occur at run time. Eg: StringIndexOutOfBoundsException.