Functional Interface in Java

A Functional Interface in Java 8 is an interface that has exactly one abstract method (SAM – Single Abstract Method). It can have any number of default and static methods, but only one abstract method. Functional interfaces are the foundation of Lambda Expressions and Method References in Java 8. ✅ Key Points Only one…

0 Comments

Method Reference in Java

In Java, method references provide a concise way to refer to methods or constructors without executing them. They are part of Java 8’s lambda expressions feature and are used mainly with functional interfaces. Method references make code shorter and more readable. Syntax There are four types of method references: Reference to a static method…

0 Comments

Optional in Java

In Java, Optional is a container object introduced in Java 8 that may or may not contain a non-null value. It is primarily used to avoid NullPointerException and to make code more readable by explicitly handling the presence or absence of values. Here’s a thorough breakdown: 1. Creating an Optional import java.util.Optional; public class…

0 Comments

java.time

java.time is Java’s modern date and time API, introduced in Java 8 to replace the older java.util.Date and java.util.Calendar classes. It’s part of the Java Time API (JSR-310) and is more consistent, immutable, and thread-safe. Let me walk you through the main classes with examples. 1. LocalDate – Date without time Represents a date…

0 Comments

default methods and static methods in interface

In Java 8, interfaces were enhanced significantly with the introduction of default methods and static methods. Earlier, interfaces could only declare abstract methods (implicitly public abstract) and constants (implicitly public static final). 🔹 1. Default Methods in Interfaces A default method is a method in an interface that has a body and uses the…

0 Comments

Iterator in Java

🔹 What is an Iterator? An Iterator in Java is an object that allows you to traverse (iterate) through a collection (like ArrayList, HashSet, etc.) one element at a time.It is part of the java.util package and is the standard way to loop through collections when you don’t want to use traditional loops. 🔹…

0 Comments

Map in Java

In Java, a Map is a data structure that stores key–value pairs. Each key is unique, but values can be duplicated. Maps are part of the Java Collections Framework, but they are not a subtype of Collection. Instead, they are their own interface in java.util. Here’s a breakdown: Map Interface Found in java.util. Represents…

0 Comments

List in Java

In Java, a List is an ordered collection (also called a sequence) that allows duplicate elements. It is part of the Java Collections Framework and is defined in the java.util package. 🔑 Key Points about Lists They maintain insertion order. Can contain duplicate elements. Elements can be accessed via index (zero-based). Lists are dynamic…

0 Comments

Set in Java

In Java, a Set is a collection that: Stores unique elements (no duplicates allowed). Does not guarantee order (depending on the implementation). Is part of the Java Collections Framework (java.util package). 🔑 Main Set Implementations 1. HashSet Backed by a hash table. Elements are unordered. Fast for add(), remove(), contains() (O(1) on average). import…

0 Comments

Date in Java

In Java, handling dates and calendars can be done using different APIs depending on which version of Java you’re working with: ✅ Modern Approach (Java 8 and later) Java 8 introduced the java.time package (JSR-310), which provides a much better and cleaner API for date and time handling. Common Classes: LocalDate → Date without…

0 Comments

End of content

No more pages to load