Record in Java

What is a Record in Java? A record is a special kind of class introduced in Java 16 (preview earlier), and fully standard from Java 16 onwards, designed to model immutable data. Think of it as a concise way to define a class whose main purpose is to store data. A record automatically provides:…

0 Comments

Stack in Java

In Java, a stack is a data structure that follows the LIFO (Last In, First Out) principle. This means the most recently added element is the first one to be removed. 1. Using java.util.Stack Java provides a built-in Stack class in java.util package. Example: import java.util.Stack; public class StackExample { public static void main(String[]…

0 Comments

Sequenced Collections

In Java 21, sequenced collections are part of the java.util package and are designed to maintain element insertion order, meaning the order in which elements were added is preserved. This is different from regular collections like HashSet or HashMap which do not guarantee order. Java 21 introduces enhancements to sequenced collections, building on previous…

0 Comments

Sealed Class in Java

1. What is a Sealed Class? A sealed class is a class that restricts which other classes or interfaces can extend or implement it. It allows you to control the inheritance hierarchy more strictly than abstract classes. Think of it like saying: “Only these specific classes are allowed to inherit from me.” 2. Why…

0 Comments

Generics in Java

🔹 What are Generics in Java? Generics allow you to write classes, interfaces, and methods where the type of data is specified as a parameter.This makes your code type-safe, reusable, and easier to read. Instead of writing separate classes/methods for different data types, you can use type parameters (<T>, <E>, <K, V>, etc.). 🔹…

0 Comments

Logging in Java

1. Using java.util.logging (built-in Java logging) import java.util.logging.Logger; import java.util.logging.Level; public class LoggingExample { private static final Logger logger = Logger.getLogger(LoggingExample.class.getName()); public static void main(String[] args) { logger.info("This is an info message"); logger.warning("This is a warning message"); logger.severe("This is a severe message"); int x = 5; int y = 0; try { int result…

0 Comments

Lombok Library

What is Lombok? Lombok is a Java library that helps reduce boilerplate code—the repetitive code you often write in Java, like getters, setters, constructors, toString(), hashCode(), etc. It does this through annotations that are processed at compile-time, so the generated code doesn’t appear in your source files but is present in the compiled bytecode.…

0 Comments

Apache Commons

Apache Commons is a popular set of reusable Java components developed by the Apache Software Foundation. Its goal is to provide well-tested, reusable code to simplify common programming tasks, so you don’t have to reinvent the wheel. It is widely used in enterprise and open-source projects. Here’s a structured overview: 1. Core Libraries in…

0 Comments

Guava in Java

What is Guava? Guava is an open-source Java library developed by Google. It provides a wide variety of core libraries that complement Java’s standard libraries. Guava focuses on making Java programming easier, safer, and more efficient. Some key areas Guava helps with: Collections Caching Functional programming utilities String manipulation Concurrency utilities Hashing I/O utilities…

0 Comments

Streams

In Java, I/O Streams are the core mechanism for reading from and writing to data sources such as files, network sockets, memory, or even the console.The term "stream" means a flow of data — either input (reading) or output (writing). 1. Types of Streams Java classifies streams along two main axes: a. Direction Input…

0 Comments

End of content

No more pages to load