Set - 1

Question 1 :

What is Collection API ?

Answer :

The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces.
Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.
Example of interfaces: Collection, Set, List and Map.

Question 2 :

Is Iterator a Class or Interface? What is its use?

Answer :

Answer: Iterator is an interface which is used to step through the elements of a Collection.

Question 3 :

What is similarities/difference between an Abstract class and Interface?

Answer :

Differences are as follows:
Interfaces provide a form of multiple inheritance. A class can extend only one other class. Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc.
A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class. Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast.

Neither Abstract classes or Interface can be instantiated.

Question 4 :

Java Interview Questions - How to define an Abstract class? 

Answer :

A class containing abstract method is called Abstract class. An Abstract class can't be instantiated.
Example of Abstract class:

abstract class testAbstractClass {
	protected String myString; 
	public String getMyString() { 
		return myString; 
	public abstract string anyAbstractFunction();


Question 5 :

How to define an Interface in Java ?

Answer :

In Java Interface defines the methods but does not implement them. Interface can include constants. A class that implements the interfaces is bound to implement all the methods defined in Interface.
Emaple of Interface:

public interface sampleInterface {
	public void functionOne();
	public long CONSTANT_ONE = 1000;