Interface java

THE LEGACY INTERFACE IN JAVA

0  0 2016-12-21 10:47:37

To Support the collection framework added in J2SE 1.2, some of the classes are reengineered, such classes are known as Legacy classes.
So these Legacy classes and interface are generalised in the JDK 5.

Java.util.* package defines all the legacy classes which are as follows:
 Dictionary
 Hash Table
 Properties
 Stack
 Vector

1.Enumeration Interface :  
Methods which are enumerating object via collection are defined in the enumeration interface. Enumerator interface suspended by iterator interface. But some of the legacy classes such as vectors and Properties which are use Enumeration interface methods.

Two methods used by Enumeration Interface:
 boolean hasMoreElements():
 Object nextElement():

boolean hasMoreElements() : Test and returns True or False the enumeration contains more elements or not .
Object nextElement() : Returns next element from the enumeration object has at least one object is provided.

2. Vector :
Vector implements a dynamic array same like ArrayList , but Vectors are synchronized for thread safety.
Another difference between Arraylist and vector is that vector contains many inheritance methods that are not part of the collections framework.

Vector has following constructors:
 Vector()
 Vector(int size)
 Vector(int size, int incr)
 Vector(collection c)

3. Stack :
Stack is subclass of vector class which execute as standard stack that is last In First out (LIFO) manner.
The default constructor define by the stack method provide the empty stack creation.

Following are methods of stack:
boolean empty()                 : Return true if stack is empty otherwise false.
Object peek()                      : without removing return topmost element.
Object pop()                        : return topmost element by removing it.
Object push(object element) : feed element into the stack.
Int search (object element )  : search element into entire stack by retuning position , if element is not found then return -1.

4. Hash Table :
The Hash Table class implements the map interface.
Java.lang.object
    |_java.util.dictionary
        |_java.util.Hashtable
We use the put and get method to store and retrieve the key/values pairs in a hashtables.
We can get an Enumeration object for the keys In a hashtable using the keys method.

 

Comments (0)

Post Your Comments

Headquarter



Hong Kong Office



Find Us On

Ziuby
Ziuby