Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Collections Class in Java
Next article icon

Collections in Java

Last Updated : 21 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
Try it on GfG Practice
redirect icon

Any group of individual objects that are represented as a single unit is known as a Java Collection of Objects. In Java, a separate framework named the "Collection Framework" has been defined in JDK 1.2 which holds all the Java Collection Classes and Interface in it. 

In Java, the Collection interface (java.util.Collection) and Map interface (java.util.Map) are the two main “root” interfaces of Java collection classes.

What You Should Learn in Java Collections?

  • List Interface
    • Abstract List Class
    • Abstract Sequential List Class
    • Array List
    • Vector Class
    • Stack Class
    • LinkedList Class
  • Queue Interface
    • Blocking Queue Interface
    • AbstractQueue Class
    • PriorityQueue Class
    • PriorityBlockingQueue Class
    • ConcurrentLinkedQueue Class
    • ArrayBlockingQueue Class
    • DelayQueue Class
    • LinkedBlockingQueue Class
    • LinkedTransferQueue
  • Deque Interface
    • BlockingDeque Interface
    • ConcurrentLinkedDeque Class
    • ArrayDeque Class
  • Set Interface
    • Abstract Set Class
    • CopyOnWriteArraySet Class
    • EnumSet Class
    • ConcurrentHashMap Class
    • HashSet Class
    • LinkedHashSet Class
  • SortedSet Interface
    • NavigableSet Interface
    • TreeSet
    • ConcurrentSkipListSet Class
  • Map Interface
    • SortedMap Interface
    • NavigableMap Interface
    • ConcurrentMap Interface
    • TreeMap Class
    • AbstractMap Class
    • ConcurrentHashMap Class
    • EnumMap Class
    • HashMap Class
    • IdentityHashMap Class
    • LinkedHashMap Class
    • HashTable Class
    • Properties Class
  • Other Important Concepts
    • How to convert HashMap to ArrayList
    • Randomly select items from a List
    • How to add all items from a collection to an ArrayList
    • Conversion of Java Maps to List
    • Array to ArrayList Conversion
    • ArrayList to Array Conversion
    • Differences between Array and ArrayList

   

What is a Framework in Java?

A framework is a set of classes and interfaces which provide a ready-made architecture. In order to implement a new feature or a class, there is no need to define a framework. However, an optimal object-oriented design always includes a framework with a collection of classes such that all the classes perform the same kind of task. 

Need for a Separate Collection Framework in Java

Before the Collection Framework(or before JDK 1.2) was introduced, the standard methods for grouping Java objects (or collections) were Arrays or Vectors, or Hashtables. All of these collections had no common interface. Therefore, though the main aim of all the collections is the same, the implementation of all these collections was defined independently and had no correlation among them. And also, it is very difficult for the users to remember all the different methods, syntax, and constructors present in every collection class. 
Let's understand this with an example of adding an element in a hashtable and a vector. 

Example:

Java
// Java program to demonstrate // why collection framework was needed import java.io.*; import java.util.*;  class CollectionDemo {      public static void main(String[] args)     {         // Creating instances of the array,         // vector and hashtable         int arr[] = new int[] { 1, 2, 3, 4 };         Vector<Integer> v = new Vector();         Hashtable<Integer, String> h = new Hashtable();          // Adding the elements into the         // vector         v.addElement(1);         v.addElement(2);          // Adding the element into the         // hashtable         h.put(1, "geeks");         h.put(2, "4geeks");          // Array instance creation requires [],         // while Vector and hastable require ()         // Vector element insertion requires addElement(),         // but hashtable element insertion requires put()          // Accessing the first element of the         // array, vector and hashtable         System.out.println(arr[0]);         System.out.println(v.elementAt(0));         System.out.println(h.get(1));          // Array elements are accessed using [],         // vector elements using elementAt()         // and hashtable elements using get()     } } 

Output
1 1 geeks 

