Quantcast
Viewing latest article 3
Browse Latest Browse All 15

Java 6.0 APIs

Java 6.0 introduces many Application Programming Interfaces and there are many enhancements in existing classes especially in collection APIs. The summary of changes in collection framework is listed below…

New Interfaces

  • Deque
  • BlockingDeque
  • NavigableSet
  • NavigableMap

New Classes

  • ArrayDeque
  • LinkedBlockingDeque
  • ConcurrentSkipListSet
  • ConcurrentSkipListMap
  • AbstractMap.SimpleEntry
  • AbstractMap.SimpleImmutableEntry

Updated Classes

  • LinkedList
  • TreeSet
  • TreeMap
  • Collections

Deque and ArrayDeque

Deque is the abbreviation for Double Ended Queue. It is a collection that allows to add and remove elements from both the ends. The implementations of Deque can be used as Stack or Queue. The Deque implementations use the insertion and remove method in two types,one used to throw exception to indicate failed operation while another one returns a special value as an indicator, in this case we often use null to indicate that collection is empty. So need to block the insertion of null values

ArrayDeque

ArrayDeque is one of the implements Deque. It has the following properties

  • No capacity restrictions.
  • Faster than stack and linked list when used as stack and queue.
  • ArrayDeque is considered to be not thread Safe.

BlockingDeque and LinkedBlockingDeque

BlockingDeque has similar properties of Deque with some additional functionalities. If we are trying to insert an element in to a BlockingDeque, that is already full, it will wait till the space becomes available to insert given element. The time limit to wait can be customized by the developer. BlockingDeque insertion and removal methods come in four types

  • Methods that throws exception
  • Methods that returns special values
  • Methods that waits indefinitely till space to available for insertion
  • Methods that waits for a specified time for space to be available for insertion

NavigableSet and ConcurrentSkipListSet

NavigableSet methods returns the closest matches of a given element for elements in the collection. NavigableSet methods lower, floor, ceiling, and higher return elements less than, less than or equal, greater than or equal, and greater than of a given element respectively. It returns null if there is no such element. NavigableSet can be accessed and traversed in either direction. ConcurrentSkipListSet is one of the implementations of NavigableSet.

NavigableMap and ConcurrentSkipListMap

It is similar to NavigableSet used to store key,values pairs. ConcurrentSkipListMap is one of the implementations of NavigableMap.

AbstractMap.SimpleEntry and AbstractMap.SimpleImmutableEntry

These are the static classes inside abstractMap class used to hold key, value pairs. The difference between these two classes is that AbstractMap.SimpleEntry allow programmers to set the value using setValue method while the AbstractMap.SimpleImmutableEntry throws UnsupportedOperationException if we try to set the value.

Modified classes

There are few changes introduced in the java 6 collections like LinkedList modified to implement Deque, TreeSet is modified so that it can implement NavigableSet and TreeMap modified to implement NavigableMap.

Java6.0 new features allows the programmer to develop easier retrieval of elements in desired way.

Julian is a professional content writer on Java Development at Telious Technologies.

Article Source: http://EzineArticles.com/?expert=Julian_Jaic

The post Java 6.0 APIs appeared first on CodingThis.


Viewing latest article 3
Browse Latest Browse All 15

Trending Articles