<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Java on Java &amp; Software Architecture Knowledge Hub</title><link>https://samirsahoo.github.io/design-patterns-hub/tags/java/</link><description>Recent content in Java on Java &amp; Software Architecture Knowledge Hub</description><generator>Hugo</generator><language>en-US</language><copyright>© 2026 Samir Kumar Sahoo (https://github.com/samirsahoo). All rights reserved.</copyright><atom:link href="https://samirsahoo.github.io/design-patterns-hub/tags/java/index.xml" rel="self" type="application/rss+xml"/><item><title>The Java Memory Model and Happens-Before</title><link>https://samirsahoo.github.io/design-patterns-hub/java/advanced/java-memory-model/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/advanced/java-memory-model/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Java Memory Model (JMM)&lt;/strong&gt;, defined in chapter 17 of the Java Language Specification, specifies &lt;strong&gt;when a write made by one thread is guaranteed to be visible to another&lt;/strong&gt;. It defines a &lt;strong&gt;happens-before&lt;/strong&gt; relation: if action A happens-before action B, then B sees A&amp;rsquo;s effects.&lt;/p&gt;</description></item><item><title>Garbage Collection: G1, ZGC and Tuning Basics</title><link>https://samirsahoo.github.io/design-patterns-hub/java/advanced/garbage-collection/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/advanced/garbage-collection/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;&lt;strong&gt;Garbage collection (GC)&lt;/strong&gt; automatically frees heap memory used by objects that the program &lt;strong&gt;can no longer reach&lt;/strong&gt;. The JVM ships several collectors that trade &lt;strong&gt;pause time&lt;/strong&gt;, &lt;strong&gt;throughput&lt;/strong&gt; and &lt;strong&gt;memory overhead&lt;/strong&gt; differently.&lt;/p&gt;&#10;&lt;h2 id="the-problem"&gt;The problem&lt;a class="heading-anchor" href="#the-problem" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Manual memory management causes leaks and use-after-free bugs. Automatic GC removes those but costs CPU and sometimes &lt;strong&gt;pauses&lt;/strong&gt; the application. The right collector and heap size can turn 2-second pauses into sub-millisecond ones, or double throughput.&lt;/p&gt;</description></item><item><title>Functional Programming in Java: Lambdas, Method References and Streams</title><link>https://samirsahoo.github.io/design-patterns-hub/java/advanced/functional-programming-and-streams/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/advanced/functional-programming-and-streams/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;&lt;strong&gt;Functional programming in Java&lt;/strong&gt; means passing &lt;strong&gt;behaviour as values&lt;/strong&gt;:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;lambdas&lt;/strong&gt; and &lt;strong&gt;method references&lt;/strong&gt; implement &lt;strong&gt;functional interfaces&lt;/strong&gt; (interfaces with one abstract method)&lt;/li&gt;&#10;&lt;li&gt;the &lt;strong&gt;Streams API&lt;/strong&gt; processes data declaratively: you say &lt;strong&gt;what&lt;/strong&gt; to compute (filter, map, group), not &lt;strong&gt;how&lt;/strong&gt; to loop.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="the-problem"&gt;The problem&lt;a class="heading-anchor" href="#the-problem" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Loops mix the &amp;ldquo;what&amp;rdquo; with the &amp;ldquo;how&amp;rdquo;: index variables, temporary collections and mutable accumulators. Anonymous inner classes for callbacks were verbose. Lambdas and streams make data transformations shorter and clearer, and easier to parallelise &lt;strong&gt;when&lt;/strong&gt; that helps.&lt;/p&gt;</description></item><item><title>The Java Concurrency API: Executors, CompletableFuture, Locks and Concurrent Collections</title><link>https://samirsahoo.github.io/design-patterns-hub/java/advanced/concurrency-api/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/advanced/concurrency-api/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;&lt;code&gt;java.util.concurrent&lt;/code&gt; provides &lt;strong&gt;higher-level building blocks&lt;/strong&gt; for running work in parallel and coordinating threads safely:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;executors&lt;/strong&gt; run tasks&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;futures&lt;/strong&gt; represent results that arrive later&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;locks and atomics&lt;/strong&gt; protect shared state&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;concurrent collections&lt;/strong&gt; are safe to share between threads.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="the-problem"&gt;The problem&lt;a class="heading-anchor" href="#the-problem" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Creating raw &lt;code&gt;Thread&lt;/code&gt;s per task does not scale (platform threads are expensive OS threads). Hand-written &lt;code&gt;wait&lt;/code&gt;/&lt;code&gt;notify&lt;/code&gt; code is notoriously buggy. Sharing a plain &lt;code&gt;HashMap&lt;/code&gt; between threads corrupts it. The concurrency API gives tested abstractions, so you rarely touch low-level primitives.&lt;/p&gt;</description></item><item><title>Virtual Threads, Structured Concurrency and Scoped Values</title><link>https://samirsahoo.github.io/design-patterns-hub/java/advanced/virtual-threads-and-structured-concurrency/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/advanced/virtual-threads-and-structured-concurrency/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;A &lt;strong&gt;virtual thread&lt;/strong&gt; (Java 21, Project Loom) is a &lt;code&gt;Thread&lt;/code&gt; managed by the JVM rather than the operating system. It is so cheap that you can create &lt;strong&gt;millions&lt;/strong&gt;, one per request or task. When it blocks on I/O, the JVM &lt;strong&gt;parks&lt;/strong&gt; it and frees the underlying OS thread for other work.&lt;/p&gt;</description></item><item><title>Exception Handling and Try-With-Resources</title><link>https://samirsahoo.github.io/design-patterns-hub/java/fundamentals/exceptions-and-try-with-resources/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/fundamentals/exceptions-and-try-with-resources/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;An &lt;strong&gt;exception&lt;/strong&gt; is an object that signals that something went wrong and transfers control to the nearest matching &lt;code&gt;catch&lt;/code&gt;. &lt;strong&gt;Try-with-resources&lt;/strong&gt; automatically closes resources such as files, connections and streams, even when exceptions occur.&lt;/p&gt;&#10;&lt;h2 id="the-problem"&gt;The problem&lt;a class="heading-anchor" href="#the-problem" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Error codes are easy to ignore, and manual cleanup in &lt;code&gt;finally&lt;/code&gt; blocks is verbose and buggy: a second exception during cleanup hides the first. Badly designed exceptions leak implementation details, lose root causes or force callers into empty &lt;code&gt;catch&lt;/code&gt; blocks.&lt;/p&gt;</description></item><item><title>The Java Platform Module System (JPMS)</title><link>https://samirsahoo.github.io/design-patterns-hub/java/advanced/java-module-system/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/advanced/java-module-system/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Java Platform Module System (JPMS)&lt;/strong&gt;, introduced in Java 9 (Project Jigsaw), groups packages into &lt;strong&gt;modules&lt;/strong&gt; with explicit &lt;strong&gt;dependencies&lt;/strong&gt; (&lt;code&gt;requires&lt;/code&gt;) and an explicit &lt;strong&gt;public API&lt;/strong&gt; (&lt;code&gt;exports&lt;/code&gt;). Everything else is &lt;strong&gt;strongly encapsulated&lt;/strong&gt;: other modules cannot use it, even through reflection.&lt;/p&gt;</description></item><item><title>Designing Concurrent Objects: Safety, Liveness and Locking Strategies</title><link>https://samirsahoo.github.io/design-patterns-hub/java/advanced/concurrent-object-design/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/advanced/concurrent-object-design/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;A &lt;strong&gt;thread-safe&lt;/strong&gt; class behaves correctly when its methods are called from several threads at the same time, without callers needing extra synchronization. Designing one means balancing four forces that Doug Lea describes in &lt;em&gt;Concurrent Programming in Java&lt;/em&gt;:&lt;/p&gt;</description></item><item><title>Generics, Wildcards and Type Erasure</title><link>https://samirsahoo.github.io/design-patterns-hub/java/fundamentals/generics-and-type-erasure/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/fundamentals/generics-and-type-erasure/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;&lt;strong&gt;Generics&lt;/strong&gt; let classes, interfaces and methods take &lt;strong&gt;types as parameters&lt;/strong&gt;, such as &lt;code&gt;List&amp;lt;Order&amp;gt;&lt;/code&gt; or &lt;code&gt;Map&amp;lt;String, Price&amp;gt;&lt;/code&gt;. The compiler checks that you put in and take out only the right type. At runtime most of that type information is &lt;strong&gt;erased&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>The Java Collections Framework: Internal Architecture</title><link>https://samirsahoo.github.io/design-patterns-hub/java/fundamentals/collections-framework/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/fundamentals/collections-framework/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Java Collections Framework (JCF)&lt;/strong&gt; is a set of &lt;strong&gt;interfaces&lt;/strong&gt; (&lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt;, &lt;code&gt;Map&lt;/code&gt;, &lt;code&gt;Queue&lt;/code&gt;, &lt;code&gt;Deque&lt;/code&gt;), &lt;strong&gt;implementations&lt;/strong&gt; (&lt;code&gt;ArrayList&lt;/code&gt;, &lt;code&gt;HashMap&lt;/code&gt;, &lt;code&gt;TreeMap&lt;/code&gt; and others) and &lt;strong&gt;algorithms&lt;/strong&gt; (&lt;code&gt;Collections.sort&lt;/code&gt;, &lt;code&gt;binarySearch&lt;/code&gt;) for storing and processing groups of objects.&lt;/p&gt;&#10;&lt;h2 id="the-problem"&gt;The problem&lt;a class="heading-anchor" href="#the-problem" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Choosing the wrong collection is one of the most common hidden performance bugs: &lt;code&gt;contains&lt;/code&gt; on a large &lt;code&gt;ArrayList&lt;/code&gt; is O(n), and &lt;code&gt;LinkedList.get(i)&lt;/code&gt; walks the list. Mutable keys break &lt;code&gt;HashMap&lt;/code&gt;. Knowing the internals tells you the costs.&lt;/p&gt;</description></item><item><title>State-Dependent Actions: Balking, Guarded Suspension and Timeouts</title><link>https://samirsahoo.github.io/design-patterns-hub/java/advanced/state-dependent-actions/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/advanced/state-dependent-actions/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;A &lt;strong&gt;state-dependent action&lt;/strong&gt; is an operation that only makes sense when an object is in a certain state: you cannot take an item from an empty queue, withdraw from an empty account, or start an engine that is already running. In a single-threaded program, the wrong state is an error. In a concurrent program, the state might become right &lt;strong&gt;if you wait&lt;/strong&gt;, because another thread may change it.&lt;/p&gt;</description></item><item><title>Concurrency Design Patterns: Messages, Worker Threads, Futures, Cancellation and Pipelines</title><link>https://samirsahoo.github.io/design-patterns-hub/java/advanced/concurrency-design-patterns/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/advanced/concurrency-design-patterns/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Once objects are safe to share (see &lt;a href="https://samirsahoo.github.io/design-patterns-hub/java/advanced/concurrent-object-design/"&gt;Designing concurrent objects&lt;/a&gt;), the next question is &lt;strong&gt;how work gets onto threads&lt;/strong&gt; and how results and failures come back. Doug Lea&amp;rsquo;s &lt;em&gt;Concurrent Programming in Java&lt;/em&gt; catalogues the recurring answers. Most now have direct support in &lt;code&gt;java.util.concurrent&lt;/code&gt;, so this page names each pattern, explains the forces behind it, and shows the modern API.&lt;/p&gt;</description></item><item><title>Modern Java: Records, Sealed Classes and Pattern Matching</title><link>https://samirsahoo.github.io/design-patterns-hub/java/fundamentals/modern-java-features/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/fundamentals/modern-java-features/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Modern Java (16 to 21, refined through 25 LTS and 27) adds features for modelling &lt;strong&gt;data as data&lt;/strong&gt;:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;records&lt;/strong&gt; for transparent, immutable data carriers&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;sealed types&lt;/strong&gt; for closed sets of alternatives&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;pattern matching&lt;/strong&gt; to safely take data apart and branch on its shape.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Together these are called &lt;strong&gt;data-oriented programming&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>Reflection API and Dynamic Proxies</title><link>https://samirsahoo.github.io/design-patterns-hub/java/fundamentals/reflection-and-dynamic-proxies/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/java/fundamentals/reflection-and-dynamic-proxies/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Reflection&lt;/strong&gt; lets a program &lt;strong&gt;inspect and use&lt;/strong&gt; classes, methods, fields, constructors and annotations &lt;strong&gt;at runtime&lt;/strong&gt;, without knowing them at compile time.&lt;/li&gt;&#10;&lt;li&gt;A &lt;strong&gt;dynamic proxy&lt;/strong&gt; is an object created at runtime that &lt;strong&gt;implements interfaces&lt;/strong&gt; (or subclasses a class) and routes every method call through your handler code.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Together they are the engine behind dependency injection, AOP, ORMs, serialisation and test mocks.&lt;/p&gt;</description></item></channel></rss>