As we can observe, none of these collections(Array, Vector, or Hashtable) implements a standard member access interface, it was very difficult for programmers to write algorithms that can work for all kinds of Collections. Another drawback is that most of the ‘Vector’ methods are final, meaning we cannot extend the ’Vector’ class to implement a similar kind of Collection. Therefore, Java developers decided to come up with a common interface to deal with the above-mentioned problems and introduced the Collection Framework in JDK 1.2 post which both, legacy Vectors and Hashtables were modified to conform to the Collection Framework. 

Advantages of the Java Collection Framework

Since the lack of a collection framework gave rise to the above set of disadvantages, the following are the advantages of the collection framework. 

  1. Consistent API: The API has a basic set of interfaces like Collection, Set, List, or Map, all the classes (ArrayList, LinkedList, Vector, etc) that implement these interfaces have some common set of methods.
     
  2. Reduces programming effort: A programmer doesn't have to worry about the design of the Collection but rather he can focus on its best use in his program. Therefore, the basic concept of Object-oriented programming (i.e.) abstraction has been successfully implemented.
     
  3. Increases program speed and quality: Increases performance by providing high-performance implementations of useful data structures and algorithms because in this case, the programmer need not think of the best implementation of a specific data structure. He can simply use the best implementation to drastically boost the performance of his algorithm/program.

Hierarchy of the Collection Framework in Java

The utility package, (java.util) contains all the classes and interfaces that are required by the collection framework. The collection framework contains an interface named an iterable interface which provides the iterator to iterate through all the collections. This interface is extended by the main collection interface which acts as a root for the collection framework. All the collections extend this collection interface thereby extending the properties of the iterator and the methods of this interface. The following figure illustrates the hierarchy of the collection framework. 

Collections in Java


Before understanding the different components in the above framework, let's first understand a class and an interface. 

  • Class: A class is a user-defined blueprint or prototype from which objects are created. It represents the set of properties or methods that are common to all objects of one type.
     
  • Interface: Like a class, an interface can have methods and variables, but the methods declared in an interface are by default abstract (only method signature, nobody). Interfaces specify what a class must do and not how. It is the blueprint of the class.

Methods of the Collection Interface

This interface contains various methods which can be directly used by all the collections which implement this interface. They are:

Method

Description

add(Object)This method is used to add an object to the collection.
addAll(Collection c)This method adds all the elements in the given collection to this collection.
clear()This method removes all of the elements from this collection.
contains(Object o)This method returns true if the collection contains the specified element.
containsAll(Collection c)This method returns true if the collection contains all of the elements in the given collection.
equals(Object o)This method compares the specified object with this collection for equality.
hashCode()This method is used to return the hash code value for this collection.
isEmpty()This method returns true if this collection contains no elements.
iterator()This method returns an iterator over the elements in this collection.
parallelStream()This method returns a parallel Stream with this collection as its source.
remove(Object o)This method is used to remove the given object from the collection. If there are duplicate values, then this method removes the first occurrence of the object.
removeAll(Collection c)This method is used to remove all the objects mentioned in the given collection from the collection.
removeIf(Predicate filter)This method is used to remove all the elements of this collection that satisfy the given predicate.
retainAll(Collection c)This method is used to retain only the elements in this collection that are contained in the specified collection.
size()This method is used to return the number of elements in the collection.
spliterator()This method is used to create a Spliterator over the elements in this collection.
stream()This method is used to return a sequential Stream with this collection as its source.
toArray()This method is used to return an array containing all of the elements in this collection.

Interfaces that Extend the Java Collections Interface

The collection framework contains multiple interfaces where every interface is used to store a specific type of data. The following are the interfaces present in the framework. 

1. Iterable Interface

This is the root interface for the entire collection framework. The collection interface extends the iterable interface. Therefore, inherently, all the interfaces and classes implement this interface. The main functionality of this interface is to provide an iterator for the collections. Therefore, this interface contains only one abstract method which is the iterator. It returns the 

Iterator iterator();

2. Collection Interface

This interface extends the iterable interface and is implemented by all the classes in the collection framework. This interface contains all the basic methods which every collection has like adding the data into the collection, removing the data, clearing the data, etc. All these methods are implemented in this interface because these methods are implemented by all the classes irrespective of their style of implementation. And also, having these methods in this interface ensures that the names of the methods are universal for all the collections. Therefore, in short, we can say that this interface builds a foundation on which the collection classes are implemented.

