Skip to main content

Introduction to Java Programming

  What is Java? Java is a programming language and a platform. Java is a high-level, robust, object-oriented and secure programming language. Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in the year 1995. James Gosling is known as the father of Java. Firstly, it was called  Greentalk  and the file extension was  .gt . After that, it was called  Oak . Initially Java was designed for small, embedded systems in electronic appliances like set-top boxes. Platform:  Any hardware or software environment in which a program runs, is known as a platform. Since Java has a runtime environment (JRE) and API(Application Programming Interface), it is called a platform. The principles for creating Java programming were "Simple, Robust, Portable, Platform-independent, Secured, High performance, Multithreaded, Architecture neutral, Object-oriented, Interpreted, and Dynamic". Currently, Java is used in internet programming, mobile devices, games, e-business so

29. Collection Framework in Java

 

Collection Framework in Java

  • Any group of individual objects which are represented as a single unit is known as the collection of objects.
  • framework is a set of classes and interfaces which provide a ready-made architecture.
  • In Java, a separate framework named the "Collection Framework" has been defined in JDK 1.2 which holds all the collection classes and interface in it.
  • Before the Collection Frameworks was introduced, the standard methods for grouping Java objects were Arrays or Vectors or Hashtables.

Hierarchy of the Collection Framework

  • The utility package (java.util) contains all the classes and interfaces that are required by the collection framework.
  • The Iterator interface provides the facility of iterating the elements in a forward direction. It is the root interface for all the collection classes.
  • The Iterator interface helps easily to retrieve the elements of a collection and perform operations on each element.
  • The Collection interface is not directly implemented by any class. However, it is implemented indirectly via its sub-types or sub-interfaces like List, Queue, and Set.

Collections in Java

  • List interface: It inhibits a list type data structure in which we can store the ordered collection of objects.
  • ArrayList class: It uses a dynamic array internally to store the duplicate elements.
  • LinkedList class: It uses a doubly linked list internally to store the duplicate elements.
  • Vector class: It uses a dynamic array to store the data elements. It is similar to ArrayList.
  • Stack class: It implements the Last-in-First-out data structure i.e. stack.
  • Queue interface: It maintains the First-in-First-out order. It can be defined as an ordered list that is used to hold the elements which are about to be processed.
  • PriorityQueue class: It holds the objects which are to be processed by their priority. It doesn't allow null values to be stored in queue.
  • Deque Interface: Dequeue stands for a double-ended queue which enables us to perform the operations at both the ends.
  • ArrayDeque: It also enables us to perform operations at both the ends. It is faster than ArrayList and Stack.
  • Set Interface: It represents the unordered set of elements which doesn't allow us to store the duplicate items.
  • HashSet class: It represents the collection of unique items that uses a hash table for storage.
  • LinkedHashSet class: It is an ordered version of HashSet that maintains a doubly-linked list across all elements.
    When iterating through a HashSet the order is unpredictable, while a LinkedHashSet lets us iterate through the elements in the order in which they were inserted.
  • SortedSet interface: It is a alternate of Set interface in which the elements are arranged in the ascending order.
  • TreeSet class: It uses a tree for storage of unique elements in ascending order.

Comments