Skip to content
geeksforgeeks
  • 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
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • GfG 160: Daily DSA
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • 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:
Java IO - Input/Output in Java with Examples
Next article icon

Java 8 Features - Complete Tutorial

Last Updated : 05 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Java 8 is the most awaited release of the Java programming language development because, in the entire history of Java, it has never released that many major features. It consists of major features of Java. It is a new version of Java and was released by Oracle on 18 March 2014. Java provided support for functional programming, new Java 8 APIs, a new JavaScript engine, a new Java 8 streaming API, functional interfaces, default methods, date-time API changes, etc.

Java 8 Tutorial

Major Java 8 Features Introduced

There are a few major Java 8 features mentioned below:

  • Lambda Expressions: Concise functional code using ->.
  • Functional Interfaces: Single-method interfaces.
  • Introduced and Improved APIs:
    1. Stream API: Efficient Data Manipulation.
    2. Date/Time API: Robust Date and Time Handling.
    3. Collection API Improvements: Enhanced Methods for Collections (e.g., removeIf, replaceAll).
    4. Concurrency API Improvements: New classes for parallel processing (e.g., CompletableFuture).
  • Optional Class: Handle null values safely.
  • forEach() Method in Iterable Interface: Executes an action for each element in a Collection.
  • Default Methods: Evolve interfaces without breaking compatibility.
  • Static Methods: Allows adding methods with default implementations to interfaces.
  • Method References: Refer to methods easily.

This Java 8 tutorial covers all the important Java 8 features like Java 8 APIs, Java arrays, Java 8 ArrayList, and many more included in the Java 8 programming language. To explore detail features of Java language you can explore Java course, in this course you will get a free full beginner to advanced topics of Java programming.

Java 8 Features

  • Lambda Expressions
  • Functional Interfaces
  • Method Reference
  • Streams
  • Comparable and Comparator
  • Optional Class
  • Date/Time API

Lambda Expressions

Lambda Expression basically expresses an instance of the functional interface, in other words, you can say it provides a clear and concise way to represent a method of the functional interface using an expression. Lambda Expressions are added in Java 8.

  • Lambda Expressions in Java 8
  • Lambda Expressions Parameters
  • Java Lambda Expression with Collections
  • Lambda Expression Variable Capturing with Examples
  • How to Create Thread using Lambda Expressions in Java?
  • Serialization of Lambda Expression in Java
  • Block Lambda Expressions in Java
  • Match Lambdas to Interfaces in Java
  • Converting ArrayList to HashMap in Java 8 using a Lambda Expression
  • Check if a String Contains Only Alphabets in Java Using Lambda Expression
  • Remove Elements From a List that Satisfy a Given Predicate in Java

Functional Interfaces

An interface that contains only one abstract method is known as a functional interface, but there is no restriction, you can have n number of default and static methods inside a functional interface.

  • Functional Interfaces in Java
  • Consumer Interface in Java with Examples
  • BiConsumer Interface in Java with Examples
  • Predicate Interface with Examples
  • Function Interface in Java with Examples
  • Supplier Interface in Java with Examples

Method Reference

Method reference is a shorthand notation of a lambda expression to call a method. There are four types of method references that are as follows:

  • Static Method Reference
  • Instance Method Reference of a particular object
  • Instance Method Reference of an arbitrary object of a particular type
  • Constructor Reference.

Example:

numList.stream().filter(n -> n > 5).sorted().forEach(System.out::println);
  • Method References in Java with examples
  • Converting ArrayList to HashMap using Method Reference in Java 8

Streams

Stream API is introduced in Java 8 and is used to process collections of objects with the functional style of coding using the lambda expression. So to understand what stream API is, you must have knowledge of both lambda and functional interfaces.

  • Java 8 Stream
  • Difference Between Streams and Collections in Java
  • Implement Filter Function using Reduce in Java 8 Streams
  • Java Stream API – Filters
  • Parallel vs Sequential Stream in Java
  • Functional Programming in Java 8+ using the Stream API with Example
  • Intermediate Methods of Stream in Java
  • Difference Between map() And flatMap() In Java Stream
  • Array to Stream in Java
  • 10 Ways to Create a Stream in Java
  • How to Print Elements of a Stream in Java 8
  • Collecting a Stream to an Immutable Collection in Java
  • Comparing Streams to Loops in Java
  • Why You Need to Close the Java Streams in Finally Block?
  • Convert an Iterable to Stream in Java
  • Convert an Iterator to Stream in Java
  • Difference Between Stream.of() and Arrays.stream() method in Java
  • Convert Stream to Set in Java
  • Convert a Set to Stream in Java
  • Streams on Arrays in Java 8

Java Stream Programs

Java Streams provide a powerful and expressive way to process sequences of elements in Java, enabling functional-style operations on collections of data. The Stream API, introduced in Java 8, facilitates efficient data manipulation and transformation using a sequence of operations that can be performed in parallel or sequentially