3. List Interface

This is a child interface of the collection interface. This interface is dedicated to the data of the list type in which we can store all the ordered collections of the objects. This also allows duplicate data to be present in it. This list interface is implemented by various classes like ArrayList, Vector, Stack, etc. Since all the subclasses implement the list, we can instantiate a list object with any of these classes. 

For example: 

List <T> al = new ArrayList<> (); 
List <T> ll = new LinkedList<> (); 
List <T> v = new Vector<> (); 
Where T is the type of the object

The classes which implement the List interface are as follows:

i). ArrayList

ArrayList provides us with dynamic arrays in Java. Though, it may be slower than standard arrays but can be helpful in programs where lots of manipulation in the array is needed. The size of an ArrayList is increased automatically if the collection grows or shrinks if the objects are removed from the collection. Java ArrayList allows us to randomly access the list. ArrayList can not be used for primitive types, like int, char, etc. We will need a wrapper class for such cases. 

Let's understand the ArrayList with the following example:

Java
// Java program to demonstrate the // working of ArrayList import java.io.*; import java.util.*;  class GFG {      // Main Method     public static void main(String[] args)     {          // Declaring the ArrayList with         // initial size n         ArrayList<Integer> al = new ArrayList<Integer>();          // Appending new elements at         // the end of the list         for (int i = 1; i <= 5; i++)             al.add(i);          // Printing elements         System.out.println(al);          // Remove element at index 3         al.remove(3);          // Displaying the ArrayList         // after deletion         System.out.println(al);          // Printing elements one by one         for (int i = 0; i < al.size(); i++)             System.out.print(al.get(i) + " ");     } } 

Output
[1, 2, 3, 4, 5] [1, 2, 3, 5] 1 2 3 5 

ii). LinkedList

The LinkedList class is an implementation of the LinkedList data structure which is a linear data structure where the elements are not stored in contiguous locations and every element is a separate object with a data part and address part. The elements are linked using pointers and addresses. Each element is known as a node. 

Let's understand the LinkedList with the following example:

Java
// Java program to demonstrate the // working of LinkedList import java.io.*; import java.util.*;  class GFG {      // Main Method     public static void main(String[] args)     {          // Declaring the LinkedList         LinkedList<Integer> ll = new LinkedList<Integer>();          // Appending new elements at         // the end of the list         for (int i = 1; i <= 5; i++)             ll.add(i);          // Printing elements         System.out.println(ll);          // Remove element at index 3         ll.remove(3);          // Displaying the List         // after deletion         System.out.println(ll);          // Printing elements one by one         for (int i = 0; i < ll.size(); i++)             System.out.print(ll.get(i) + " ");     } } 

Output
[1, 2, 3, 4, 5] [1, 2, 3, 5] 1 2 3 5 

iii). Vector

A vector provides us with dynamic arrays in Java. Though, it may be slower than standard arrays but can be helpful in programs where lots of manipulation in the array is needed. This is identical to ArrayList in terms of implementation. However, the primary difference between a vector and an ArrayList is that a Vector is synchronized and an ArrayList is non-synchronized. 

Let's understand the Vector with an example:

Java
// Java program to demonstrate the // working of Vector import java.io.*; import java.util.*;  class GFG {      // Main Method     public static void main(String[] args)     {          // Declaring the Vector         Vector<Integer> v = new Vector<Integer>();          // Appending new elements at         // the end of the list         for (int i = 1; i <= 5; i++)             v.add(i);          // Printing elements         System.out.println(v);          // Remove element at index 3         v.remove(3);          // Displaying the Vector         // after deletion         System.out.println(v);          // Printing elements one by one         for (int i = 0; i < v.size(); i++)             System.out.print(v.get(i) + " ");     } } 

Output
[1, 2, 3, 4, 5] [1, 2, 3, 5] 1 2 3 5 

iv). Stack

