UTIL Programming Questions & Answers

Explore model answers categorized by subjects like Java, HTML, DBMS, and more.

UTIL Programming Questions & Answers

What is Util?

Answer:
Util is a Java Package

Explain Set Interface?

Answer:
The List interface provides support for ordered collections of objects.

What is the Collections API?

Answer:
The Collections API is a set of classes and interfaces that support operations on collections of objects.
 	

What is the difference between Enumeration and Iterator interface?

Answer:
The Enumeration interface allows you to iterate through all the elements of a collection. Iterating through an Enumeration is similar to iterating through an Iterator. However, there is no removal support with Enumeration.

Explain Enumeration Interface?

Answer:
The Enumeration interface allows you to iterate through all the elements of a collection. Iterating through an Enumeration is 

similar to iterating through an Iterator. However, there is no removal support with Enumeration.
Basic methods:
boolean hasMoreElements();
Object nextElement();

What is an Iterator interface?

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

Explain Java Collections Framework?

Answer:
Java Collections Framework provides a well designed set of interfaces and classes that support operations on a collection of objects.

Explain Iterator Interface and main method of Iterator?

Answer:
An Iterator is similar to the Enumeration interface. With the Iterator interface methods, you can traverse a collection from start to end and safely remove elements from the underlying collection. The iterator() method generally used in query 

operations.
Basic methods:
iterator.remove();
iterator.hasNext();
iterator.next();

What are the two types of Set implementations available in the Collections Framework?

Answer:
HashSet and TreeSet are the two Set implementations available in the Collections Framework.

What is the difference between HashSet and TreeSet?

Answer:
HashSet Class implements java.util.Set interface to eliminate the duplicate entries and uses hashing for storage. Hashing is 

nothing but mapping between a key value and a data item, this provides efficient searching.

The TreeSet Class implements java.util.Set interface provides an ordered set, eliminates duplicate entries and uses tree for 

storage.

What is the difference between ArrayList and LinkedList?

Answer:
The ArrayList Class implements java.util.List interface and uses array for storage. An array storage’s are generally faster 

but we cannot insert and delete entries in middle of the list. To achieve this kind of addition and deletion requires a new 

array constructed. You can access any element at randomly.

The LinkedList Class implements java.util.List interface and uses linked list for storage. A linked list allow elements to be 

added, removed from the collection at any location in the container by ordering the elements. With this implementation you 

can only access the elements in sequentially.

Explain Map Interface?

Answer:
A map is a special kind of set with no duplicates. The key values are used to lookup, or index the stored data. The Map 

interface is not an extension of Collection interface, it has it’s own hierarchy. Map does not allow duplicates in the 

collection. In Map implementations null is valid entry, but allowed only once.

What are the two types of Map implementations available in the Collections Framework?

Answer:
HashMap and TreeMap are two types of Map implementations available in the Collections Framework.

What is the difference between HashMap and TreeMap?

Answer:
The HashMap Class implements java.util.Map interface and uses hashing for storage. Indirectly Map uses Set functionality so, 

it does not permit duplicates. The TreeMap Class implements java.util.Map interface and uses tree for storage. It provides 

the ordered map.

Explain the functionality of Vector Class?

Answer:
Once array size is set you cannot change size of the array. To deal with this kind of situations we use Vector. Vector grows 

and shrink it’s size automatically. Vector allows to store only objects not primitives. To store primitives, convert 

primitives in to objects using wrapper classes before adding them into Vector. The Vector reallocates and resizes itself 

automatically.

What does the following statement convey?

Answer:
Vector vt = new Vector(3, 10);
vt is an instance of Vector class with an initial capacity of 3 and grows in increment of 10 in each relocation

What is the difference between Vector and ArrayList?

Answer:
Vector and ArrayList are very similar. Both of them represent a growable array. The main difference is that Vector is synchronized while ArrayList is not.

What is the difference between Hashtable and HashMap?

Answer:
Both provide key-value access to data. The key differences are :
a. Hashtable is synchronised but HasMap is not synchronised.
b. HashMap permits null values but Hashtable doesn’t allow null values.
c. iterator in the HashMap is fail-safe while the enumerator for the Hashtable is not fail safe.

How do I make an array larger?

Answer:
You cannot directly make an array larger. You must make a new (larger) array and copy the original elements into it, usually with System.arraycopy(). If you find yourself frequently doing this, the Vector class does this automatically for you, as long as your arrays are not of primitive data types.

What is the use of Locale class?

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

What is the use of ResourceBundle class?

Answer:
The ResourceBundle class is used to store locale-specific resources that can be loaded by a program to tailor the program’s appearance to the particular locale in which it is being run.