Category: Java

  • JVM Architecture

    The JVM (Java Virtual Machine) architecture is a crucial part of the Java Runtime Environment (JRE) that enables Java applications to run on any device or operating system without modification. Here’s a breakdown of its core components: Absolutely! Let’s walk through a simple Java program and see how it flows through the JVM architecture step…

  • Gatherer API

    Introduced in Java 24, the Gatherer API is a powerful way to define custom intermediate operations in a Stream pipeline — something you couldn’t do easily before. It’s like a customizable version of map(), filter(), and flatMap(), but with more control and state awareness. Feature Traditional Stream Ops (map, filter, findFirst) Gatherer API Custom intermediate…

  • Virtual Threads in Java

    Virtual Threads v/s Platform (Normal) Threads Aspect Virtual Threads Platform Threads Thread Type Lightweight, managed by JVM, multiplexed on few OS threads Heavyweight, directly mapped to OS threads Creation Cost Very low; can create millions High; limited by OS and memory Blocking Behavior Cheap; JVM suspends and reuses carrier threads Expensive; blocks OS thread Best…

  • Structured Concurrency

    What is Structured Concurrency? Structured concurrency is a programming paradigm that treats groups of concurrent tasks as a single unit of work. It ensures that: ✅ Why Use It? ⚙️ How It Works (Java Example with StructuredTaskScope) 🌳 Benefits

  • Collecting statistics such as count, min, max, sum, and average

    Class Name Data Type Introduced In Package IntSummaryStatistics int Java 8 java.util LongSummaryStatistics long Java 8 java.util DoubleSummaryStatistics double Java 8 java.util Each of these classes provides:

  • Simple comparison between List.of() and Collections.unmodifiableList()

    Here’s a simple comparison between List.of() and Collections.unmodifiableList() Key Differences List.of() Collections.unmodifiableList() Java Version Java 9+ Java 1.2+ Backed by the original list ❌ No ✅ Yes Allows null elements ❌ No ✅ Yes (if original list has them) Reflects changes in the original ❌ No ✅ Yes Immutable or Unmodifiable ✅ Truly immutable ✅…

  • Yield Statement

    The yield statement is used in a switch expression to exit a case and return a value. This value becomes the result of the entire switch expression. The expression after yield must not be void. In a switch expression, use yield to return a value. return exits a method, not a switch case. Feature yield…

  • Var Type Identifier

    The var keyword can only be used for local variables inside methods, constructors, or initializer blocks. It can’t be used for fields or parameters. Additionally, the variable must be initialized immediately so the compiler can determine its type—null alone is not sufficient. Reference https://dev.java/learn/language-basics/using-var

  • Spring Boot Annotations

    @SpringBootApplication @SpringBootApplication is an annotation in the Spring Framework for Java that indicates that a class is a Spring Boot application. This annotation combines several other annotations, including @Configuration, @EnableAutoConfiguration, and @ComponentScan, into a single convenient annotation. The @Configuration annotation indicates that the class is a source of bean definitions for the application context. The…

  • Deserializing JSON to an abstract class, interface, or to inherited objects in Spring Boot Webclient

    @JsonTypeInfo and @JsonSubTypes annotations. First, you need to ensure that your classes are properly annotated for serialization and deserialization. You can use the @JsonTypeInfo and @JsonSubTypes annotations to specify the type hierarchy of your objects @JsonSubTypes with not matching any conditions and return as null If you have a JSON object that does not match…