Stack class models and implements the Stack data structure. The class is based on the basic principle of last-in-first-out. In addition to the basic push and pop operations, the class provides three more functions empty, search, and peek. The class can also be referred to as the subclass of Vector. 

Let's understand the stack with an example:

Java
// Java program to demonstrate the // working of a stack import java.util.*; public class GFG {      // Main Method     public static void main(String args[])     {         Stack<String> stack = new Stack<String>();         stack.push("Geeks");         stack.push("For");         stack.push("Geeks");         stack.push("Geeks");          // Iterator for the stack         Iterator<String> itr = stack.iterator();          // Printing the stack         while (itr.hasNext()) {             System.out.print(itr.next() + " ");         }          System.out.println();          stack.pop();          // Iterator for the stack         itr = stack.iterator();          // Printing the stack         while (itr.hasNext()) {             System.out.print(itr.next() + " ");         }     } } 

Output
Geeks For Geeks Geeks  Geeks For Geeks 

Note: Stack is a subclass of Vector and a legacy class. It is thread-safe which might be overhead in an environment where thread safety is not needed. An alternate to Stack is to use ArrayDequeue which is not thread-safe and has faster array implementation.


4. Queue Interface

As the name suggests, a queue interface maintains the FIFO(First In First Out) order similar to a real-world queue line. This interface is dedicated to storing all the elements where the order of the elements matter. For example, whenever we try to book a ticket, the tickets are sold on a first come first serve basis. Therefore, the person whose request arrives first into the queue gets the ticket. There are various classes like PriorityQueue, ArrayDeque, etc. Since all these subclasses implement the queue, we can instantiate a queue object with any of these classes. 

For example:

Queue <T> pq = new PriorityQueue<> (); 
Queue <T> ad = new ArrayDeque<> (); 
Where T is the type of the object. 

The most frequently used implementation of the queue interface is the PriorityQueue. 

Priority Queue

A PriorityQueue is used when the objects are supposed to be processed based on priority. It is known that a queue follows the First-In-First-Out algorithm, but sometimes the elements of the queue are needed to be processed according to the priority and this class is used in these cases. The PriorityQueue is based on the priority heap. The elements of the priority queue are ordered according to the natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used. 

Let's understand the priority queue with an example:

Java
// Java program to demonstrate the working of // priority queue in Java import java.util.*;  class GfG {      // Main Method     public static void main(String args[])     {         // Creating empty priority queue         PriorityQueue<Integer> pQueue             = new PriorityQueue<Integer>();          // Adding items to the pQueue using add()         pQueue.add(10);         pQueue.add(20);         pQueue.add(15);          // Printing the top element of PriorityQueue         System.out.println(pQueue.peek());          // Printing the top element and removing it         // from the PriorityQueue container         System.out.println(pQueue.poll());          // Printing the top element again         System.out.println(pQueue.peek());     } } 

Output
10 10 15 


5. Deque Interface

This is a very slight variation of the queue data structure. Deque, also known as a double-ended queue, is a data structure where we can add and remove elements from both ends of the queue. This interface extends the queue interface. The class which implements this interface is ArrayDeque. Since ArrayDeque class implements the Deque interface, we can instantiate a deque object with this class. 

For example:

Deque<T> ad = new ArrayDeque<> (); 
Where T is the type of the object. 

The class which implements the deque interface is ArrayDeque. 

ArrayDeque

ArrayDeque class which is implemented in the collection framework provides us with a way to apply resizable array. This is a special kind of array that grows and allows users to add or remove an element from both sides of the queue. Array deques have no capacity restrictions and they grow as necessary to support usage. 

Let's understand ArrayDeque with an example:
 

Java
// Java program to demonstrate the // ArrayDeque class in Java  import java.util.*; public class ArrayDequeDemo {     public static void main(String[] args)     {         // Initializing an deque         ArrayDeque<Integer> de_que             = new ArrayDeque<Integer>(10);          // add() method to insert         de_que.add(10);         de_que.add(20);         de_que.add(30);         de_que.add(40);         de_que.add(50);          System.out.println(de_que);          // clear() method         de_que.clear();          // addFirst() method to insert the         // elements at the head         de_que.addFirst(564);         de_que.addFirst(291);          // addLast() method to insert the         // elements at the tail         de_que.addLast(24);         de_que.addLast(14);          System.out.println(de_que);     } } 