. Java Stream Programs will give a clear view to the topic:

  • Program to Convert a Map to a Stream in Java
  • Program to Convert Boxed Array to Stream in Java
  • Program to Convert Primitive Array to Stream in Java
  • Program to Convert a Set to Stream in Java using Generics
  • Program to Convert List to Stream in Java
  • Program to Convert Stream to an Array in Java
  • How to get Slice of a Stream in Java
  • Flattening Nested Collections in Java
  • How to Convert a Stream into a Map in Java
  • Find the First Element of a Stream in Java
  • Find the Last Element of a Stream in Java
  • How to Find Duplicate Elements in a Stream in Java
  • Count the Occurrence of a Given Character in a String Using Stream API in Java
  • Reverse Elements of a Parallel Stream in Java
  • How to Get ArrayList From Stream in Java 8
  • Generate Infinite Stream of Double in Java
  • Generate Infinite Stream of Integers in Java
  • Program to Iterate over a Stream with Indices in Java 8
  • Flatten a Stream of Arrays in Java using forEach loop
  • Flatten a Stream of Lists in Java using forEach loop
  • Flatten a Stream of Map in Java using forEach loop
  • Convert a String to a List of Characters in Java
  • Initialize a List in a Single Line with a Specified Value using Java Stream

Java Stream Methods

Methods related to one of the most powerful features of Java Stream are mentioned below.

  • Stream forEach() method in Java with Examples
  • Stream forEachOrdered() Method in Java with Examples
  • foreach() loop vs Stream foreach() vs Parallel Stream foreach()
  • Stream of() method in Java
  • Java Stream findAny() with Examples
  • Stream anyMatch() in Java with Examples
  • Stream allMatch() in Java with Examples
  • Stream filter() in Java with Examples
  • Stream sorted (Comparator comparator) Method in Java
  • Stream sorted() in Java
  • Stream.distinct() in Java
  • Stream.concat() in Java
  • Stream.reduce() in Java with Examples
  • stream.limit() method in Java
  • Stream ofNullable(T) method in Java with Examples
  • Stream dropWhile() method in Java with Examples
  • Stream iterate(T,Predicate,UnaryOperator) Method in Java with Examples
  • Stream takeWhile() method in Java with Examples
  • concat() Method of Stream Interface in Java API
  • Stream findFirst() in Java with Examples
  • DoubleStream mapToObj() in Java
  • Stream.Builder accept() Method in Java
  • IntStream.Builder add() Method in Java
  • DoubleStream.Builder build() in Java
  • Stream.Builder build() in Java
  • Collectors.joining() Method with Examples
  • Stream builder() in Java with Examples
  • Stream empty() in Java with Examples
  • LongStream flatMap(LongFunction mapper) in Java
  • LongStream filter() in Java with Examples

Comparable and Comparator

Comparable and Comparator are interfaces used to order objects. They are particularly useful in sorting operations and collections that require natural ordering. Here we will learn about Comparable and Comparator in depth.

  • Comparable vs Comparator in Java
  • Comparator Interface in Java with Examples
  • Why to Use Comparator Interface Rather than Comparable Interface in Java?
  • Sort an Array of Triplet using Java Comparable and Comparator
  • Java Program to Sort LinkedList using Comparable
  • How to Sort HashSet Elements using Comparable Interface in Java?
  • Sort LinkedHashMap by Values using Comparable Interface in Java
  • Sort LinkedHashMap by Keys using Comparable Interface in Java
  • How to Sort LinkedHashSet Elements using Comparable Interface in Java?

Optional Class

  • Java 8 Optional Class
  • Optional ofNullable() Method in Java with Examples
  • Optional orElse() Method in Java with Examples
  • Optional ifPresentOrElse() Method in Java with Examples
  • Optional orElseGet() Method in Java with Examples
  • Optional filter() Method in Java with Examples
  • Optional empty() Method in Java with Examples
  • Optional hashCode() Method in Java with Examples
  • Optional toString() Method in Java with Examples
  • Optional equals() Method in Java with Examples
  • Optional stream() Method in Java with examples
  • Optional or() Method in Java with Examples
  • Optional get() Method in Java with Examples
  • Optional isPresent() Method in Java with Examples
  • Optional orElseThrow() Method in Java with Examples
  • Optional of() method in Java with Examples

Date/Time API

This section gives you to handle the ever-changing world of dates and times within your Java programs. Explore working with calendars, timestamps, and time manipulation – essential skills for building applications that deal with deadlines, scheduling, or even historical data analysis.

  • Date-Time API in Java 8
  • java.time.LocalDate Class in Java
  • java.time.LocalTime Class in Java
  • java.time.LocalDateTime Class in Java
  • java.time.MonthDay Class in Java
  • java.time.OffsetTime Class in Java
  • java.time.OffsetDateTime Class in Java
  • java.time.Clock Class in Java
  • java.time.ZonedDateTime Class in Java
  • java.time.ZoneId Class in Java
  • java.time.ZoneOffset Class in Java
  • java.time.Year Class in Java
  • java.time.YearMonth Class in Java
  • java.time.Period Class in Java
  • java.time.Duration Class in Java
  • java.time.Instant Class in Java
  • Java 8 Clock instant() method with Examples
  • Java 8 Clock fixed() method with Examples

