<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: shantanu mahakale</title>
    <description>The latest articles on Forem by shantanu mahakale (@codeintention).</description>
    <link>https://forem.com/codeintention</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3602975%2F8cb76ba4-a341-4358-b3c6-2752b6b42aae.jpg</url>
      <title>Forem: shantanu mahakale</title>
      <link>https://forem.com/codeintention</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/codeintention"/>
    <language>en</language>
    <item>
      <title>Quick Recap: Caching in Java</title>
      <dc:creator>shantanu mahakale</dc:creator>
      <pubDate>Fri, 21 Nov 2025 16:21:18 +0000</pubDate>
      <link>https://forem.com/codeintention/quick-recap-caching-in-java-3k5k</link>
      <guid>https://forem.com/codeintention/quick-recap-caching-in-java-3k5k</guid>
      <description>&lt;p&gt;Caching stores frequently accessed data in memory to improve performance and reduce expensive calls (e.g., DB/API). It helps speed up applications and reduce load on resources.&lt;/p&gt;

&lt;p&gt;Java provides multiple ways to implement caching — from simple in-memory maps to production-grade caching frameworks.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Use Caching?
&lt;/h2&gt;

&lt;p&gt;✔ Improves performance&lt;br&gt;&lt;br&gt;
✔ Reduces DB/API calls&lt;br&gt;&lt;br&gt;
✔ Faster response times&lt;br&gt;&lt;br&gt;
✔ Better scalability&lt;br&gt;&lt;br&gt;
✔ Helps design high-performance systems&lt;/p&gt;


&lt;h2&gt;
  
  
  Types of Caching
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Cache Type&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example Use Case&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;In-Memory&lt;/td&gt;
&lt;td&gt;Stored in JVM memory&lt;/td&gt;
&lt;td&gt;Java Map, LRU Cache&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Distributed&lt;/td&gt;
&lt;td&gt;Shared across servers&lt;/td&gt;
&lt;td&gt;Redis, Hazelcast&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Local + Remote&lt;/td&gt;
&lt;td&gt;Hybrid&lt;/td&gt;
&lt;td&gt;Ehcache with DB store&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Application-Level&lt;/td&gt;
&lt;td&gt;Annotations-based&lt;/td&gt;
&lt;td&gt;Spring Cache&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h2&gt;
  
  
  Simple In-Memory Cache Using Map
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Map&amp;lt;String, String&amp;gt; cache = new HashMap&amp;lt;&amp;gt;();
cache.put("user:1", "John");
cache.get("user:1"); // Fast lookup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;⚠ Not thread-safe &amp;amp; no eviction policy.&lt;/p&gt;


&lt;h2&gt;
  
  
  LRU Cache (Least Recently Used)
&lt;/h2&gt;