Output
[10, 20, 30, 40, 50] [291, 564, 24, 14] 


6. Set Interface

A set is an unordered collection of objects in which duplicate values cannot be stored. This collection is used when we wish to avoid the duplication of the objects and wish to store only the unique objects. This set interface is implemented by various classes like HashSet, TreeSet, LinkedHashSet, etc. Since all the subclasses implement the set, we can instantiate a set object with any of these classes. 

For example:

Set<T> hs = new HashSet<> (); 
Set<T> lhs = new LinkedHashSet<> (); 
Set<T> ts = new TreeSet<> (); 
Where T is the type of the object. 

The following are the classes that implement the Set interface:

i). HashSet

The HashSet class is an inherent implementation of the hash table data structure. The objects that we insert into the HashSet do not guarantee to be inserted in the same order. The objects are inserted based on their hashcode. This class also allows the insertion of NULL elements. Let's understand HashSet with an example:

Java
// Java program to demonstrate the // working of a HashSet import java.util.*;  public class HashSetDemo {      // Main Method     public static void main(String args[])     {         // Creating HashSet and         // adding elements         HashSet<String> hs = new HashSet<String>();          hs.add("Geeks");         hs.add("For");         hs.add("Geeks");         hs.add("Is");         hs.add("Very helpful");          // Traversing elements         Iterator<String> itr = hs.iterator();         while (itr.hasNext()) {             System.out.println(itr.next());         }     } } 

Output
Very helpful Geeks For Is 

ii). LinkedHashSet

A LinkedHashSet is very similar to a HashSet. The difference is that this uses a doubly linked list to store the data and retains the ordering of the elements. 

Let's understand the LinkedHashSet with an example: 

Java
// Java program to demonstrate the // working of a LinkedHashSet import java.util.*;  public class LinkedHashSetDemo {      // Main Method     public static void main(String args[])     {         // Creating LinkedHashSet and         // adding elements         LinkedHashSet<String> lhs             = new LinkedHashSet<String>();          lhs.add("Geeks");         lhs.add("For");         lhs.add("Geeks");         lhs.add("Is");         lhs.add("Very helpful");          // Traversing elements         Iterator<String> itr = lhs.iterator();         while (itr.hasNext()) {             System.out.println(itr.next());         }     } } 

Output
Geeks For Is Very helpful 


7. Sorted Set Interface

This interface is very similar to the set interface. The only difference is that this interface has extra methods that maintain the ordering of the elements. The sorted set interface extends the set interface and is used to handle the data which needs to be sorted. The class which implements this interface is TreeSet. Since this class implements the SortedSet, we can instantiate a SortedSet object with this class. 

For example:

SortedSet<T> ts = new TreeSet<> (); 
Where T is the type of the object. 

The class which implements the sorted set interface is TreeSet. 
 
TreeSet

The TreeSet class uses a Tree for storage. The ordering of the elements is maintained by a set using their natural ordering whether or not an explicit comparator is provided. This must be consistent with equals if it is to correctly implement the Set interface. It can also be ordered by a Comparator provided at a set creation time, depending on which constructor is used. 

Let's understand TreeSet with an example:

Java
// Java program to demonstrate the // working of a TreeSet import java.util.*;  public class TreeSetDemo {      // Main Method     public static void main(String args[])     {         // Creating TreeSet and         // adding elements         TreeSet<String> ts = new TreeSet<String>();          ts.add("Geeks");         ts.add("For");         ts.add("Geeks");         ts.add("Is");         ts.add("Very helpful");          // Traversing elements         Iterator<String> itr = ts.iterator();         while (itr.hasNext()) {             System.out.println(itr.next());         }     } } 

Output
For Geeks Is Very helpful 


8. Map Interface