Miscellaneous

Java is a versatile and powerful programming language that encompasses a wide range of features and tools, enabling developers to build robust, high-performance applications. Let us learn some Java Miscellaneous topics are mentioned below:

  • Default Methods In Java 8
  • Static method in Interface in Java
  • Can We Override Default Method in Java?
  • forEach() method in Java
  • Nashorn JavaScript Engine in Java with Examples
  • MetaSpace in Java 8 with Examples
  • Java class dependency analyzer in Java 8 with Examples
  • LongUnaryOperator Interface in Java
  • IntUnaryOperator Interface in Java
  • DoubleUnaryOperator Interface in Java
  • UnaryOperator Interface in Java
  • ObjLongConsumer Interface with Example
  • ObjIntConsumer Interface with Example
  • ObjDoubleConsumer Interface with Example
  • DoubleSupplier Interface with Examples
  • BooleanSupplier Interface with Examples
  • IntSupplier Interface with Examples
  • LongSupplier Interface with Examples
  • LongConsumer Interface in Java with Examples
  • DoubleConsumer Interface in Java with Examples
  • IntConsumer Interface in Java with Examples
  • LongFunction Interface in Java with Examples
  • IntFunction Interface in Java with Examples
  • ToDoubleFunction Interface in Java with Examples
  • DoubleFunction Interface in Java with Examples
  • ToIntFunction Interface in Java with Examples
  • LongToIntFunction Interface in Java with Examples
  • ToLongFunction Interface in Java with Examples
  • LongToDoubleFunction Interface in Java with Examples
  • ToLongBiFunction Interface in Java with Examples
  • ToIntBiFunction Interface in Java with Examples
  • ToDoubleBiFunction Interface in Java with Examples
  • DoubleToLongFunction Interface in Java with Examples
  • IntToDoubleFunction Interface in Java with Examples
  • IntToLongFunction Interface in Java with Examples
  • DoubleToIntFunction Interface in Java with Example
  • ArrayDeque removeIf() method in Java with Examples

Conclusion

Java 8 has brought many exciting features that make it a powerful tool for developers. With the introduction of Lambda expressions, Stream API, and new Date and Time API, Java 8 has improved code efficiency and readability. These Java 8 features allow developers to write more flexible and concise code, making their work easier and more enjoyable. Overall, Java 8 continues to be a valuable update that has significantly enhanced the Java programming language.


Next Article
Java IO - Input/Output in Java with Examples
author
abhishek1
Improve
Article Tags :
  • Java
  • Java 8
  • Tutorials