&lt;p&gt;Using &lt;strong&gt;LinkedHashMap&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LinkedHashMap&amp;lt;K,V&amp;gt; cache = new LinkedHashMap&amp;lt;&amp;gt;(16, 0.75f, true) {
protected boolean removeEldestEntry(Map.Entry&amp;lt;K,V&amp;gt; eldest) {
return size() &amp;gt; 100; // Max entries
}
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Removes least-used items automatically&lt;br&gt;&lt;br&gt;
👉 Best for lightweight caching&lt;/p&gt;


&lt;h2&gt;
  
  
  Concurrent Caching
&lt;/h2&gt;

&lt;p&gt;Use &lt;code&gt;ConcurrentHashMap&lt;/code&gt; for thread-safe cache:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ConcurrentHashMap&amp;lt;String, Object&amp;gt; cache = new ConcurrentHashMap&amp;lt;&amp;gt;();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✔ Safe for multi-threaded access&lt;br&gt;&lt;br&gt;
❌ No eviction/TTL built-in&lt;/p&gt;




&lt;h2&gt;
  
  
  Popular Caching Libraries
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Library&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Use Case&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Ehcache&lt;/td&gt;
&lt;td&gt;Local / Hybrid&lt;/td&gt;
&lt;td&gt;Spring apps, Hibernate&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Caffeine&lt;/td&gt;
&lt;td&gt;In-memory&lt;/td&gt;
&lt;td&gt;High-performance LRU/TTL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Redis&lt;/td&gt;
&lt;td&gt;Distributed&lt;/td&gt;
&lt;td&gt;Microservices, APIs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hazelcast&lt;/td&gt;
&lt;td&gt;Distributed&lt;/td&gt;
&lt;td&gt;Cluster-wide caching&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Guava Cache&lt;/td&gt;
&lt;td&gt;In-memory&lt;/td&gt;
&lt;td&gt;Simple TTL, eviction&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Example: Using Caffeine Cache (High Performance)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cache&amp;lt;String, Object&amp;gt; cache = Caffeine.newBuilder()
.maximumSize(1000)
.expireAfterWrite(10, TimeUnit.MINUTES)
.build();
cache.put("user:1", userObject);
cache.getIfPresent("user:1");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✔ Very fast in-memory caching&lt;br&gt;&lt;br&gt;
✔ Supports eviction &amp;amp; TTL&lt;br&gt;&lt;br&gt;
✔ Used in modern Spring Boot apps&lt;/p&gt;




&lt;h2&gt;
  
  
  Spring Boot Caching (Annotation-Based)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Enable Caching:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@EnableCaching
@SpringBootApplication
public class App {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Apply Cache:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Cacheable("users")
public User getUser(int id) {
return userRepo.findById(id); // Runs only once
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Evict Cache:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@CacheEvict(value="users", allEntries=true)
public void clearCache() {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Supports: &lt;strong&gt;Caffeine, Redis, Ehcache, Hazelcast&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  When to Use Which Cache?
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Recommended Cache&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Basic in-memory&lt;/td&gt;
&lt;td&gt;HashMap / ConcurrentHashMap&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LRU logic&lt;/td&gt;
&lt;td&gt;LinkedHashMap / Caffeine&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Spring Boot apps&lt;/td&gt;
&lt;td&gt;@Cacheable + Caffeine&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Microservices&lt;/td&gt;
&lt;td&gt;Redis / Hazelcast&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Distributed apps&lt;/td&gt;
&lt;td&gt;Redis / Memcached&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Common Pitfalls
&lt;/h2&gt;

&lt;p&gt;❌ Memory leaks (no eviction)&lt;br&gt;&lt;br&gt;
❌ Stale data issues&lt;br&gt;&lt;br&gt;
❌ Incorrect TTL configuration&lt;br&gt;&lt;br&gt;
❌ Using cache for everything&lt;br&gt;&lt;br&gt;
❌ Cache inconsistency across multiple nodes&lt;/p&gt;




&lt;h2&gt;
  
  
  Best Practices
&lt;/h2&gt;

&lt;p&gt;✔ Monitor cache hit/miss ratio&lt;br&gt;&lt;br&gt;
✔ Set eviction &amp;amp; TTL policies&lt;br&gt;&lt;br&gt;
✔ Avoid caching large objects&lt;br&gt;&lt;br&gt;
✔ Use caching only for read-heavy data&lt;br&gt;&lt;br&gt;
✔ Prefer Caffeine or Redis for production&lt;/p&gt;

</description>
      <category>java</category>
      <category>performance</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>Quick Recap: Maps in Java</title>
      <dc:creator>shantanu mahakale</dc:creator>
      <pubDate>Fri, 21 Nov 2025 16:09:32 +0000</pubDate>
      <link>https://forem.com/codeintention/quick-recap-maps-in-java-5bei</link>
      <guid>https://forem.com/codeintention/quick-recap-maps-in-java-5bei</guid>
      <description>&lt;p&gt;Java provides multiple &lt;code&gt;Map&lt;/code&gt; implementations — each designed for different use cases such as fast lookups, sorted data, concurrency, or predictable order. Understanding their internal working helps in writing performant code.&lt;/p&gt;




&lt;h2&gt;
  
  
  Main Map Implementations
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Map Type&lt;/th&gt;
&lt;th&gt;Ordering&lt;/th&gt;
&lt;th&gt;Thread-Safe&lt;/th&gt;
&lt;th&gt;Best For&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;HashMap&lt;/td&gt;
&lt;td&gt;No order&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;Fast lookup&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LinkedHashMap&lt;/td&gt;
&lt;td&gt;Insertion order&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;Caching (LRU)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TreeMap&lt;/td&gt;
&lt;td&gt;Sorted order&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;Range queries&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ConcurrentHashMap&lt;/td&gt;
&lt;td&gt;No order&lt;/td&gt;
&lt;td&gt;✔ Yes&lt;/td&gt;
&lt;td&gt;Concurrent access&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  1. HashMap (Most Used)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Uses &lt;strong&gt;array + linked list / tree (red-black tree)&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Default capacity = 16, load factor = 0.75
&lt;/li&gt;
&lt;li&gt;Collisions handled using &lt;strong&gt;chaining&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Hashing Logic:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;index = hash(key) &amp;amp; (n - 1) // n = array size
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;When collision occurs:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Java 8+: if bucket size &amp;gt; 8 → converts &lt;strong&gt;list → tree&lt;/strong&gt; (better performance)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Time Complexity:&lt;/strong&gt;&lt;br&gt;
| Operation | Average | Worst |&lt;br&gt;
|-----------|---------|-------|&lt;br&gt;
| get/put | O(1) | O(n) (if all collide) |&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best For:&lt;/strong&gt; Fast lookups, general-purpose storage&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Not Thread-safe&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  2. LinkedHashMap
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Extends &lt;code&gt;HashMap&lt;/code&gt; → &lt;strong&gt;maintains insertion order&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Uses &lt;strong&gt;doubly linked list + HashMap&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Can be used for &lt;strong&gt;LRU Cache&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// LRU Cache Example
LinkedHashMap&amp;lt;K,V&amp;gt; cache = new LinkedHashMap&amp;lt;&amp;gt;(16, 0.75f, true) {
  protected boolean removeEldestEntry(Map.Entry&amp;lt;K,V&amp;gt; eldest) {
  return size() &amp;gt; 100;
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best For:&lt;/strong&gt; Caching / maintaining order&lt;/p&gt;




&lt;h2&gt;
  
  
  3. TreeMap
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Implements &lt;strong&gt;Red-Black Tree&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Keys sorted in &lt;strong&gt;natural order&lt;/strong&gt; or using &lt;code&gt;Comparator&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Supports &lt;strong&gt;range queries, floorKey(), ceilingKey()&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TreeMap&amp;lt;Integer, String&amp;gt; map = new TreeMap&amp;lt;&amp;gt;();
map.put(10, "A");
map.put(5, "B");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Time Complexity (always):&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;get()&lt;/code&gt; → O(log n)
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;put()&lt;/code&gt; → O(log n)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Best For:&lt;/strong&gt; Sorted data, range-based queries&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Cannot store null keys&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  4. ConcurrentHashMap
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Thread-safe, &lt;strong&gt;non-blocking concurrent access&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Uses &lt;strong&gt;bucket-level locking (segments)&lt;/strong&gt; in Java 7
&lt;/li&gt;
&lt;li&gt;Java 8+: &lt;strong&gt;CAS + synchronized blocks&lt;/strong&gt;, no segments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Key Idea:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiple threads can read/write safely&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;synchronized&lt;/code&gt; keyword needed
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example
Map&amp;lt;String, Integer&amp;gt; map = new ConcurrentHashMap&amp;lt;&amp;gt;();
map.put("A", 1);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best For:&lt;/strong&gt; Highly concurrent applications&lt;/p&gt;




&lt;h2&gt;
  
  
  Internal Comparison
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;HashMap&lt;/th&gt;
&lt;th&gt;LinkedHashMap&lt;/th&gt;
&lt;th&gt;TreeMap&lt;/th&gt;
&lt;th&gt;ConcurrentHashMap&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Order&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Insertion&lt;/td&gt;
&lt;td&gt;Sorted&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Thread-safe&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Null Keys&lt;/td&gt;
&lt;td&gt;1 allowed&lt;/td&gt;
&lt;td&gt;1 allowed&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance&lt;/td&gt;
&lt;td&gt;Fastest&lt;/td&gt;
&lt;td&gt;Slight overhead&lt;/td&gt;
&lt;td&gt;O(log n)&lt;/td&gt;
&lt;td&gt;High in concurrency&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  When to Use What?
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Recommended Map&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Fast lookup&lt;/td&gt;
&lt;td&gt;HashMap&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Maintain order&lt;/td&gt;
&lt;td&gt;LinkedHashMap&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sorted data&lt;/td&gt;
&lt;td&gt;TreeMap&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multithreading&lt;/td&gt;
&lt;td&gt;ConcurrentHashMap&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LRU Cache&lt;/td&gt;
&lt;td&gt;LinkedHashMap&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Range queries&lt;/td&gt;
&lt;td&gt;TreeMap&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>algorithms</category>
      <category>java</category>
      <category>performance</category>
    </item>
    <item>
      <title>Quick Recap: Internal Working of Lists in Java</title>
      <dc:creator>shantanu mahakale</dc:creator>
      <pubDate>Fri, 21 Nov 2025 16:05:04 +0000</pubDate>
      <link>https://forem.com/codeintention/quick-recap-internal-working-of-lists-in-java-46hk</link>
      <guid>https://forem.com/codeintention/quick-recap-internal-working-of-lists-in-java-46hk</guid>
      <description>&lt;p&gt;Java provides multiple List implementations — each with different internal mechanisms and performance trade-offs. Choosing the right one based on use case is important for performance.&lt;/p&gt;




&lt;h2&gt;
  
  
  Most Common List Implementations
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;List Type&lt;/th&gt;
&lt;th&gt;Main Feature&lt;/th&gt;
&lt;th&gt;Use Case&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;ArrayList&lt;/td&gt;
&lt;td&gt;Fast reads&lt;/td&gt;
&lt;td&gt;General-purpose&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LinkedList&lt;/td&gt;
&lt;td&gt;Fast insert/delete&lt;/td&gt;
&lt;td&gt;Frequent add/remove&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Vector&lt;/td&gt;
&lt;td&gt;Synchronized ArrayList&lt;/td&gt;
&lt;td&gt;Legacy thread-safe code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CopyOnWriteArrayList&lt;/td&gt;
&lt;td&gt;Thread-safe &amp;amp; immutable copy on write&lt;/td&gt;
&lt;td&gt;Concurrent reads, few writes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  1. ArrayList (Most Used)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Backed by &lt;strong&gt;dynamic array&lt;/strong&gt; (&lt;code&gt;Object[]&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fast random access&lt;/strong&gt; — O(1) using index&lt;/li&gt;
&lt;li&gt;When full → grows by &lt;strong&gt;50%&lt;/strong&gt; (in newer JDKs)&lt;/li&gt;
&lt;li&gt;Not thread-safe&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Internal Resize Logic:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;newCapacity = oldCapacity + (oldCapacity &amp;gt;&amp;gt; 1); // 1.5x growth
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best For:&lt;/strong&gt; Read-heavy operations &amp;amp; small modifications&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Avoid When:&lt;/strong&gt; Frequent insert/delete from middle → O(n) shifts&lt;/p&gt;


&lt;h2&gt;
  
  
  2. LinkedList
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Doubly Linked List&lt;/strong&gt; internally (&lt;code&gt;prev&lt;/code&gt;, &lt;code&gt;next&lt;/code&gt; pointers)&lt;/li&gt;
&lt;li&gt;No index-based access → O(n)&lt;/li&gt;
&lt;li&gt;Insertion &amp;amp; deletion = O(1) (if position known)&lt;/li&gt;
&lt;li&gt;More memory overhead (storing pointers)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Node Structure:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Node&amp;lt;E&amp;gt; {
  E item;
  Node&amp;lt;E&amp;gt; next;
  Node&amp;lt;E&amp;gt; prev;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best For:&lt;/strong&gt; Queue/Deque, frequent add/remove&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Avoid When:&lt;/strong&gt; Random access &amp;amp; large data reads&lt;/p&gt;


&lt;h2&gt;
  
  
  3. Vector (Legacy Thread-Safe)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Same as ArrayList but &lt;strong&gt;synchronized&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Grows by &lt;strong&gt;100%&lt;/strong&gt; (double size)&lt;/li&gt;
&lt;li&gt;Old and not used in modern apps&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Resize Logic:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;newCapacity = oldCapacity * 2;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best For:&lt;/strong&gt; Legacy apps with single-threaded logic&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Avoid When:&lt;/strong&gt; Modern concurrency → use &lt;strong&gt;ArrayList + sync&lt;/strong&gt; or &lt;strong&gt;CopyOnWriteArrayList&lt;/strong&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  4. CopyOnWriteArrayList
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Used in &lt;strong&gt;concurrent environments&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;On every write → creates &lt;strong&gt;new copy of array&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;No locks during read → very fast reads&lt;/li&gt;
&lt;li&gt;Write operations = expensive (copy on each change)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Internal Write Logic:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public boolean add(E e) {
synchronized (lock) {
Object[] newArr = Arrays.copyOf(oldArr, oldArr.length + 1);
newArr[last] = e;
array = newArr;
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best For:&lt;/strong&gt; Many reads, very few writes&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Avoid When:&lt;/strong&gt; Write-heavy operations (slow performance)&lt;/p&gt;




&lt;h2&gt;
  
  
  Performance Comparison
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th&gt;ArrayList&lt;/th&gt;
&lt;th&gt;LinkedList&lt;/th&gt;
&lt;th&gt;CopyOnWriteArrayList&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Read by index&lt;/td&gt;
&lt;td&gt;🚀 Fast&lt;/td&gt;
&lt;td&gt;❌ Slow&lt;/td&gt;
&lt;td&gt;🚀 Fast&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Insert/Delete middle&lt;/td&gt;
&lt;td&gt;❌ Slow&lt;/td&gt;
&lt;td&gt;🚀 Fast&lt;/td&gt;
&lt;td&gt;❌ Very slow&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Thread safety&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Memory usage&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;Medium–High&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  When to Use What?
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Recommended List&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Random access&lt;/td&gt;
&lt;td&gt;ArrayList&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Frequent insert/delete&lt;/td&gt;
&lt;td&gt;LinkedList&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Legacy sync code&lt;/td&gt;
&lt;td&gt;Vector&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Concurrent reads, few writes&lt;/td&gt;
&lt;td&gt;CopyOnWriteArrayList&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Queue / Deque&lt;/td&gt;
&lt;td&gt;LinkedList&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;List Type&lt;/th&gt;
&lt;th&gt;Backed By&lt;/th&gt;
&lt;th&gt;Best Use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;ArrayList&lt;/td&gt;
&lt;td&gt;Dynamic array&lt;/td&gt;
&lt;td&gt;Fast lookup&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LinkedList&lt;/td&gt;
&lt;td&gt;Doubly linked list&lt;/td&gt;
&lt;td&gt;Frequent addition/removal&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Vector&lt;/td&gt;
&lt;td&gt;Dynamic array (synchronized)&lt;/td&gt;
&lt;td&gt;Legacy systems&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CopyOnWriteArrayList&lt;/td&gt;
&lt;td&gt;Dynamic array clone&lt;/td&gt;
&lt;td&gt;Concurrent reads&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>algorithms</category>
      <category>java</category>
      <category>performance</category>
    </item>
    <item>
      <title>Quick Recap: Design Patterns in Java (Real Examples)</title>
      <dc:creator>shantanu mahakale</dc:creator>
      <pubDate>Fri, 21 Nov 2025 15:56:52 +0000</pubDate>
      <link>https://forem.com/codeintention/quick-recap-design-patterns-in-java-real-examples-4p75</link>
      <guid>https://forem.com/codeintention/quick-recap-design-patterns-in-java-real-examples-4p75</guid>
      <description>&lt;p&gt;Design patterns provide reusable solutions to common software problems. Here’s a concise recap with &lt;strong&gt;actual Java / Spring framework examples&lt;/strong&gt; — not generic ones.&lt;/p&gt;




&lt;h2&gt;
  
  
  Creational Patterns
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Singleton&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Ensures only one instance exists.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/ Real Example:
Calendar calendar = Calendar.getInstance();
Runtime runtime = Runtime.getRuntime();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Used in logging, DB connections, cache managers.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Factory Method&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Creates objects without exposing logic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example: Java Collections
List&amp;lt;String&amp;gt; list = List.of("A", "B"); // Java 9 Factory
NumberFormat format = NumberFormat.getInstance();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring Example: &lt;code&gt;BeanFactory.getBean("beanName")&lt;/code&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Builder Pattern&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Best for creating complex objects with many fields.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example: StringBuilder
String result = new StringBuilder()
  .append("Hello ")
  .append("World")
  .toString();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also used in Lombok: &lt;code&gt;@Builder&lt;/code&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Prototype Pattern&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Create objects by cloning.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example: Object clone()
Employee cloned = (Employee) employee.clone();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Useful when object creation is costly.&lt;/p&gt;




&lt;h2&gt;
  
  
  Structural Patterns
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Adapter Pattern&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Converts one interface to another.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example: InputStreamReader adapts InputStream to Reader.
Reader reader = new InputStreamReader(inputStream);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Used when integrating legacy systems.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Decorator Pattern&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Adds functionality at runtime.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example: I/O Streams
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("file.txt"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also in Spring: &lt;code&gt;HandlerInterceptor&lt;/code&gt;, &lt;code&gt;Filter&lt;/code&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Facade Pattern&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Provides a simplified interface.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example: JDBC
Connection conn = DriverManager.getConnection(url);
// JDBC hides complex driver logic!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also: &lt;code&gt;HibernateTemplate&lt;/code&gt;, &lt;code&gt;RestTemplate&lt;/code&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Proxy Pattern&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Controls access to an object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example: Java Dynamic Proxy (used in Spring AOP)
Proxy.newProxyInstance(...)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Used for authentication, logging, lazy loading.&lt;/p&gt;




&lt;h2&gt;
  
  
  Behavioral Patterns
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Observer Pattern&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Notifies when state changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example: PropertyChangeListener (Java Beans)
button.addActionListener(...);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring Example: ApplicationEventPublisher&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Strategy Pattern&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Different algorithms, same interface.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example: Comparator
Collections.sort(list, (a, b) -&amp;gt; a.compareTo(b));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring: &lt;code&gt;AuthenticationStrategy&lt;/code&gt;, &lt;code&gt;RetryStrategy&lt;/code&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Template Method Pattern&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Defines skeleton → subclasses override steps.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example: HttpServlet.doGet() / doPost()
abstract class HttpServlet {
  protected void doGet() {}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring JDBC Template follows this pattern.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Command Pattern&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Encapsulates a request as an object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example: Runnable
ExecutorService.exec(new MyTask());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Used in scheduling, undo operations.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Iterator Pattern&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Sequential access without exposing structure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example:
Iterator&amp;lt;String&amp;gt; itr = list.iterator();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Summary Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pattern&lt;/th&gt;
&lt;th&gt;Real Java Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Singleton&lt;/td&gt;
&lt;td&gt;Runtime.getRuntime()&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Factory&lt;/td&gt;
&lt;td&gt;NumberFormat.getInstance()&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Builder&lt;/td&gt;
&lt;td&gt;StringBuilder&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Adapter&lt;/td&gt;
&lt;td&gt;InputStreamReader&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Decorator&lt;/td&gt;
&lt;td&gt;BufferedInputStream&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Facade&lt;/td&gt;
&lt;td&gt;JDBC (DriverManager)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Proxy&lt;/td&gt;
&lt;td&gt;Spring AOP / Dynamic Proxy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Observer&lt;/td&gt;
&lt;td&gt;ActionListener&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Strategy&lt;/td&gt;
&lt;td&gt;Comparator&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Template Method&lt;/td&gt;
&lt;td&gt;HttpServlet&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Command&lt;/td&gt;
&lt;td&gt;Runnable&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>architecture</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>java</category>
    </item>
    <item>
      <title>Quick Recap: Elasticsearch &amp; Lucene</title>
      <dc:creator>shantanu mahakale</dc:creator>
      <pubDate>Fri, 21 Nov 2025 15:17:53 +0000</pubDate>
      <link>https://forem.com/codeintention/quick-recap-elasticsearch-lucene-3lcg</link>
      <guid>https://forem.com/codeintention/quick-recap-elasticsearch-lucene-3lcg</guid>
      <description>&lt;p&gt;Elasticsearch is a &lt;strong&gt;distributed search and analytics engine&lt;/strong&gt;, built on top of &lt;strong&gt;Apache Lucene&lt;/strong&gt;. It is commonly used for &lt;strong&gt;full-text search&lt;/strong&gt;, &lt;strong&gt;log analytics&lt;/strong&gt;, &lt;strong&gt;metrics&lt;/strong&gt;, and &lt;strong&gt;real-time data exploration&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Lucene is the &lt;strong&gt;core indexing + search library&lt;/strong&gt; behind Elasticsearch — Elasticsearch is Lucene made easy + scalable.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Lucene?
&lt;/h2&gt;

&lt;p&gt;Lucene is a &lt;strong&gt;low-level search/indexing library&lt;/strong&gt; written in Java.&lt;br&gt;&lt;br&gt;
It provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Full-text search&lt;/li&gt;
&lt;li&gt;Tokenization &amp;amp; analyzers&lt;/li&gt;
&lt;li&gt;Inverted index mechanism&lt;/li&gt;
&lt;li&gt;Scoring &amp;amp; relevance ranking&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Lucene is NOT a server or database — it’s just a library.&lt;/p&gt;


&lt;h2&gt;
  
  
  What is Elasticsearch?
&lt;/h2&gt;

&lt;p&gt;Elasticsearch is an &lt;strong&gt;open-source distributed search engine&lt;/strong&gt; built on top of Lucene with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;REST API-based querying&lt;/li&gt;
&lt;li&gt;Distributed storage (shards &amp;amp; replicas)&lt;/li&gt;
&lt;li&gt;Full-text search + filtering + aggregations&lt;/li&gt;
&lt;li&gt;Scalable architecture for big data
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client → Elasticsearch → Lucene Index → Results
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Key Concepts in Elasticsearch
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Index&lt;/td&gt;
&lt;td&gt;Like a database&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Document&lt;/td&gt;
&lt;td&gt;JSON object (like a row)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Field&lt;/td&gt;
&lt;td&gt;Key-value inside document&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Shard&lt;/td&gt;
&lt;td&gt;Partition of an index&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Replica&lt;/td&gt;
&lt;td&gt;Copy of shard (for fault tolerance)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h2&gt;
  
  
  Lucene: Inverted Index (Core Idea)
&lt;/h2&gt;

&lt;p&gt;Lucene converts text into tokens and builds a &lt;strong&gt;reverse lookup table&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Text: "Java is great. Java streams are powerful."
Inverted Index:
"java" → [doc1, doc1]
"is" → [doc1]
"streams" → [doc1]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Faster to search “java” instead of scanning entire text.&lt;/p&gt;




&lt;h2&gt;
  
  
  Elasticsearch Search Flow
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Text → Analyzer → Tokens
&lt;/li&gt;
&lt;li&gt;Tokens stored in inverted index (Lucene)
&lt;/li&gt;
&lt;li&gt;Query converted into tokens
&lt;/li&gt;
&lt;li&gt;Relevant documents matched + scored
&lt;/li&gt;
&lt;li&gt;Sorted + returned as results&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Example Query (Search API)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET users/_search
{
  "query": {
    "match": { "name": "shantanu" }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Full Text Search vs Exact Match
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Search Type&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;When Used&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;match&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;"java developer"&lt;/td&gt;
&lt;td&gt;Full-text search&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;term&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;"400"&lt;/td&gt;
&lt;td&gt;Exact value match&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;wildcard&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;"dev*"&lt;/td&gt;
&lt;td&gt;Pattern-based search&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Aggregations (Analytics Support)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET logs/_search
{
  "aggs": {
    "errors_by_status": {
      "terms": { "field": "status_code" }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Works like SQL &lt;code&gt;GROUP BY&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  When to Use Elasticsearch?
&lt;/h2&gt;

&lt;p&gt;✔ Full-text search&lt;br&gt;&lt;br&gt;
✔ Log analytics (ELK stack)&lt;br&gt;&lt;br&gt;
✔ Real-time dashboards&lt;br&gt;&lt;br&gt;
✔ Autocomplete &amp;amp; suggestions&lt;br&gt;&lt;br&gt;
✔ Distributed scalability  &lt;/p&gt;

&lt;p&gt;Examples: eCommerce search, StackOverflow search, Kibana dashboards, Log analysis.&lt;/p&gt;




&lt;h2&gt;
  
  
  When NOT to Use Elasticsearch?
&lt;/h2&gt;

&lt;p&gt;❌ As a replacement for a relational DB&lt;br&gt;&lt;br&gt;
❌ For complex transactions&lt;br&gt;&lt;br&gt;
❌ For small datasets&lt;br&gt;&lt;br&gt;
❌ When ACID guarantees are critical  &lt;/p&gt;

&lt;p&gt;Use PostgreSQL/MySQL instead.&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Elasticsearch&lt;/th&gt;
&lt;th&gt;Lucene&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Type&lt;/td&gt;
&lt;td&gt;Distributed search engine&lt;/td&gt;
&lt;td&gt;Search library&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Interface&lt;/td&gt;
&lt;td&gt;REST API&lt;/td&gt;
&lt;td&gt;Java library&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Storage&lt;/td&gt;
&lt;td&gt;JSON documents&lt;/td&gt;
&lt;td&gt;Inverted index&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scale&lt;/td&gt;
&lt;td&gt;Distributed (clusters)&lt;/td&gt;
&lt;td&gt;Single machine&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Use Case&lt;/td&gt;
&lt;td&gt;Search &amp;amp; analytics&lt;/td&gt;
&lt;td&gt;Core indexing logic&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>distributedsystems</category>
      <category>backend</category>
      <category>database</category>
      <category>java</category>
    </item>
    <item>
      <title>Quick Recap: JPA (Java Persistence API)</title>
      <dc:creator>shantanu mahakale</dc:creator>
      <pubDate>Fri, 21 Nov 2025 15:13:46 +0000</pubDate>
      <link>https://forem.com/codeintention/quick-recap-jpa-java-persistence-api-cjg</link>
      <guid>https://forem.com/codeintention/quick-recap-jpa-java-persistence-api-cjg</guid>
      <description>&lt;p&gt;JPA is a standard in Java for &lt;strong&gt;object-relational mapping (ORM)&lt;/strong&gt; — it allows developers to map Java objects to database tables and perform CRUD operations without writing SQL manually.&lt;/p&gt;

&lt;p&gt;It is mainly used with &lt;strong&gt;relational databases (e.g., Oracle, PostgreSQL, MySQL)&lt;/strong&gt; and can also be used with &lt;strong&gt;MongoDB&lt;/strong&gt; using Spring Data.&lt;/p&gt;




&lt;h2&gt;
  
  
  Core Concepts in JPA
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Entity&lt;/strong&gt; → Represents a table row&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Entity Manager&lt;/strong&gt; → Handles DB operations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Persistence Context&lt;/strong&gt; → Cache/session for entities&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Repository&lt;/strong&gt; → Interface for CRUD queries&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transaction&lt;/strong&gt; → Ensures atomic operations&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Mapping Entities (Oracle Example)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false)
private String name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  JPA Annotations Cheat Sheet
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Annotation&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;@Entity&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Marks a class as a DB entity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;@Table&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Maps to DB table&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;@Id&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Primary key&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;@GeneratedValue&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Auto-increment strategy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;@Column&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Map field to column&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;@OneToMany&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Relationship mapping&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;@ManyToOne&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Foreign key relation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;@Transactional&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Wrap method in transaction&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Spring Data JPA Repository (Oracle Example)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface UserRepo extends JpaRepository&amp;lt;User, Long&amp;gt; {
List&amp;lt;User&amp;gt; findByName(String name);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 No SQL needed — method names generate queries.&lt;/p&gt;




&lt;h2&gt;
  
  
  Transactions (Relational DBs)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Transactional
public void saveUser(User user) {
repo.save(user);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Guarantees ACID behavior with Oracle/Postgres/MySQL.&lt;/p&gt;




&lt;h2&gt;
  
  
  JPA with MongoDB (Spring Data)
&lt;/h2&gt;

&lt;p&gt;MongoDB is &lt;strong&gt;NoSQL&lt;/strong&gt;, so traditional JPA is not used. Instead, we use &lt;strong&gt;Spring Data MongoDB&lt;/strong&gt;, which follows a similar repository pattern.&lt;/p&gt;

&lt;h3&gt;
  
  
  Entity for MongoDB:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Document(collection = "users")
public class User {
@Id
private String id;
private String name;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Repository:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface UserRepo extends MongoRepository&amp;lt;User, String&amp;gt; {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Still works like JPA, but &lt;strong&gt;no joins, no relationships, no transactions&lt;/strong&gt; across collections.&lt;/p&gt;




&lt;h2&gt;
  
  
  JPA vs MongoDB – Key Differences
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;JPA (Oracle)&lt;/th&gt;
&lt;th&gt;MongoDB&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Database Type&lt;/td&gt;
&lt;td&gt;Relational (SQL)&lt;/td&gt;
&lt;td&gt;NoSQL (Document)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Schema&lt;/td&gt;
&lt;td&gt;Fixed&lt;/td&gt;
&lt;td&gt;Flexible&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Transactions&lt;/td&gt;
&lt;td&gt;ACID&lt;/td&gt;
&lt;td&gt;Limited (single doc)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Joins&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No (embed instead)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Querying&lt;/td&gt;
&lt;td&gt;JPQL / Criteria&lt;/td&gt;
&lt;td&gt;Mongo Query DSL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Repository&lt;/td&gt;
&lt;td&gt;JpaRepository&lt;/td&gt;
&lt;td&gt;MongoRepository&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  When to Use JPA (Relational)
&lt;/h2&gt;

&lt;p&gt;✔ Complex relationships&lt;br&gt;&lt;br&gt;
✔ Transactions required&lt;br&gt;&lt;br&gt;
✔ Strong schema &amp;amp; constraints&lt;br&gt;&lt;br&gt;
✔ Enterprise applications  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt; Oracle, PostgreSQL, MySQL&lt;/p&gt;




&lt;h2&gt;
  
  
  When to Use MongoDB (NoSQL)
&lt;/h2&gt;

&lt;p&gt;✔ Flexible schema&lt;br&gt;&lt;br&gt;
✔ High scalability&lt;br&gt;&lt;br&gt;
✔ JSON-style data&lt;br&gt;&lt;br&gt;
✔ Fast reads/writes&lt;br&gt;&lt;br&gt;
✔ No complex joins needed  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt; Logs, user profiles, IoT data, analytics&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Use Case&lt;/th&gt;
&lt;th&gt;Recommended&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Banking / Finance&lt;/td&gt;
&lt;td&gt;JPA with Oracle&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Microservices&lt;/td&gt;
&lt;td&gt;JPA + PostgreSQL OR MongoDB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;IoT / Analytics&lt;/td&gt;
&lt;td&gt;MongoDB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;High reads/writes&lt;/td&gt;
&lt;td&gt;MongoDB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Strict schema&lt;/td&gt;
&lt;td&gt;JPA&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>backend</category>
      <category>database</category>
      <category>java</category>
    </item>
    <item>
      <title>Quick Recap: Java Threads</title>
      <dc:creator>shantanu mahakale</dc:creator>
      <pubDate>Fri, 21 Nov 2025 15:09:53 +0000</pubDate>
      <link>https://forem.com/codeintention/quick-recap-java-threads-13c9</link>
      <guid>https://forem.com/codeintention/quick-recap-java-threads-13c9</guid>
      <description>&lt;p&gt;Java supports multithreading to perform multiple tasks concurrently. Threads allow efficient use of CPU cores, improve performance, and enable responsive applications. They are a core part of Java concurrency.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is a Thread?
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;thread&lt;/strong&gt; is a lightweight unit of execution within a process.&lt;br&gt;&lt;br&gt;
A Java application &lt;strong&gt;starts with a single main thread&lt;/strong&gt; but can spawn multiple threads to run tasks in parallel.&lt;/p&gt;


&lt;h2&gt;
  
  
  Ways to Create Threads
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Extending &lt;code&gt;Thread&lt;/code&gt; class
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyThread extends Thread {
public void run() {
System.out.println("Thread running");
}
}
new MyThread().start();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  2. Implementing &lt;code&gt;Runnable&lt;/code&gt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyTask implements Runnable {
public void run() {
System.out.println("Task executed");
}
}
new Thread(new MyTask()).start();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  3. Using Lambda (Java 8+)
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;new Thread(() -&amp;gt; System.out.println("Lambda thread")).start();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  4. Using &lt;code&gt;ExecutorService&lt;/code&gt; (Preferred)
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ExecutorService exec = Executors.newFixedThreadPool(5);
exec.submit(() -&amp;gt; System.out.println("Task"));
exec.shutdown();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Thread States
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;State&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;NEW&lt;/td&gt;
&lt;td&gt;Created but not started&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RUNNABLE&lt;/td&gt;
&lt;td&gt;Running or ready to run&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BLOCKED&lt;/td&gt;
&lt;td&gt;Waiting for monitor lock&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WAITING&lt;/td&gt;
&lt;td&gt;Waiting indefinitely&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TIMED_WAITING&lt;/td&gt;
&lt;td&gt;Waiting with timeout&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TERMINATED&lt;/td&gt;
&lt;td&gt;Finished&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h2&gt;
  
  
  Thread Lifecycle
&lt;/h2&gt;

&lt;p&gt;NEW → RUNNABLE → WAITING/BLOCKED → RUNNABLE → TERMINATED&lt;/p&gt;


&lt;h2&gt;
  
  
  Common Thread Methods
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;start()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Starts thread&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;run()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Code executed by thread&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;sleep(ms)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Pause thread&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;join()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Wait for thread to finish&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;yield()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Hint to switch threads&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;interrupt()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Interrupt thread&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h2&gt;
  
  
  Synchronization
&lt;/h2&gt;

&lt;p&gt;Used to prevent race conditions when multiple threads access shared resources.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;synchronized void increment() {
count++;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or using intrinsic locks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;synchronized(obj) {
// critical section
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Deadlock
&lt;/h2&gt;

&lt;p&gt;Occurs when two threads wait for each other’s resources — both get stuck forever.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Thread A has Lock1 → waiting for Lock2
Thread B has Lock2 → waiting for Lock1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Avoid by always acquiring locks in the same order.&lt;/p&gt;




&lt;h2&gt;
  
  
  Thread Pool (Executor Framework)
&lt;/h2&gt;

&lt;p&gt;Better than creating threads manually.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ExecutorService pool = Executors.newFixedThreadPool(10);
pool.submit(task);
pool.shutdown();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reuses threads&lt;/li&gt;
&lt;li&gt;Improves performance&lt;/li&gt;
&lt;li&gt;Manages queue &amp;amp; scheduling&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Future &amp;amp; Callable (Return Values from Threads)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Callable&amp;lt;Integer&amp;gt; task = () -&amp;gt; 10 * 2;
Future&amp;lt;Integer&amp;gt; result = executor.submit(task);
System.out.println(result.get()); // 20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Virtual Threads (Java 19+ / 21)
&lt;/h2&gt;

&lt;p&gt;Lightweight threads — thousands can be created with minimal overhead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Thread.startVirtualThread(() -&amp;gt; {
// task goes here
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Game changer for concurrency &amp;amp; high-throughput apps.&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Thread&lt;/td&gt;
&lt;td&gt;Unit of execution&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Runnable&lt;/td&gt;
&lt;td&gt;Task without return&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Callable&lt;/td&gt;
&lt;td&gt;Task with return&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ExecutorService&lt;/td&gt;
&lt;td&gt;Manages thread pool&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;synchronized&lt;/td&gt;
&lt;td&gt;Prevents race conditions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Future&lt;/td&gt;
&lt;td&gt;Get result of async task&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Virtual Thread&lt;/td&gt;
&lt;td&gt;Lightweight concurrency&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>beginners</category>
      <category>java</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Quick Recap: Spring Boot Versions</title>
      <dc:creator>shantanu mahakale</dc:creator>
      <pubDate>Fri, 21 Nov 2025 14:48:37 +0000</pubDate>
      <link>https://forem.com/codeintention/quick-recap-spring-boot-versions-54l2</link>
      <guid>https://forem.com/codeintention/quick-recap-spring-boot-versions-54l2</guid>
      <description>&lt;p&gt;Spring Boot simplifies Java backend development by providing &lt;strong&gt;auto-configuration, embedded servers, production-ready features, and rapid development support&lt;/strong&gt;. Here's a version-wise recap focusing on features that actually impact coding experience.&lt;/p&gt;




&lt;h2&gt;
  
  
  Spring Boot 1.x (2014)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;First release of Spring Boot&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Embedded Tomcat/Jetty&lt;/strong&gt; — no external server needed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Auto-configuration&lt;/strong&gt; (core feature introduced)&lt;/li&gt;
&lt;li&gt;Spring Boot Starter dependencies (&lt;code&gt;spring-boot-starter-web&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;application.properties&lt;/code&gt; for configuration
👉 Foundation for rapid development in Spring.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Spring Boot 2.x (Major Evolution)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Spring Boot 2.0&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Based on &lt;strong&gt;Spring Framework 5&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Reactive programming with &lt;strong&gt;WebFlux&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Java 8+ required&lt;/li&gt;
&lt;li&gt;Actuator redesigned with &lt;code&gt;/actuator/*&lt;/code&gt; endpoints&lt;/li&gt;
&lt;li&gt;Gradle plugin improved
👉 Start of reactive and microservice-ready Spring.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Spring Boot 2.1&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Better Kubernetes support&lt;/li&gt;
&lt;li&gt;Enhanced Actuator metrics (Micrometer)&lt;/li&gt;
&lt;li&gt;Lazy initialization support&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Spring Boot 2.2&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Java 11 support&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Reactive health indicators&lt;/li&gt;
&lt;li&gt;Startup time optimization&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Spring Boot 2.3&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Docker &amp;amp; Container support&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Better Graceful Shutdown&lt;/li&gt;
&lt;li&gt;Improved tests&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Spring Boot 2.4&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;New config loading system&lt;/li&gt;
&lt;li&gt;Better support for external configs
&lt;/li&gt;
&lt;li&gt;Removed &lt;code&gt;bootstrap.properties&lt;/code&gt; for Spring Cloud&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Spring Boot 2.5&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Improved embedded server performance&lt;/li&gt;
&lt;li&gt;Layered JARs for Docker image optimization&lt;/li&gt;
&lt;li&gt;Easier startup tracking and metrics&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Spring Boot 2.6 – 2.7&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Deprecation of older patterns (MVC fallback)&lt;/li&gt;
&lt;li&gt;Spring Native &amp;amp; AOT (Ahead-of-Time compilation)&lt;/li&gt;
&lt;li&gt;Hints of moving toward Spring Boot 3 standards&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Spring Boot 2.x focused heavily on microservices, Docker, and reactive architectures.&lt;/p&gt;




&lt;h2&gt;
  
  
  Spring Boot 3.x (Current Stable Major)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Java 17 required (minimum)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Jakarta namespace migration (&lt;code&gt;javax&lt;/code&gt; → &lt;code&gt;jakarta&lt;/code&gt;)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Built on &lt;strong&gt;Spring Framework 6&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;AOT &amp;amp; GraalVM Native Image support&lt;/li&gt;
&lt;li&gt;Better performance &amp;amp; memory footprint&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@HttpExchange&lt;/code&gt; &amp;amp; declarative HTTP clients&lt;/li&gt;
&lt;li&gt;Enhanced observability (Micrometer + Actuator)
👉 Major breaking change due to Jakarta migration.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Summary Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;Key Highlights&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1.x&lt;/td&gt;
&lt;td&gt;Embedded server, auto-config&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2.0&lt;/td&gt;
&lt;td&gt;WebFlux, Java 8+, Actuator redesign&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2.3&lt;/td&gt;
&lt;td&gt;Docker support, health checks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2.4&lt;/td&gt;
&lt;td&gt;New config loading&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2.6–2.7&lt;/td&gt;
&lt;td&gt;Native image hints, AOT prep&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3.x&lt;/td&gt;
&lt;td&gt;Jakarta migration, Java 17+, HTTP client&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  What Should Developers Know Today?
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Area&lt;/th&gt;
&lt;th&gt;Recommendation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;New projects&lt;/td&gt;
&lt;td&gt;Use Spring Boot 3.x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Native/GraalVM&lt;/td&gt;
&lt;td&gt;Use Spring Boot 3.x with AOT&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Legacy upgrades&lt;/td&gt;
&lt;td&gt;Move from 2.x → 3.x (Jakarta migration)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance-focused apps&lt;/td&gt;
&lt;td&gt;Watch for Spring Boot 4 &amp;amp; Loom&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>backend</category>
      <category>java</category>
      <category>springboot</category>
    </item>
    <item>
      <title>Quick Recap: Angular Versions</title>
      <dc:creator>shantanu mahakale</dc:creator>
      <pubDate>Fri, 21 Nov 2025 14:42:08 +0000</pubDate>
      <link>https://forem.com/codeintention/quick-recap-angular-versions-1704</link>
      <guid>https://forem.com/codeintention/quick-recap-angular-versions-1704</guid>
      <description>&lt;p&gt;Angular continues to evolve with a strong focus on performance, developer productivity, and reduced bundle size. Here's a version-wise recap from Angular 8 onwards — covering the most relevant features for developers.&lt;/p&gt;




&lt;h2&gt;
  
  
  Angular 8
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Ivy Engine (Preview)&lt;/strong&gt; – New rendering engine&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Differential Loading&lt;/strong&gt; – Generates separate bundles for modern &amp;amp; legacy browsers&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lazy Loading with Dynamic Imports&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;loadChildren: () =&amp;gt; import('./module').then(m =&amp;gt; m.Module)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Web Worker Support&lt;/strong&gt; (&lt;code&gt;ng generate web-worker&lt;/code&gt;)
👉 Foundation for future major upgrades.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Angular 9
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Ivy Rendering Engine becomes default&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Smaller bundle sizes&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Faster compilation&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Better debugging &amp;amp; type checking&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improved Test Performance&lt;/strong&gt;
👉 A major change — Ivy officially replaces View Engine.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Angular 10
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Smaller, cleaner package size&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optional chaining &amp;amp; nullish coalescing (TS 3.9)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user?.address?.city
value ?? 'default'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stricter project setup&lt;/strong&gt; (&lt;code&gt;ng new app --strict&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New Date Range Picker in Angular Material&lt;/strong&gt;
👉 Focus on quality and type safety.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Angular 11
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Faster builds &amp;amp; HMR (Hot Module Replacement)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng serve --hmr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Automatic font optimization&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Updated ESLint instead of TSLint&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improved logging &amp;amp; debugging&lt;/strong&gt;
👉 Better DX (Developer Experience).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Angular 12
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Removed support for View Engine&lt;/strong&gt; → Ivy-only&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Strict mode by default&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Webpack 5 support&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nullish Coalescing in templates&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{ user?.name ?? 'Guest' }}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Push towards modern tooling.&lt;/p&gt;




&lt;h2&gt;
  
  
  Angular 13
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;No more &lt;code&gt;ngcc&lt;/code&gt; (Angular Compatibility Compiler)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ESBuild for faster builds&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Simplified Angular Package Format&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Component API improvements&lt;/strong&gt;
👉 Cleaned up legacy dependencies — faster builds.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Angular 14
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Standalone Components (major change!)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Component({
standalone: true,
template: &amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;
})
export class HelloComponent {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Typed Reactive Forms&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Better CLI autocompletion&lt;/strong&gt;
👉 Can build apps without NgModule — huge shift.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Angular 15
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Standalone APIs officially stable&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Functional route guards &amp;amp; resolvers&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const authGuard: CanActivateFn = (route, state) =&amp;gt; true;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Improved performance&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Directive composition API&lt;/strong&gt;
👉 Encourages modular and cleaner applications.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Angular 16
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Signals (reactivity model, preview)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const count = signal(0);
count.set(5);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Server-side rendering improvements&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Better hydration&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Faster compilation&lt;/strong&gt;
👉 Signals simplify state management — major future shift.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Angular 17 (Latest Major)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Full support for Signals (stable)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New Control Flow Syntax&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@if(condition) { ... }
@for(item of items) { ... }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Better SSR &amp;amp; hydration&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Improved routing with deferrable views&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Standalone apps now the default&lt;/strong&gt;
👉 Angular becomes lighter, more React-like.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Summary Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;Key Features&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Angular 8&lt;/td&gt;
&lt;td&gt;Ivy (preview), differential loading&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Angular 9&lt;/td&gt;
&lt;td&gt;Ivy default, faster builds&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Angular 10&lt;/td&gt;
&lt;td&gt;Optional chaining, strict mode&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Angular 11&lt;/td&gt;
&lt;td&gt;HMR, ESLint, font optimization&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Angular 12&lt;/td&gt;
&lt;td&gt;Ivy-only, Webpack 5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Angular 13&lt;/td&gt;
&lt;td&gt;ESBuild, removed ngcc&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Angular 14&lt;/td&gt;
&lt;td&gt;Standalone components, typed forms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Angular 15&lt;/td&gt;
&lt;td&gt;Functional guards, modular architecture&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Angular 16&lt;/td&gt;
&lt;td&gt;Signals (preview), SSR upgrades&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Angular 17&lt;/td&gt;
&lt;td&gt;Signals stable, new control flow&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>frontend</category>
      <category>angular</category>
      <category>typescript</category>
      <category>performance</category>
    </item>
    <item>
      <title>Quick Recap: Java Versions</title>
      <dc:creator>shantanu mahakale</dc:creator>
      <pubDate>Fri, 21 Nov 2025 14:30:00 +0000</pubDate>
      <link>https://forem.com/codeintention/quick-recap-java-versions-52k6</link>
      <guid>https://forem.com/codeintention/quick-recap-java-versions-52k6</guid>
      <description>&lt;p&gt;Here’s a practical summary of the most useful Java features added from &lt;strong&gt;Java 8 to recent versions&lt;/strong&gt;, focusing on what developers actually use in daily coding.&lt;/p&gt;




&lt;h2&gt;
  
  
  Java 8 (Most Impactful Release)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lambda Expressions&lt;/strong&gt; → Functional programming
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stream API&lt;/strong&gt; → Declarative data processing
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Functional Interfaces&lt;/strong&gt; (&lt;code&gt;@FunctionalInterface&lt;/code&gt;)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Default &amp;amp; Static Methods in Interfaces&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optional Class&lt;/strong&gt; – Avoid null checks
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Date/Time API (java.time)&lt;/strong&gt; – Replaces old Date/Calendar
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Method References&lt;/strong&gt; (&lt;code&gt;::&lt;/code&gt; operator)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Most popular version in production even today.&lt;/p&gt;




&lt;h2&gt;
  
  
  Java 9
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Modules (JPMS)&lt;/strong&gt; – &lt;code&gt;module-info.java&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JShell&lt;/strong&gt; – REPL for testing code quickly
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Factory Methods for Collections&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List.of(1, 2, 3);
Set.of("A", "B");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Improved Stream API: &lt;code&gt;takeWhile()&lt;/code&gt;, &lt;code&gt;dropWhile()&lt;/code&gt;, &lt;code&gt;iterate()&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Java 10
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Local Variable Type Inference (&lt;code&gt;var&lt;/code&gt;)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var name = "Shantanu";
var list = new ArrayList&amp;lt;String&amp;gt;();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Not like JavaScript – only for local vars.&lt;/p&gt;




&lt;h2&gt;
  
  
  Java 11 (LTS Release)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;HTTP Client API (modern replacement for HttpURLConnection)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HttpClient client = HttpClient.newHttpClient();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;String Methods&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"hello".isBlank();
"line1\nline2".lines();
"test".repeat(3);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;var&lt;/code&gt; allowed in lambda params&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Very stable &amp;amp; widely used enterprise version after Java 8.&lt;/p&gt;




&lt;h2&gt;
  
  
  Java 14
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Switch Expressions (Enhanced)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int result = switch(x) {
case 1 -&amp;gt; 100;
case 2 -&amp;gt; 200;
default -&amp;gt; 0;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Records (Preview)&lt;/strong&gt; – Lightweight data classes
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;NullPointerException with details&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Java 15
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Text Blocks (Multiline Strings)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String json = """
{
"name": "John"
}
""";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Clean JSON, SQL, HTML formatting.&lt;/p&gt;




&lt;h2&gt;
  
  
  Java 16
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Records (Final Release)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public record User(String name, int age) {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pattern Matching for instanceof&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (obj instanceof String s) {
System.out.println(s.toUpperCase());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Java 17 (LTS)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sealed Classes&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public sealed class Animal permits Dog, Cat {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Switch pattern matching (Preview)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Stronger encapsulation &amp;amp; security updates&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Current long-term support (LTS) version used widely in new projects.&lt;/p&gt;




&lt;h2&gt;
  
  
  Java 19 / 20 (Preview Features)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Virtual Threads (Project Loom)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Thread.startVirtualThread(() -&amp;gt; {
// lightweight threads
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Massive performance boost for high-concurrency apps.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Structured Concurrency&lt;/strong&gt;
Better control over multi-threading workflows.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Java 21 (LTS – Most Recent Major)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Virtual Threads (Final)&lt;/strong&gt; – Game changer for performance
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;String Templates (Preview)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;STR."Hello, ${name}!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sequenced Collections&lt;/strong&gt; – Ordered access to elements
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Record Patterns&lt;/strong&gt; – Destructuring syntax
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pattern Matching Enhancements&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Consider upgrading if starting a new application.&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;Key Features&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Java 8&lt;/td&gt;
&lt;td&gt;Lambdas, Streams, Optional, Date API&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Java 9&lt;/td&gt;
&lt;td&gt;Modules, JShell&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Java 10&lt;/td&gt;
&lt;td&gt;var keyword&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Java 11&lt;/td&gt;
&lt;td&gt;HTTP Client API, String methods&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Java 14&lt;/td&gt;
&lt;td&gt;Switch expressions, Records (preview)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Java 15&lt;/td&gt;
&lt;td&gt;Text Blocks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Java 16&lt;/td&gt;
&lt;td&gt;Records, Pattern Matching&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Java 17&lt;/td&gt;
&lt;td&gt;LTS, Sealed Classes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Java 19/20&lt;/td&gt;
&lt;td&gt;Virtual Threads (preview)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Java 21&lt;/td&gt;
&lt;td&gt;Virtual Threads (final), String templates&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Quick Recap: Java Streams</title>
      <dc:creator>shantanu mahakale</dc:creator>
      <pubDate>Fri, 21 Nov 2025 14:20:18 +0000</pubDate>
      <link>https://forem.com/codeintention/quick-recap-java-streams-53d9</link>
      <guid>https://forem.com/codeintention/quick-recap-java-streams-53d9</guid>
      <description>&lt;p&gt;Java Streams (introduced in Java 8) provide a &lt;strong&gt;functional, declarative way&lt;/strong&gt; to process collections. They allow writing cleaner and more readable code using pipelines like:&lt;br&gt;&lt;br&gt;
&lt;strong&gt;source → intermediate operations → terminal operation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Streams do &lt;strong&gt;not modify original data&lt;/strong&gt; — they create a new result.&lt;/p&gt;




&lt;h2&gt;
  
  
  Key Features of Streams
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Supports &lt;strong&gt;functional programming&lt;/strong&gt; style&lt;/li&gt;
&lt;li&gt;Works with &lt;strong&gt;Collections, Arrays, I/O data&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lazy evaluation&lt;/strong&gt; (executed only when needed)&lt;/li&gt;
&lt;li&gt;Supports &lt;strong&gt;parallel processing&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No modification&lt;/strong&gt; of original data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Readable pipelines&lt;/strong&gt; for data processing&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Stream Pipeline
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;collection.stream()
.filter(...)
.map(...)
.sorted(...)
.collect(...);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Source&lt;/strong&gt; → &lt;code&gt;stream()&lt;/code&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Intermediate Ops&lt;/strong&gt; → &lt;code&gt;filter()&lt;/code&gt;, &lt;code&gt;map()&lt;/code&gt;, &lt;code&gt;sorted()&lt;/code&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Terminal Ops&lt;/strong&gt; → &lt;code&gt;collect()&lt;/code&gt;, &lt;code&gt;forEach()&lt;/code&gt;, &lt;code&gt;reduce()&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Common Intermediate Operations
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Keep only matching elements&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;map()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Transform elements&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;sorted()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Sort elements&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;distinct()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Remove duplicates&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;limit()&lt;/code&gt; / &lt;code&gt;skip()&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Pagination-like usage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;peek()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Debug/log values&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Common Terminal Operations
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;collect()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Convert to List/Set/Map&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;forEach()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Loop through items&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;count()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Count elements&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;min()&lt;/code&gt; / &lt;code&gt;max()&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Find smallest/largest&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;reduce()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Aggregate into a single result&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;toArray()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Convert to array&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Filter &amp;amp; Collect
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;Integer&amp;gt; evens = nums.stream()
.filter(n -&amp;gt; n % 2 == 0)
.collect(Collectors.toList());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Map (Transform)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;Integer&amp;gt; doubled = nums.stream()
.map(n -&amp;gt; n * 2)
.collect(Collectors.toList());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Reduce (Sum)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int sum = nums.stream()
.reduce(0, Integer::sum);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Sorting
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;String&amp;gt; sorted = names.stream()
.sorted()
.collect(Collectors.toList());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Parallel Streams
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list.parallelStream()
.forEach(System.out::println);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Used for large data processing&lt;br&gt;&lt;br&gt;
⚠️ Avoid for small collections (thread overhead)&lt;br&gt;&lt;br&gt;
⚠️ Be careful with shared mutable data&lt;/p&gt;




&lt;h2&gt;
  
  
  When to Use Java Streams?
&lt;/h2&gt;

&lt;p&gt;✔ Cleaner &amp;amp; readable code&lt;br&gt;&lt;br&gt;
✔ Complex data transformation&lt;br&gt;&lt;br&gt;
✔ Large dataset processing&lt;br&gt;&lt;br&gt;
✔ Aggregations and filtering&lt;br&gt;&lt;br&gt;
✔ Multi-core parallel processing (parallelStream)&lt;/p&gt;

&lt;p&gt;❌ Avoid when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Debugging is complex&lt;/li&gt;
&lt;li&gt;Performance is critical with small data&lt;/li&gt;
&lt;li&gt;Code readability becomes worse&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Summary Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;Key Idea&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Stream&lt;/td&gt;
&lt;td&gt;Flow of data without storage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Intermediate Op&lt;/td&gt;
&lt;td&gt;Returns another Stream&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Terminal Op&lt;/td&gt;
&lt;td&gt;Produces final result&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Immutable&lt;/td&gt;
&lt;td&gt;Original data not changed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lazy Eval&lt;/td&gt;
&lt;td&gt;Runs only when needed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Functional&lt;/td&gt;
&lt;td&gt;Uses lambda expressions&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
    </item>
    <item>
      <title>Quick Recap: System Design Components</title>
      <dc:creator>shantanu mahakale</dc:creator>
      <pubDate>Fri, 21 Nov 2025 14:13:49 +0000</pubDate>
      <link>https://forem.com/codeintention/quick-recap-system-design-components-3jf3</link>
      <guid>https://forem.com/codeintention/quick-recap-system-design-components-3jf3</guid>
      <description>&lt;p&gt;In modern distributed systems, different components work together to handle requests, scale applications, and ensure reliability. Here’s a quick summary of commonly used components with real-world tools for each.&lt;/p&gt;




&lt;h2&gt;
  
  
  API Gateway
&lt;/h2&gt;

&lt;p&gt;Acts as the &lt;strong&gt;single entry point&lt;/strong&gt; for all client requests. It routes requests to internal services, handles authentication, rate limiting, caching, and request validation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tools/Examples:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Kong
&lt;/li&gt;
&lt;li&gt;Amazon API Gateway
&lt;/li&gt;
&lt;li&gt;Apigee (Google)
&lt;/li&gt;
&lt;li&gt;Nginx (can be configured as gateway)
&lt;/li&gt;
&lt;li&gt;Zuul (Netflix OSS)
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Best for microservices architecture to centralize all API traffic.&lt;/p&gt;




&lt;h2&gt;
  
  
  Reverse Proxy
&lt;/h2&gt;

&lt;p&gt;Sits between clients and backend servers. It forwards client requests to the appropriate server while hiding the server details. Can also handle caching, SSL termination, compression.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tools/Examples:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Nginx
&lt;/li&gt;
&lt;li&gt;Apache HTTP Server
&lt;/li&gt;
&lt;li&gt;HAProxy
&lt;/li&gt;
&lt;li&gt;Caddy
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Used to improve security and manage traffic flow to backend servers.&lt;/p&gt;




&lt;h2&gt;
  
  
  Load Balancer
&lt;/h2&gt;

&lt;p&gt;Distributes incoming traffic across multiple servers to prevent overload and ensure high availability. Helps with scalability and fault tolerance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Layer 4 (Transport)&lt;/strong&gt; – Uses TCP/UDP
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Layer 7 (Application)&lt;/strong&gt; – Uses HTTP/HTTPS &amp;amp; application logic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tools/Examples:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AWS ELB / ALB
&lt;/li&gt;
&lt;li&gt;HAProxy
&lt;/li&gt;
&lt;li&gt;Nginx
&lt;/li&gt;
&lt;li&gt;Traefik
&lt;/li&gt;
&lt;li&gt;F5 Big-IP
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Ensures no single server becomes a bottleneck.&lt;/p&gt;




&lt;h2&gt;
  
  
  CDN (Content Delivery Network)
&lt;/h2&gt;

&lt;p&gt;Caches and delivers static assets (images, videos, scripts) from edge locations closer to users — improving performance and latency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tools/Examples:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cloudflare
&lt;/li&gt;
&lt;li&gt;Akamai
&lt;/li&gt;
&lt;li&gt;AWS CloudFront
&lt;/li&gt;
&lt;li&gt;Fastly
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Best for static assets, video streaming, and global content delivery.&lt;/p&gt;




&lt;h2&gt;
  
  
  Message Queue / Streaming
&lt;/h2&gt;

&lt;p&gt;Used for &lt;strong&gt;asynchronous communication&lt;/strong&gt; between services. Helps with decoupling, buffering, and reliable message delivery.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tools/Examples:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Kafka
&lt;/li&gt;
&lt;li&gt;RabbitMQ
&lt;/li&gt;
&lt;li&gt;AWS SQS
&lt;/li&gt;
&lt;li&gt;Google Pub/Sub
&lt;/li&gt;
&lt;li&gt;ActiveMQ
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Ideal when services shouldn’t wait for each other.&lt;/p&gt;




&lt;h2&gt;
  
  
  Cache Layer
&lt;/h2&gt;

&lt;p&gt;Stores frequently accessed data to reduce database load and improve speed. Can be in-memory or distributed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tools/Examples:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Redis
&lt;/li&gt;
&lt;li&gt;Memcached
&lt;/li&gt;
&lt;li&gt;Hazelcast
&lt;/li&gt;
&lt;li&gt;Aerospike
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Great for session storage, lookup data, leaderboards, caching SQL queries.&lt;/p&gt;




&lt;h2&gt;
  
  
  Database Types (Quick Recap)
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Use Case&lt;/th&gt;
&lt;th&gt;Tools&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;SQL&lt;/td&gt;
&lt;td&gt;Strong consistency&lt;/td&gt;
&lt;td&gt;PostgreSQL, MySQL, Oracle&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;NoSQL&lt;/td&gt;
&lt;td&gt;High scalability&lt;/td&gt;
&lt;td&gt;MongoDB, Cassandra, DynamoDB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;In-Memory&lt;/td&gt;
&lt;td&gt;Fast reads&lt;/td&gt;
&lt;td&gt;Redis, Memcached&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Graph&lt;/td&gt;
&lt;td&gt;Relationships&lt;/td&gt;
&lt;td&gt;Neo4j, JanusGraph&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Service Discovery
&lt;/h2&gt;

&lt;p&gt;Automatically tracks available services and their dynamic locations (IP/ports). Essential in microservices.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tools/Examples:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Consul
&lt;/li&gt;
&lt;li&gt;Eureka (Netflix)
&lt;/li&gt;
&lt;li&gt;Etcd
&lt;/li&gt;
&lt;li&gt;Zookeeper
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 Helps services find and communicate with each other without manual config.&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;th&gt;Tools&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;API Gateway&lt;/td&gt;
&lt;td&gt;Entry point for clients&lt;/td&gt;
&lt;td&gt;Kong, API Gateway, Zuul&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reverse Proxy&lt;/td&gt;
&lt;td&gt;Forward client requests&lt;/td&gt;
&lt;td&gt;Nginx, Apache, HAProxy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Load Balancer&lt;/td&gt;
&lt;td&gt;Distribute traffic&lt;/td&gt;
&lt;td&gt;AWS ELB, Nginx, Traefik&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CDN&lt;/td&gt;
&lt;td&gt;Deliver static content&lt;/td&gt;
&lt;td&gt;Cloudflare, Akamai&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Message Queue&lt;/td&gt;
&lt;td&gt;Async communication&lt;/td&gt;
&lt;td&gt;Kafka, RabbitMQ&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cache&lt;/td&gt;
&lt;td&gt;Fast data access&lt;/td&gt;
&lt;td&gt;Redis, Memcached&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Service Discovery&lt;/td&gt;
&lt;td&gt;Track service IPs&lt;/td&gt;
&lt;td&gt;Consul, Eureka&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>architecture</category>
      <category>distributedsystems</category>
      <category>systemdesign</category>
    </item>
  </channel>
</rss>