A map is a data structure that supports the key-value pair for mapping the data. This interface doesn't support duplicate keys because the same key cannot have multiple mappings, however, it allows duplicate values in different keys. A map is useful if there is data and we wish to perform operations on the basis of the key. This map interface is implemented by various classes like HashMap, TreeMap, etc. Since all the subclasses implement the map, we can instantiate a map object with any of these classes. 

For example:

Map<T> hm = new HashMap<> (); 
Map<T> tm = new TreeMap<> ();

Where T is the type of the object.

The frequently used implementation of a Map interface is a HashMap. 

HashMap

HashMap provides the basic implementation of the Map interface of Java. It stores the data in (Key, Value) pairs. To access a value in a HashMap, we must know its key. HashMap uses a technique called Hashing. Hashing is a technique of converting a large String to a small String that represents the same String so that the indexing and search operations are faster. HashSet also uses HashMap internally. 

Let's understand the HashMap with an example:

Java
// Java program to demonstrate the // working of a HashMap import java.util.*;  public class HashMapDemo {      // Main Method     public static void main(String args[])     {         // Creating HashMap and         // adding elements         HashMap<Integer, String> hm             = new HashMap<Integer, String>();          hm.put(1, "Geeks");         hm.put(2, "For");         hm.put(3, "Geeks");          // Finding the value for a key         System.out.println("Value for 1 is " + hm.get(1));          // Traversing through the HashMap         for (Map.Entry<Integer, String> e : hm.entrySet())             System.out.println(e.getKey() + " "                                + e.getValue());     } } 

Output
Value for 1 is Geeks 1 Geeks 2 For 3 Geeks 

Next Article
Collections Class in Java

K

kartik
Improve
Article Tags :
  • Java
  • Java-Collections
Practice Tags :
  • Java
  • Java-Collections