Practice Tags :
  • Java

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
  • Java Overview

    • 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

    • The Complete History of Java Programming Language
      Java is an Object-Oriented programming language developed by James Gosling in the early 1990s. The team initiated this project to develop a language for digital devices such as set-top boxes, televisions, etc. Originally, C++ was considered to be used in the project, but the idea was rejected for se
      5 min read

    • How to Install Java on Windows, Linux and macOS?
      Java is a versatile programming language widely used for building applications. To start coding in Java, you first need to install the Java Development Kit (JDK) on your system. This article provides detailed steps for installing Java on Windows 7, 8, 10, 11, Linux Ubuntu, and macOS.Download and Ins
      5 min read

    • Setting up Environment Variables For Java - Complete Guide to Set JAVA_HOME
      In the journey to learning the Java programming language, setting up environment variables for Java is essential because it helps the system locate the Java tools needed to run the Java programs. Now, this guide on how to setting up environment variables for Java is a one-place solution for Mac, Win
      6 min read

    • How JVM Works - JVM Architecture
      JVM (Java Virtual Machine) runs Java applications as a run-time engine. JVM is the one that calls the main method present in a Java code. JVM is a part of JRE (Java Runtime Environment). Java applications are called WORA (Write Once Run Anywhere). This means a programmer can develop Java code on one
      7 min read

    • JDK in Java
      The Java Development Kit (JDK) is a cross-platformed software development environment that offers a collection of tools and libraries necessary for developing Java-based software applications and applets. It is a core package used in Java, along with the JVM (Java Virtual Machine) and the JRE (Java
      5 min read

    • Differences Between JDK, JRE and JVM
      Understanding the difference between JDK, JRE, and JVM plays a very important role in understanding how Java works and how each component contributes to the development and execution of Java applications. The main difference between JDK, JRE, and JVM is:JDK: Java Development Kit is a software develo
      3 min read

    Java Basics

    • Java Syntax
      Java is an object-oriented programming language that is known for its simplicity, portability, and robustness. The syntax of Java programming language is very closely aligned with C and C++, which makes it easier to understand. Java Syntax refers to a set of rules that define how Java programs are w
      6 min read

    • Java Hello World Program
      Java is one of the most popular and widely used programming languages and platforms. In this article, we will learn how to write a simple Java Program. This article will guide you on how to write, compile, and run your first Java program. With the help of Java, we can develop web and mobile applicat
      6 min read

    • Java Identifiers
      An identifier in Java is the name given to Variables, Classes, Methods, Packages, Interfaces, etc. These are the unique names used to identify programming elements. Every Java Variable must be identified with a unique name.Example:public class Test{ public static void main(String[] args) { int a = 2
      2 min read

    • Java Keywords
      In Java, keywords are the reserved words that have some predefined meanings and are used by the Java compiler for some internal process or represent some predefined actions. These words cannot be used as identifiers such as variable names, method names, class names, or object names. Now, let us go t
      5 min read

    • Java Data Types
      Java is statically typed and also a strongly typed language because each type of data, such as integer, character, hexadecimal, packed decimal etc. is predefined as part of the programming language, and all constants or variables defined for a given program must be declared with the specific data ty
      15 min read

    • Java Variables
      In Java, variables are containers that store data in memory. Understanding variables plays a very important role as it defines how data is stored, accessed, and manipulated.Key Components of Variables in Java:A variable in Java has three components, which are listed below:Data Type: Defines the kind
      9 min read

    • Scope of Variables in Java
      The scope of variables is the part of the program where the variable is accessible. Like C/C++, in Java, all identifiers are lexically (or statically) scoped, i.e., scope of a variable can be determined at compile time and independent of the function call stack. In this article, we will learn about
      7 min read

    • Java Operators
      Java operators are special symbols that perform operations on variables or values. These operators are essential in programming as they allow you to manipulate data efficiently. They can be classified into different categories based on their functionality. In this article, we will explore different
      15 min read

    • Java User Input - Scanner Class
      The most common way to take user input in Java is using the Scanner class. It is a part of java.util package. The scanner class can handle input from different places, like as we are typing at the console, reading from a file, or working with data streams. This class was introduced in Java 5. Before
      4 min read

    Java Flow Control

    • Java if statement
      The Java if statement is the most simple decision-making statement. It is used to decide whether a certain statement or block of statements will be executed or not i.e. if a certain condition is true then a block of statements is executed otherwise not.Example:Java// Java program to illustrate If st
      5 min read

    • Java if-else Statement
      The if-else statement in Java is a powerful decision-making tool used to control the program's flow based on conditions. It executes one block of code if a condition is true and another block if the condition is false. In this article, we will learn Java if-else statement with examples.Example:Java/
      3 min read

    • Java if-else-if ladder with Examples
      The Java if-else-if ladder is used to evaluate multiple conditions sequentially. It allows a program to check several conditions and execute the block of code associated with the first true condition. If none of the conditions are true, an optional else block can execute as a fallback.Example: The b
      3 min read

    • Java For Loop
      Java for loop is a control flow statement that allows code to be executed repeatedly based on a given condition. The for loop in Java provides an efficient way to iterate over a range of values, execute code multiple times, or traverse arrays and collections.Now let's go through a simple Java for lo
      4 min read

    • For-Each Loop in Java
      The for-each loop in Java (also called the enhanced for loop) was introduced in Java 5 to simplify iteration over arrays and collections. It is cleaner and more readable than the traditional for loop and is commonly used when the exact index of an element is not required.Example: Using a for-each lo
      8 min read

    • Java while Loop
      Java while loop is a control flow statement used to execute the block of statements repeatedly until the given condition evaluates to false. Once the condition becomes false, the line immediately after the loop in the program is executed.Let's go through a simple example of a Java while loop:Javapub
      3 min read

    • Java Do While Loop
      Java do-while loop is an Exit control loop. Unlike for or while loop, a do-while check for the condition after executing the statements of the loop body.Example:Java// Java program to show the use of do while loop public class GFG { public static void main(String[] args) { int c = 1; // Using do-whi
      4 min read

    • Java Break Statement
      The Break Statement in Java is a control flow statement used to terminate loops and switch cases. As soon as the break statement is encountered from within a loop, the loop iterations stop there, and control returns from the loop immediately to the first statement after the loop. Example:Java// Java
      3 min read

    • Java Continue Statement
      In Java, the continue statement is used inside the loops such as for, while, and do-while to skip the current iteration and move directly to the next iteration of the loop.Example:Java// Java Program to illustrate the use of continue statement public class Geeks { public static void main(String args
      4 min read

    • Java return Keyword
      return keyword in Java is a reserved keyword which is used to exit from a method, with or without a value. The usage of the return keyword can be categorized into two cases:Methods returning a valueMethods not returning a value1. Methods Returning a ValueFor the methods that define a return type, th
      4 min read

    Java Methods

    • 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

    • How to Call a Method in Java?
      In Java, calling a method helps us to reuse code and helps everything be organized. Java methods are just a block of code that does a specific task and gives us the result back. In this article, we are going to learn how to call different types of methods in Java with simple examples.What is a Metho
      3 min read

    • Static Method vs Instance Method in Java
      In Java, methods are mainly divided into two parts based on how they are connected to a class, which are the static method and the Instance method. The main difference between static and instance methods is listed below:Static method: A static method is a part of the class and can be called without
      4 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

    • Command Line Arguments in Java
      Java command-line argument is an argument, i.e., passed at the time of running the Java program. In Java, the command line arguments passed from the console can be received in the Java program, and they can be used as input. The users can pass the arguments during the execution, bypassing the comman
      3 min read

    • Variable Arguments (Varargs) in Java
      In Java, Variable Arguments (Varargs) write methods that can take any number of inputs, which simply means we do not have to create more methods for different numbers of parameters. This concept was introduced in Java 5 to make coding easier. Instead of passing arrays or multiple methods, we can sim
      5 min read

    Java Arrays

    • 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

    • How to Declare and Initialize an Array in Java?
      An array in Java is a linear data structure that is used to store multiple values of the same data type. In an array, each element has a unique index value, which makes it easy to access individual elements. We first need to declare the size of an array because the size of the array is fixed in Java
      5 min read

    • Java Multi-Dimensional Arrays
      Multidimensional arrays are used to store the data in rows and columns, where each row can represent another individual array are multidimensional array. It is also known as array of arrays. The multidimensional array has more than one dimension, where each row is stored in the heap independently. T
      10 min read

    • Jagged Array in Java
      In Java, a Jagged array is an array that holds other arrays. When we work with a jagged array, one thing to keep in mind is that the inner array can be of different lengths. It is like a 2D array, but each row can have a different number of elements.Example:arr [][]= { {10,20}, {30,40,50,60},{70,80,
      6 min read

    • Arrays Class in Java
      The Arrays class in java.util package is a part of the Java Collection Framework. This class provides static methods to dynamically create and access Java arrays. It consists of only static methods and the methods of an Object class. The methods of this class can be used by the class name itself.The
      15 min read

    • Final Arrays in Java
      In Java, final is a keyword that is used to make a variable constant. Once we declare a variable as final, its value can not be changed throughout the program. But when we use final with an array, it is a bit different thing. Final applies to the reference, not the contents. This means we cannot rea
      4 min read

    Java Strings

    • 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

    • Why Java Strings are Immutable?
      In Java, strings are immutable means their values cannot be changed once they are created. This feature enhances performance, security, and thread safety. In this article, we are going to learn why strings are immutable in Java and how this benefits Java applications.What Does Immutable Mean?When we
      4 min read

    • Java String concat() Method with Examples
      The string concat() method concatenates (appends) a string to the end of another string. It returns the combined string. It is used for string concatenation in Java. It returns NullPointerException if any one of the strings is Null.In this article, we will learn how to concatenate two strings in Jav
      4 min read

    • String Class in Java
      A string is a sequence of characters. In Java, objects of the String class are immutable, which means they cannot be changed once created. In this article, we are going to learn about the String class in Java.Example of String Class in Java:Java// Java Program to Create a String import java.io.*; cl
      7 min read

    • StringBuffer Class in Java
      The StringBuffer class in Java represents a sequence of characters that can be modified, which means we can change the content of the StringBuffer without creating a new object every time. It represents a mutable sequence of characters.Features of StringBuffer ClassThe key features of StringBuffer c
      11 min read

    • Java StringBuilder Class
      In Java, the StringBuilder class is a part of the java.lang package that provides a mutable sequence of characters. Unlike String (which is immutable), StringBuilder allows in-place modifications, making it memory-efficient and faster for frequent string operations.Declaration:StringBuilder sb = new
      7 min read

    • String vs StringBuilder vs StringBuffer in Java
      A string is a sequence of characters. In Java, String objects are immutable, which simply means once created, their values can not be changed. In Java, String, StringBuilder, and StringBuffer are used for handling strings. The main difference is:String: Immutable, meaning its value cannot be changed
      6 min read

    Java OOPs Concepts

    • 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

    • 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

    • Object Class in Java
      Object class in Java is present in java.lang package. Every class in Java is directly or indirectly derived from the Object class. If a class does not extend any other class then it is a direct child class of the Java Object class and if it extends another class then it is indirectly derived. The Ob
      7 min read

    • Abstraction in Java
      Abstraction in Java is the process of hiding the implementation details and only showing the essential details or features to the user. It allows to focus on what an object does rather than how it does it. The unnecessary details are not displayed to the user.Key features of abstraction:Abstraction
      10 min read

    • Encapsulation in Java
      In Java, encapsulation is one of the coret concept of Object Oriented Programming (OOP) in which we bind the data members and methods into a single unit. Encapsulation is used to hide the implementation part and show the functionality for better readability and usability. The following are important
      10 min read

    • Inheritance in Java
      Java Inheritance is a fundamental concept in OOP(Object-Oriented Programming). It is the mechanism in Java by which one class is allowed to inherit the features(fields and methods) of another class. In Java, Inheritance means creating new classes based on existing ones. A class that inherits from an
      13 min read

    • Polymorphism in Java
      Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
      7 min read

    • Method Overloading in Java
      In Java, Method Overloading allows us to define multiple methods with the same name but different parameters within a class. This difference may include:The number of parametersThe types of parametersThe order of parametersMethod overloading in Java is also known as Compile-time Polymorphism, Static
      10 min read

    • Overriding in Java
      Overriding in Java occurs when a subclass or child class implements a method that is already defined in the superclass or base class. When a subclass provides its own version of a method that is already defined in its superclass, we call it method overriding. The subclass method must match the paren
      15 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 Interfaces

    • 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

    • Interfaces and Inheritance in Java
      Java supports inheritance and interfaces, which are important concepts for building reusable code. A class can extend another class and can implement one and more than one Java interface. Note: This topic has a major influence on the concept of Java and Multiple Inheritance. Interface Implementation
      7 min read

    • Java Class vs Interfaces
      In Java, the difference between a class and an interface is syntactically similar; both contain methods and variables, but they are different in many aspects. The main difference is, A class defines the state of behaviour of objects.An interface defines the methods that a class must implement.Class
      5 min read

    • Java Functional Interfaces
      A functional interface in Java is an interface that contains only one abstract method. Functional interfaces can have multiple default or static methods, but only one abstract method. Runnable, ActionListener, and Comparator are common examples of Java functional interfaces. From Java 8 onwards, lam
      7 min read

    • Nested Interface in Java
      In Java, we can declare interfaces as members of a class or another interface. Such an interface is called a member interface or nested interface. Interfaces declared outside any class can have only public and default (package-private) access specifiers. In Java, nested interfaces (interfaces declar
      5 min read

    • Marker Interface in Java
      In Java, a marker Interface is an empty interface that has no fields or methods. It is used just to mark or tag a class to tell Java or other programs something special about that class. These interfaces do not have any methods inside but act as metadata to provide information about the class. Examp
      4 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
      6 min read

    Java 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 List Interface
      The List Interface in Java extends the Collection Interface and is a part of the java.util package. It is used to store the ordered collections of elements. In a Java List, we can organize and manage the data sequentially. Key Features:Maintained the order of elements in which they are added.Allows
      15+ min read

    • ArrayList in Java
      Java ArrayList is a part of the collections framework and it is a class of java.util package. It provides us with dynamic-sized arrays in Java. The main advantage of ArrayList is that, unlike normal arrays, we don't need to mention the size when creating ArrayList. It automatically adjusts its capac
      9 min read

    • Vector Class in Java
      The Vector class in Java implements a growable array of objects. Vectors were legacy classes, but now it is fully compatible with collections. It comes under java.util package and implement the List interface.Key Features of Vector:It expands as elements are added.Vector class is synchronized in nat
      12 min read

    • LinkedList in Java
      Linked List is a part of the Collection framework present in java.util package. This 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 an
      12 min read

    • Stack Class in Java
      The Java Collection framework provides a Stack class, which implements a Stack data structure. The class is based on the basic principle of LIFO (last-in-first-out). Besides the basic push and pop operations, the class also provides three more functions, such as empty, search, and peek. The Stack cl
      11 min read

    • Set in Java
      The Set Interface is present in java.util package and extends the Collection interface. It is an unordered collection of objects in which duplicate values cannot be stored. It is an interface that implements the mathematical set. This interface adds a feature that restricts the insertion of duplicat
      14 min read

    • Java HashSet
      HashSet in Java implements the Set interface of Collections Framework. It is used to store the unique elements and it doesn't maintain any specific order of elements. Can store the Null values.Uses HashMap (implementation of hash table data structure) internally.Also implements Serializable and Clon
      12 min read

    • TreeSet in Java
      TreeSet is one of the most important implementations of the SortedSet interface in Java that uses a Tree(red - black 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 equ
      13 min read

    • Java LinkedHashSet
      LinkedHashSet in Java implements the Set interface of the Collection Framework. It combines the functionality of a HashSet with a LinkedList to maintain the insertion order of elements. Stores unique elements only.Maintains insertion order.Provides faster iteration compared to HashSet.Allows null el
      8 min read

    • Queue Interface In Java
      The Queue Interface is a part of java.util package and extends the Collection interface. It stores and processes the data in order means elements are inserted at the end and removed from the front. Key Features:Most implementations, like PriorityQueue, do not allow null elements.Implementation Class
      11 min read

    • PriorityQueue in Java
      The PriorityQueue class in Java is part of the java.util package. It implements a priority heap-based queue that processes elements based on their priority rather than the FIFO (First-In-First-Out) concept of a Queue.Key Points:The PriorityQueue is based on the Priority Heap. The elements of the pri
      9 min read

    • Deque Interface in Java
      Deque Interface present in java.util package is a subtype of the queue interface. The Deque is related to the double-ended queue that supports adding or removing elements from either end of the data structure. It can either be used as a queue(first-in-first-out/FIFO) or as a stack(last-in-first-out/
      9 min read

    • Map Interface in Java
      In Java, the Map Interface is part of the java.util package and represents a mapping between a key and a value. The Java Map interface is not a subtype of the Collections interface. So, it behaves differently from the rest of the collection types.Key Features:No Duplicates in Keys: Keys should be un
      11 min read

    • HashMap in Java
      In Java, HashMap is part of the Java Collections Framework and is found in the java.util package. It provides the basic implementation of the Map interface in Java. HashMap stores data in (key, value) pairs. Each key is associated with a value, and you can access the value by using the corresponding
      15+ min read

    • Java LinkedHashMap
      LinkedHashMap in Java implements the Map interface of the Collections Framework. It stores key-value pairs while maintaining the insertion order of the entries. It maintains the order in which elements are added.Stores unique key-value pairs.Maintains insertion order.Allows one null key and multiple
      7 min read

    • Hashtable in Java
      Hashtable class, introduced as part of the Java Collections framework, implements a hash table that maps keys to values. Any non-null object can be used as a key or as a value. To successfully store and retrieve objects from a hashtable, the objects used as keys must implement the hashCode method an
      12 min read

    • Java Dictionary Class
      Dictionary class in Java is an abstract class that represents a collection of key-value pairs, where keys are unique and used to access the values. It was part of the Java Collections Framework and it was introduced in Java 1.0 but has been largely replaced by the Map interface since Java 1.2.Stores
      5 min read

    • SortedSet Interface in Java with Examples
      The SortedSet interface is present in java.util package extends the Set interface present in the collection framework. It is an interface that implements the mathematical set. This interface contains the methods inherited from the Set interface and adds a feature that stores all the elements in this
      8 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
      6 min read

    • Java Comparable Interface
      The Comparable interface in Java is used to define the natural ordering of objects for a user-defined class. It is part of the java.lang package and it provides a compareTo() method to compare instances of the class. A class has to implement a Comparable interface to define its natural ordering.Exam
      4 min read

    • Java Comparable vs Comparator
      In Java, both Comparable and Comparator interfaces are used for sorting objects. The main difference between Comparable and Comparator is:Comparable: It is used to define the natural ordering of the objects within the class.Comparator: It is used to define custom sorting logic externally.Difference
      5 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

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.

'); // $('.spinner-loading-overlay').show(); let script = document.createElement('script'); script.src = 'https://assets.geeksforgeeks.org/v2/editor-prod/static/js/bundle.min.js'; script.defer = true document.head.appendChild(script); script.onload = function() { suggestionModalEditor() //to add editor in suggestion modal if(loginData && loginData.premiumConsent){ personalNoteEditor() //to load editor in personal note } } script.onerror = function() { if($('.editorError').length){ $('.editorError').remove(); } var messageDiv = $('
').text('Editor not loaded due to some issues'); $('#suggestion-section-textarea').append(messageDiv); $('.suggest-bottom-btn').hide(); $('.suggestion-section').hide(); editorLoaded = false; } }); //suggestion modal editor function suggestionModalEditor(){ // editor params const params = { data: undefined, plugins: ["BOLD", "ITALIC", "UNDERLINE", "PREBLOCK"], } // loading editor try { suggestEditorInstance = new GFGEditorWrapper("suggestion-section-textarea", params, { appNode: true }) suggestEditorInstance._createEditor("") $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = true; } catch (error) { $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = false; } } //personal note editor function personalNoteEditor(){ // editor params const params = { data: undefined, plugins: ["UNDO", "REDO", "BOLD", "ITALIC", "NUMBERED_LIST", "BULLET_LIST", "TEXTALIGNMENTDROPDOWN"], placeholderText: "Description to be......", } // loading editor try { let notesEditorInstance = new GFGEditorWrapper("pn-editor", params, { appNode: true }) notesEditorInstance._createEditor(loginData&&loginData.user_personal_note?loginData.user_personal_note:"") $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = true; } catch (error) { $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = false; } } var lockedCasesHtml = `You can suggest the changes for now and it will be under 'My Suggestions' Tab on Write.

You will be notified via email once the article is available for improvement. Thank you for your valuable feedback!`; var badgesRequiredHtml = `It seems that you do not meet the eligibility criteria to create improvements for this article, as only users who have earned specific badges are permitted to do so.

However, you can still create improvements through the Pick for Improvement section.`; jQuery('.improve-header-sec-child').on('click', function(){ jQuery('.improve-modal--overlay').hide(); $('.improve-modal--suggestion').hide(); jQuery('#suggestion-modal-alert').hide(); }); $('.suggest-change_wrapper, .locked-status--impove-modal .improve-bottom-btn').on('click',function(){ // when suggest changes option is clicked $('.ContentEditable__root').text(""); $('.suggest-bottom-btn').html("Suggest changes"); $('.thank-you-message').css("display","none"); $('.improve-modal--improvement').hide(); $('.improve-modal--suggestion').show(); $('#suggestion-section-textarea').show(); jQuery('#suggestion-modal-alert').hide(); if(suggestEditorInstance !== null){ suggestEditorInstance.setEditorValue(""); } $('.suggestion-section').css('display', 'block'); jQuery('.suggest-bottom-btn').css("display","block"); }); $('.create-improvement_wrapper').on('click',function(){ // when create improvement option clicked then improvement reason will be shown if(loginData && loginData.isLoggedIn) { $('body').append('
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.unlocked-status--improve-modal-content').css("display","none"); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { showErrorMessage(e.responseJSON,e.status) }, }); } else { if(loginData && !loginData.isLoggedIn) { $('.improve-modal--overlay').hide(); if ($('.header-main__wrapper').find('.header-main__signup.login-modal-btn').length) { $('.header-main__wrapper').find('.header-main__signup.login-modal-btn').click(); } return; } } }); $('.left-arrow-icon_wrapper').on('click',function(){ if($('.improve-modal--suggestion').is(":visible")) $('.improve-modal--suggestion').hide(); else{ } $('.improve-modal--improvement').show(); }); const showErrorMessage = (result,statusCode) => { if(!result) return; $('.spinner-loading-overlay:eq(0)').remove(); if(statusCode == 403) { $('.improve-modal--improve-content.error-message').html(result.message); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); return; } } function suggestionCall() { var editorValue = suggestEditorInstance.getValue(); var suggest_val = $(".ContentEditable__root").find("[data-lexical-text='true']").map(function() { return $(this).text().trim(); }).get().join(' '); suggest_val = suggest_val.replace(/\s+/g, ' ').trim(); var array_String= suggest_val.split(" ") //array of words var gCaptchaToken = $("#g-recaptcha-response-suggestion-form").val(); var error_msg = false; if(suggest_val != "" && array_String.length >=4){ if(editorValue.length { jQuery('.ContentEditable__root').focus(); jQuery('#suggestion-modal-alert').hide(); }, 3000); } } document.querySelector('.suggest-bottom-btn').addEventListener('click', function(){ jQuery('body').append('
'); jQuery('.spinner-loading-overlay').show(); if(loginData && loginData.isLoggedIn) { suggestionCall(); return; } // script for grecaptcha loaded in loginmodal.html and call function to set the token setGoogleRecaptcha(); }); $('.improvement-bottom-btn.create-improvement-btn').click(function() { //create improvement button is clicked $('body').append('
'); $('.spinner-loading-overlay').show(); // send this option via create-improvement-post api jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { showErrorMessage(e.responseJSON,e.status); }, }); });
"For an ad-free experience and exclusive features, subscribe to our Premium Plan!"
Continue without supporting
`; $('body').append(adBlockerModal); $('body').addClass('body-for-ad-blocker'); const modal = document.getElementById("adBlockerModal"); modal.style.display = "block"; } function handleAdBlockerClick(type){ if(type == 'disabled'){ window.location.reload(); } else if(type == 'info'){ document.getElementById("ad-blocker-div").style.display = "none"; document.getElementById("ad-blocker-info-div").style.display = "flex"; handleAdBlockerIconClick(0); } } var lastSelected= null; //Mapping of name and video URL with the index. const adBlockerVideoMap = [ ['Ad Block Plus','https://media.geeksforgeeks.org/auth-dashboard-uploads/abp-blocker-min.mp4'], ['Ad Block','https://media.geeksforgeeks.org/auth-dashboard-uploads/Ad-block-min.mp4'], ['uBlock Origin','https://media.geeksforgeeks.org/auth-dashboard-uploads/ub-blocke-min.mp4'], ['uBlock','https://media.geeksforgeeks.org/auth-dashboard-uploads/U-blocker-min.mp4'], ] function handleAdBlockerIconClick(currSelected){ const videocontainer = document.getElementById('ad-blocker-info-div-gif'); const videosource = document.getElementById('ad-blocker-info-div-gif-src'); if(lastSelected != null){ document.getElementById("ad-blocker-info-div-icons-"+lastSelected).style.backgroundColor = "white"; document.getElementById("ad-blocker-info-div-icons-"+lastSelected).style.borderColor = "#D6D6D6"; } document.getElementById("ad-blocker-info-div-icons-"+currSelected).style.backgroundColor = "#D9D9D9"; document.getElementById("ad-blocker-info-div-icons-"+currSelected).style.borderColor = "#848484"; document.getElementById('ad-blocker-info-div-name-span').innerHTML = adBlockerVideoMap[currSelected][0] videocontainer.pause(); videosource.setAttribute('src', adBlockerVideoMap[currSelected][1]); videocontainer.load(); videocontainer.play(); lastSelected = currSelected; }

What kind of Experience do you want to share?

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