What is the difference between final, finally, finalize in java?

Final – it is a keyword, final variables are constants, final methods are not overridden in subclass, final class – we can not inherit final class.

Finally – in exception handling whether the exception is arise or not, finally block must execute its code.

Finalize – In java garbage collection, before an object is removed from memory finalize is called by the garbage collector. It releases the resources from that object.

What is the difference between Abstract class and Interface?

Abstract classes are partially defined classes in java.

Interface – fully abstract behavior

Various states of the Thread?

Ready, Running, Waiting, Dead

How to start a thread?

By inherited from a Thread class

By implement Runnable interface

What will do in finalize method?

Before an object is garbage collected some action are performed through finalize method

How we force a garbage collection?

We can’t force the garbage collector

What is Collection?

Collection represents group of objects. It is unordered one; allow duplicate elements and null values.

Difference between ArrayList and Vector?

ArrayList – non synchronized , memory size automatically increased by 1.5 times

Vector – synchronized, memory will be increased by double the size

Difference between ArrayList and LinkedList?

ArrayList – because of memory reallocation there is some performance degradation

LinkedList – it is not reallocated when increased

Write the code for Singleton design pattern?

Singleton pattern is a Creational pattern.

public class Singleton {
  private static final Singleton _theInstance = new Singleton();
  private Singleton() {
  }
  public static Singleton getInstance() {
    return _theInstance;
  }
 }
Advertisements