Similar Reads

    Java Tutorial
    Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. It is known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Java s
    10 min read

    Basics

    Introduction to Java
    Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995. It is platform-independent, which means we can write code once and run it anywhere using the Java Virtual Machine (JVM). Java is mostly used for building desktop applications, web applications, Android
    4 min read
    Java Programming Basics
    Java is one of the most popular and widely used programming language and platform. A platform is an environment that helps to develop and run programs written in any programming language. Java is fast, reliable and secure. From desktop to web applications, scientific supercomputers to gaming console
    4 min read
    Java Methods
    Java Methods are blocks of code that perform a specific task. A method allows us to reuse code, improving both efficiency and organization. All methods in Java must belong to a class. Methods are similar to functions and expose the behavior of objects.Example: Java program to demonstrate how to crea
    8 min read
    Access Modifiers in Java
    In Java, access modifiers are essential tools that define how the members of a class, like variables, methods, and even the class itself can be accessed from other parts of our program. They are an important part of building secure and modular code when designing large applications. Understanding de
    7 min read
    Arrays in Java
    Arrays in Java are one of the most fundamental data structures that allow us to store multiple values of the same type in a single variable. They are useful for storing and managing collections of data. Arrays in Java are objects, which makes them work differently from arrays in C/C++ in terms of me
    15+ min read
    Java Strings
    In Java, a String is the type of object that can store a sequence of characters enclosed by double quotes, and every character is stored in 16 bits, i.e., using UTF 16-bit encoding. A string acts the same as an array of characters. Java provides a robust and flexible API for handling strings, allowi
    9 min read
    Regular Expressions in Java
    In Java, Regular Expressions or Regex (in short) in Java is an API for defining String patterns that can be used for searching, manipulating, and editing a string in Java. Email validation and passwords are a few areas of strings where Regex is widely used to define the constraints. Regular Expressi
    7 min read

    OOPs & Interfaces

    Classes and Objects in Java
    In Java, classes and objects are basic concepts of Object Oriented Programming (OOPs) that are used to represent real-world concepts and entities. The class represents a group of objects having similar properties and behavior, or in other words, we can say that a class is a blueprint for objects, wh
    11 min read
    Java Constructors
    In Java, constructors play an important role in object creation. A constructor is a special block of code that is called when an object is created. Its main job is to initialize the object, to set up its internal state, or to assign default values to its attributes. This process happens automaticall
    10 min read
    Java OOP(Object Oriented Programming) Concepts
    Java Object-Oriented Programming (OOPs) is a fundamental concept in Java that every developer must understand. It allows developers to structure code using classes and objects, making it more modular, reusable, and scalable.The core idea of OOPs is to bind data and the functions that operate on it,
    13 min read
    Java Packages
    Packages in Java are a mechanism that encapsulates a group of classes, sub-packages, and interfaces. Packages are used for: Prevent naming conflicts by allowing classes with the same name to exist in different packages, like college.staff.cse.Employee and college.staff.ee.Employee.They make it easie
    8 min read
    Java Interface
    An Interface in Java programming language is defined as an abstract type used to specify the behaviour of a class. An interface in Java is a blueprint of a behaviour. A Java interface contains static constants and abstract methods. Key Properties of Interface:The interface in Java is a mechanism to
    12 min read

    Collections

    Collections in Java
    Any group of individual objects that are represented as a single unit is known as a Java Collection of Objects. In Java, a separate framework named the "Collection Framework" has been defined in JDK 1.2 which holds all the Java Collection Classes and Interface in it. In Java, the Collection interfac
    15+ min read
    Collections Class in Java
    Collections class in Java is one of the utility classes in the Java Collections Framework. The java.util package contains the Collections class in Java. The Java Collections class is used with the static methods that operate on the collections or return the collection. All the methods of this class
    13 min read
    Collection Interface in Java
    The Collection interface in Java is a core member of the Java Collections Framework located in the java.util package. It is one of the root interfaces of the Java Collection Hierarchy. The Collection interface is not directly implemented by any class. Instead, it is implemented indirectly through it
    6 min read
    Java Iterator
    An Iterator in Java is an interface used to traverse elements in a Collection sequentially. It provides methods like hasNext(), next(), and remove() to loop through collections and perform manipulation. An Iterator is a part of the Java Collection Framework, and we can use it with collections like A
    6 min read
    Java Comparator Interface
    The Comparator interface in Java is used to sort the objects of user-defined classes. The Comparator interface is present in java.util package. This interface allows us to define custom comparison logic outside of the class for which instances we want to sort. The comparator interface is useful when
    7 min read

    Exception Handling

    Java Exception Handling
    Exception handling in Java allows developers to manage runtime errors effectively by using mechanisms like try-catch block, finally block, throwing Exceptions, Custom Exception handling, etc. An Exception is an unwanted or unexpected event that occurs during the execution of a program, i.e., at runt
    10 min read
    Java Try Catch Block
    A try-catch block in Java is a mechanism to handle exceptions. This make sure that the application continues to run even if an error occurs. The code inside the try block is executed, and if any exception occurs, it is then caught by the catch block.Example: Here, we are going to handle the Arithmet
    4 min read
    Java final, finally and finalize
    In Java, the final, finally, and finalize keywords play an important role in exception handling. The main difference between final, finally, and finalize is listed below:final: The final is the keyword that can be used for immutability and restrictions in variables, methods, and classes.finally: The
    4 min read
    Chained Exceptions in Java
    Chained Exceptions in Java allow associating one exception with another, i.e. one exception describes the cause of another exception. For example, consider a situation in which a method throws an ArithmeticException because of an attempt to divide by zero.But the root cause of the error was an I/O f
    3 min read
    Null Pointer Exception in Java
    A NullPointerException in Java is a RuntimeException. It occurs when a program attempts to use an object reference that has the null value. In Java, "null" is a special value that can be assigned to object references to indicate the absence of a value.Reasons for Null Pointer ExceptionA NullPointerE
    5 min read
    Exception Handling with Method Overriding in Java
    In Java, an exception is an unwanted or unexpected event that occurs during a program's execution, i.e., at runtime, and disrupts the normal flow of the program’s instructions. Exception handling in Java handles runtime errors and helps maintain the program's normal flow by using constructs like try
    5 min read

    Java Advanced

    Java Multithreading Tutorial
    Threads are the backbone of multithreading. We are living in the real world which in itself is caught on the web surrounded by lots of applications. With the advancement in technologies, we cannot achieve the speed required to run them simultaneously unless we introduce the concept of multi-tasking
    15+ min read
    Synchronization in Java
    In multithreading, synchronization is important to make sure multiple threads safely work on shared resources. Without synchronization, data can become inconsistent or corrupted if multiple threads access and modify shared variables at the same time. In Java, it is a mechanism that ensures that only
    10 min read
    File Handling in Java
    In Java, with the help of File Class, we can work with files. This File Class is inside the java.io package. The File class can be used to create an object of the class and then specifying the name of the file.Why File Handling is Required?File Handling is an integral part of any programming languag
    6 min read
    Java Method References
    In Java, a method is a collection of statements that perform some specific task and return the result to the caller. A method reference is the shorthand syntax for a lambda expression that contains just one method call. In general, one does not have to pass arguments to method references.Why Use Met
    9 min read
    Java 8 Stream Tutorial
    Java 8 introduces Stream, which is a new abstract layer, and some new additional packages in Java 8 called java.util.stream. A Stream is a sequence of components that can be processed sequentially. These packages include classes, interfaces, and enum to allow functional-style operations on the eleme
    15+ min read
    Java Networking
    When computing devices such as laptops, desktops, servers, smartphones, and tablets and an eternally-expanding arrangement of IoT gadgets such as cameras, door locks, doorbells, refrigerators, audio/visual systems, thermostats, and various sensors are sharing information and data with each other is
    15+ min read
    JDBC Tutorial
    JDBC stands for Java Database Connectivity. JDBC is a Java API or tool used in Java applications to interact with the database. It is a specification from Sun Microsystems that provides APIs for Java applications to communicate with different databases. Interfaces and Classes for JDBC API comes unde
    12 min read
    Java Memory Management
    Java memory management is a fundamental concept that involves the automatic allocation and deallocation of objects, managed by the Java Virtual Machine (JVM). The JVM uses a garbage collector to automatically remove unused objects, freeing up memory in the background. This eliminates the need for de
    5 min read
    Garbage Collection in Java
    Garbage collection in Java is an automatic memory management process that helps Java programs run efficiently. Java programs compile to bytecode that can be run on a Java Virtual Machine (JVM). When Java programs run on the JVM, objects in the heap are created, which is a portion of memory dedicated
    7 min read
    Memory Leaks in Java
    In programming, a memory leak happens when a program keeps using memory but does not give it back when it's done. It simply means the program slowly uses more and more memory, which can make things slow and even stop working. Working of Memory Management in JavaJava has automatic garbage collection,
    3 min read

    Practice Java

    Java Interview Questions and Answers
    Java is one of the most popular programming languages in the world, known for its versatility, portability, and wide range of applications. Java is the most used language in top companies such as Uber, Airbnb, Google, Netflix, Instagram, Spotify, Amazon, and many more because of its features and per
    15+ min read
    Java Programs - Java Programming Examples
    In this article, we will learn and prepare for Interviews using Java Programming Examples. From basic Java programs like the Fibonacci series, Prime numbers, Factorial numbers, and Palindrome numbers to advanced Java programs.Java is one of the most popular programming languages today because of its
    8 min read
    Java Exercises - Basic to Advanced Java Practice Programs with Solutions
    Looking for Java exercises to test your Java skills, then explore our topic-wise Java practice exercises? Here you will get 25 plus practice problems that help to upscale your Java skills. As we know Java is one of the most popular languages because of its robust and secure nature. But, programmers
    7 min read
    Java Quiz | Level Up Your Java Skills
    The best way to scale up your coding skills is by practicing the exercise. And if you are a Java programmer looking to test your Java skills and knowledge? Then, this Java quiz is designed to challenge your understanding of Java programming concepts and assess your excellence in the language. In thi
    1 min read
    Top 50 Java Project Ideas For Beginners and Advanced [Update 2025]
    Java is one of the most popular and versatile programming languages, known for its reliability, security, and platform independence. Developed by James Gosling in 1982, Java is widely used across industries like big data, mobile development, finance, and e-commerce.Building Java projects is an excel
    15+ min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences