Interface Java Interview Questions – Set 03

What is the Collection interface

The Collection interface provides support for the implementation of a mathematical bag – an unordered collection of objects that may contain duplicates.

Which java.util classes and interfaces support event handling?

The EventObject class and the EventListener interface support event processing.

The sizeof operator is not a keyword.

What is the class and interface in java to create thread and which is the most advantageous method?

Thread class and Runnable interface can be used to create threads and using Runnable interface is the most advantageous method to create threads because we need not extend thread class here.

What method must be implemented by all threads

All tasks must implement the run() method, whether they are a subclass of Thread or implement theRunnable interface.

What interface is extended by AWT event listeners

All AWT event listeners extend the java.util.EventListener interface.

What are the classes and interfaces for servlets?-

There are two packages in servlets and they are javax. servlet and

What is interface and its use?-

Interface is similar to a class which may contain method’s signature only but not bodies and it is a formal set of method and constant declarations that must be defined by the class that implements it. Interfaces are useful for: a)Declaring methods that one or more classes are expected to implement b)Capturing similarities between unrelated classes without forcing a class relationship. c)Determining an object’s programming interface without revealing the actual body of the class.

Can you explain the core collection interfaces?

There are six interfaces and come under two different inheritance group one which comes under the collection interface root and the other in the map interface root.

Collection

It’s the base of all collection classes. It provides a unified way to manipulate collection objects. Collection has group of object called as elements. These elements can be accessed and manipulated using Iterator. List

In List interface the elements are arranged sequentially. Elements can be inserted in to any location and you can also insert duplicate elements. In order to access the elements you need to use the “ListIterator”. Using “ListIterator” you can move back and forth which makes it unique as compared to other iterators.

Set

It represents a collection but no duplicates are allowed in this case.

SortedSet

It extends the Set interface and sorts the set in ascending order.

Map

Map stores association between keys and value pairs. So given a key you can easily find the value. One thing important to note is they do not implement iterable interface. But yes you can obtain a collection view of the map which allows you loop using for loop.

SortedMap

It extends Map so that the keys are maintained in ascending order.

What are the legal operands of the instanceof operator

The left operand is an object reference or null value and the right operand is a class, interface, or arraytype.

What is an Iterator interface?

The Iterator interface is used to step through the elements of a Collection.

The Iterator is an interface, used to traverse through the elements of a Collection. It is not advisable to modify the collection itself while traversing an Iterator.