<?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>DEV Community: meenachan</title>
    <description>The latest articles on DEV Community by meenachan (@meenachan101).</description>
    <link>https://dev.to/meenachan101</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%2F1212993%2F9925bce3-c351-44de-b633-02a9f9dd386d.jpg</url>
      <title>DEV Community: meenachan</title>
      <link>https://dev.to/meenachan101</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/meenachan101"/>
    <language>en</language>
    <item>
      <title>Code Quest: Taming the Request Beast with Spliterator Magic! 🧙‍♂️✨</title>
      <dc:creator>meenachan</dc:creator>
      <pubDate>Sun, 22 Sep 2024 16:31:43 +0000</pubDate>
      <link>https://dev.to/meenachan101/code-quest-taming-the-request-beast-with-spliterator-magic-290m</link>
      <guid>https://dev.to/meenachan101/code-quest-taming-the-request-beast-with-spliterator-magic-290m</guid>
      <description>&lt;p&gt;In the realm of development, every day can feel like an epic adventure. One fateful Tuesday, I found myself facing a formidable beast: a tidal wave of urgent user requests threatening to overwhelm my code. With deadlines looming and the clock ticking, I needed a hero’s strategy to conquer this chaos. &lt;/p&gt;

&lt;p&gt;As the number of user requests surged, I realized that my initial approach—a simple filtering loop—was insufficient for managing the diverse types of requests pouring in. Urgent requests mixed with complex and incomplete ones created a tangled mess that slowed down processing and left users impatiently waiting. I needed a solution that could efficiently handle this variety while ensuring that urgent requests were prioritised.&lt;/p&gt;

&lt;p&gt;What began as a simple filtering task quickly morphed into a high-stakes race against time, pushing my coding skills to their limits.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Initial Struggle
&lt;/h3&gt;

&lt;p&gt;I started simply, filtering requests with a basic loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;urgentRequests&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isUrgent&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;urgentRequests&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This worked well for a manageable list, but as the requests soared from hundreds to thousands, my code crawled, leaving users impatiently waiting.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Parallel Stream Hail Mary
&lt;/h3&gt;

&lt;p&gt;Desperate for speed, I turned to &lt;strong&gt;parallel streams&lt;/strong&gt;, hoping to unleash some serious processing power:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;urgentRequests&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;parallelStream&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;filter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;Person:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;isUrgent&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;collect&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Collectors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toList&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While I felt like a coding hero, soon I realized that the varying request types—simple, complex, incomplete, and nested—overwhelmed my newfound speed. The chaos continued, and users were still in limbo.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Spliterator Revelation 💡
&lt;/h3&gt;

&lt;p&gt;In a moment of clarity, I discovered &lt;strong&gt;Spliterator&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  What is Spliterator?
&lt;/h4&gt;

&lt;p&gt;A &lt;strong&gt;Spliterator&lt;/strong&gt; (short for "splittable iterator") is a Java interface introduced in Java 8 that allows you to traverse and partition elements of a data structure. Unlike a standard iterator, which processes elements sequentially, a Spliterator can divide a collection into smaller parts, enabling parallel processing. This is particularly useful for collections that have diverse or nested structures.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Characteristics of Spliterator
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Splitting&lt;/strong&gt;: It can break down a data structure into smaller chunks, which can then be processed concurrently.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Characteristics&lt;/strong&gt;: It provides information about the data, such as whether it is &lt;code&gt;SIZED&lt;/code&gt;, &lt;code&gt;SUBSIZED&lt;/code&gt;, &lt;code&gt;ORDERED&lt;/code&gt;, or &lt;code&gt;CONCURRENT&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficiency&lt;/strong&gt;: It allows for efficient traversal and can adapt to various data types and structures.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Key Methods of Spliterator
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;tryAdvance(Consumer&amp;lt;? super T&amp;gt; action)&lt;/code&gt;&lt;/strong&gt;: Performs the given action on the next element if one exists, returning true if an element was processed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;trySplit()&lt;/code&gt;&lt;/strong&gt;: Attempts to split the spliterator into two parts, returning a new spliterator for the first part and leaving the second part for the original.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;estimateSize()&lt;/code&gt;&lt;/strong&gt;: Returns an estimate of the number of elements that remain to be processed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;characteristics()&lt;/code&gt;&lt;/strong&gt;: Returns a set of characteristics for this spliterator.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to Use Spliterator
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Complex Data Structures&lt;/strong&gt;: When working with collections that have diverse or nested structures, Spliterator can handle each element more intelligently.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Custom Processing Logic&lt;/strong&gt;: If you need specific handling for different types of elements, Spliterator allows for that flexibility.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parallel Processing Needs&lt;/strong&gt;: When you want fine control over how elements are processed in parallel, Spliterator shines.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The New Adventure: Spliterator Code 🛠️
&lt;/h3&gt;

&lt;p&gt;I revamped my code to use Spliterator, ready to tackle each request type head-on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;urgentRequests&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;
&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;incompleteRequests&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;gt;();&lt;/span&gt;

&lt;span class="nc"&gt;Spliterator&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;spliterator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;spliterator&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;spliterator&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;forEachRemaining&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;processRequest&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;urgentRequests&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;incompleteRequests&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, I created two lists: one for urgent requests and another for incomplete ones. The &lt;code&gt;spliterator.forEachRemaining()&lt;/code&gt; method processes each &lt;code&gt;Person&lt;/code&gt;, applying tailored logic to each request.&lt;/p&gt;

&lt;h3&gt;
  
  
  Processing Different Requests
&lt;/h3&gt;

&lt;p&gt;I defined the &lt;code&gt;processRequest&lt;/code&gt; method to handle the various types:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;processRequest&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Person&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;urgentRequests&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;incompleteRequests&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isUrgent&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isSimpleRequest&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;urgentRequests&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Quick and easy&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isComplexRequest&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;handleComplexRequest&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Handle complex scenarios&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isIncompleteRequest&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;incompleteRequests&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Log for later&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isNestedRequest&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;handleNestedRequest&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Address nested issues&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Simple Requests&lt;/strong&gt; go straight to the urgent list.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Complex Requests&lt;/strong&gt; are handled in detail.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Incomplete Requests&lt;/strong&gt; are logged for follow-up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nested Requests&lt;/strong&gt; require specialized logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Victory!🚀
&lt;/h3&gt;

&lt;p&gt;As I executed the updated code, it felt like crossing the finish line of a marathon. Spliterator handled the chaos beautifully, ensuring urgent requests were prioritized while incomplete ones were noted for future attention.&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Thoughts: Conquer Your Coding Challenges! 🏆
&lt;/h3&gt;

&lt;p&gt;To all you coding sorcerers out there, remember: with tools like Spliterator, you can transform chaos into clarity. Embrace the magic, and may your code thrive!&lt;/p&gt;

</description>
      <category>java</category>
      <category>spliterator</category>
      <category>streamapi</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The Power of Small Tweaks: Java 17's Flow Scoping and Pattern Matching Unveiled</title>
      <dc:creator>meenachan</dc:creator>
      <pubDate>Sun, 11 Aug 2024 17:10:58 +0000</pubDate>
      <link>https://dev.to/meenachan101/the-power-of-small-tweaks-java-17s-flow-scoping-and-pattern-matching-unveiled-1fj7</link>
      <guid>https://dev.to/meenachan101/the-power-of-small-tweaks-java-17s-flow-scoping-and-pattern-matching-unveiled-1fj7</guid>
      <description>&lt;h3&gt;
  
  
  A Day in the Life of a Java Developer: The Subtle Power of Java 17
&lt;/h3&gt;

&lt;p&gt;It was one of those mornings where the coffee was just right, and the code seemed to flow as smoothly as the brew in your cup. You sat down at your desk, ready to tackle a particularly gnarly piece of your project—a module that had been giving you trouble for days. It wasn’t the complexity of the logic that was the problem, but rather the clunky, repetitive code that seemed to go on and on, line after line.&lt;/p&gt;

&lt;p&gt;You sighed and leaned back in your chair. &lt;em&gt;There must be a better way,&lt;/em&gt; you thought.&lt;/p&gt;

&lt;h4&gt;
  
  
  The First Problem: Scope Creep
&lt;/h4&gt;

&lt;p&gt;Your mind drifted back to a bug that had kept you up late the previous night. It was one of those insidious, hard-to-track bugs—an error caused by a variable that had been declared too broadly. The culprit was if else statement you had written weeks ago, with a variable that lingered in the outer scope long after it was needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code was functional, sure. But something about it bothered you. The variable &lt;code&gt;result&lt;/code&gt; was hanging out in the broader scope like a ghost from a previous flow, ready to cause confusion or worse—another bug. &lt;/p&gt;

&lt;p&gt;But then you remembered something you’d read about Java 17: a little feature called &lt;em&gt;flow scoping&lt;/em&gt;. It was one of those seemingly small changes that could make a big difference. With flow scoping, variables could be confined to the specific block where they’re needed, keeping the rest of your code clean and focused.&lt;/p&gt;

&lt;p&gt;You decided to give it a try.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It was as if a weight had been lifted. The code was tighter, more elegant. The unnecessary variable was gone, leaving behind a flow that made perfect sense. You couldn’t help but smile—a small victory, but a satisfying one nonetheless.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Second Problem: The Type-Checking Grind
&lt;/h4&gt;

&lt;p&gt;Encouraged by your success, you turned to another section of code that had been nagging at you. It was a classic scenario: an &lt;code&gt;Object&lt;/code&gt; that could be anything—a &lt;code&gt;String&lt;/code&gt;, an &lt;code&gt;Integer&lt;/code&gt;, a &lt;code&gt;Double&lt;/code&gt;—and you had to check its type before you could do anything with it.&lt;/p&gt;

&lt;p&gt;The old way was clunky, involving multiple steps just to get to the good part:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello, World!"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toUpperCase&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You groaned as you looked at it. Sure, it worked, but why did you need to check the type and then cast it? Why couldn’t it be simpler?&lt;/p&gt;

&lt;p&gt;That’s when you remembered another little gem from Java 17: &lt;em&gt;pattern matching for instanceof.&lt;/em&gt; This wasn’t just a syntactical sugar—this was a way to streamline your code, to make it more readable and less error-prone.&lt;/p&gt;

&lt;p&gt;You refactored the code, eager to see the difference:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello, World!"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toUpperCase&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The effect was immediate. The code was cleaner, more concise. The type check and cast were now one and the same, all in a single line. It was as if the code was speaking your language, doing exactly what you wanted it to do without all the extra noise.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Magic of Java 17: Putting It All Together
&lt;/h4&gt;

&lt;p&gt;As the day went on, you found yourself using these features more and more, weaving them into your code like a skilled craftsman. You began to see the beauty in these small changes—the way they worked together to create something greater than the sum of their parts.&lt;/p&gt;

&lt;p&gt;By the afternoon, you were deep into refactoring an old piece of code that had always felt a little clunky. It was a loop processing an array of mixed types, each element needing its own special handling. Before, the code had been verbose, with each type check followed by an explicit cast.&lt;/p&gt;

&lt;p&gt;But now, with Java 17’s flow scoping and pattern matching, you saw a better way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PatternMatchingDemo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;elements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Java"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Pattern Matching"&lt;/span&gt;&lt;span class="o"&gt;};&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;elements&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;element&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"String: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toUpperCase&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;element&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Integer&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Integer: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;element&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Double&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Double: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Unknown type"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code was streamlined, each block of logic contained within its own scope, with variables neatly tied to their specific flow. You marveled at how such small changes could have such a big impact. The repetitive boilerplate was gone, replaced with a clarity and simplicity that felt right.&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion: The Quiet Revolution
&lt;/h4&gt;

&lt;p&gt;As you packed up for the day, you couldn’t help but reflect on how much Java 17 had transformed your code. These weren’t flashy new features, but they were powerful in their own quiet way. Flow scoping and pattern matching had helped you write code that was not only more efficient but also easier to read and maintain.&lt;/p&gt;

&lt;p&gt;In the world of software development, it’s often the small things that make the biggest difference. And today, you had discovered that Java 17’s small tricks—flow scoping and pattern matching—were just what you needed to make your code better, one line at a time.&lt;/p&gt;

</description>
      <category>java</category>
      <category>java17</category>
      <category>webdev</category>
      <category>backend</category>
    </item>
    <item>
      <title>Git Worktree: Your Ticket to Parallel Development Paradise</title>
      <dc:creator>meenachan</dc:creator>
      <pubDate>Sun, 28 Apr 2024 11:51:54 +0000</pubDate>
      <link>https://dev.to/meenachan101/git-worktree-your-ticket-to-parallel-development-paradise-3242</link>
      <guid>https://dev.to/meenachan101/git-worktree-your-ticket-to-parallel-development-paradise-3242</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;We've all been there: deep in the zone, crafting that perfect feature, when suddenly—bam!—a bug report comes crashing in, demanding immediate attention. The frustration of having to switch gears from feature development to bug fixing is enough to make any developer want to hurl their keyboard out the window. But fear not, dear developer, for Git Worktree 🌳 is here to save the day!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Struggle
&lt;/h2&gt;

&lt;p&gt;Picture this: you're knee-deep in code, crafting the next killer feature for your app. Every line of code is a masterpiece, and you're on fire. But just as you're about to unleash your creation upon the world, a bug report comes swooping in like a pesky mosquito on a summer night.&lt;/p&gt;

&lt;p&gt;Now, you're faced with the dreaded task of stashing your current changes, switching branches, fixing the bug, and then trying to remember where you left off with your feature. It's enough to make you want to pull your hair out!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Old Way
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Frantically type git stash into your terminal, hoping it'll save your precious changes.&lt;/li&gt;
&lt;li&gt;Switch to the branch for the bug fix with git checkout bug-fix-branch.&lt;/li&gt;
&lt;li&gt;Fix the bug, test, commit, and push your changes.&lt;/li&gt;
&lt;li&gt;Return to your feature branch with git checkout feature-branch.&lt;/li&gt;
&lt;li&gt;Pray to the demo gods that everything still works.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Solution: Git Worktree to the Rescue!&lt;/strong&gt;&lt;br&gt;
Enter Git Worktree, the hero we never knew we needed. With Git Worktree, you can create separate working trees for different branches, allowing you to switch between tasks seamlessly without the hassle of stashing and switching.&lt;/p&gt;
&lt;h2&gt;
  
  
  Git Worktree in Action
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Creating a Worktree:&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;git worktree add ../bug-fix bug-fix-branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command creates a new working directory called bug-fix with the bug-fix-branch checked out.&lt;br&gt;
Fixing the Bug:Head over to the bug-fix directory, fix that pesky bug, and commit your changes like a boss.&lt;br&gt;
Returning to Your Feature:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ../feature
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You're back in your feature branch, right where you left off, ready to conquer the world once again!&lt;br&gt;
Additional Git Worktree Commands:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Listing Worktree&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;git worktree list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command lists all the active worktrees along with their associated branches.&lt;br&gt;
&lt;strong&gt;Removing Worktrees&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;git worktree remove &amp;lt;path-to-worktree&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command removes the specified worktree and its associated directory.&lt;br&gt;
&lt;strong&gt;Moving Worktrees&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;git worktree move &amp;lt;path-to-worktree&amp;gt; &amp;lt;new-path&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command moves a worktree to a new location.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;With Git Worktree, the days of context switching woes are behind us. Say goodbye to stash pop nightmares and hello to seamless task switching. So go forth, dear developer, and conquer the coding world with confidence, knowing that Git Worktree has your back!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Little Dev Humor&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And to all the bugs out there that love to crash our parties uninvited: Git Worktree 🌳 is our secret weapon, and we're not afraid to use it! So bug off, because we've got code to ship!🚀&lt;/p&gt;

</description>
      <category>git</category>
      <category>programming</category>
      <category>developers</category>
      <category>productivity</category>
    </item>
    <item>
      <title>A Magical Guide to Building Your Own Web Server - For Budding Coders! 🚀✨</title>
      <dc:creator>meenachan</dc:creator>
      <pubDate>Sun, 10 Dec 2023 13:28:55 +0000</pubDate>
      <link>https://dev.to/meenachan101/a-magical-guide-to-building-your-own-web-server-for-budding-coders-2adp</link>
      <guid>https://dev.to/meenachan101/a-magical-guide-to-building-your-own-web-server-for-budding-coders-2adp</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;:&lt;br&gt;
Hello, little coding wizards! &lt;br&gt;
Today, we're embarking on a magical journey to create our very own web server. It's like having a magic wand that makes the internet dance to our tunes! 🌐✨&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Section 1: Setting Up Your Enchanted Castle 🏰&lt;/strong&gt;&lt;br&gt;
In the coding kingdom, every wizard needs a castle! Our castle is a special folder called "www," where we keep treasures to share with our friends. Let's start by creating this magical castle.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Enchanted Castle Setup
private static String ROOT_DIRECTORY = "www";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Imagine your computer as a magical castle. We're creating a folder called "www" inside the castle. This is where we'll keep all our magical web treasures!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Section 2: Magical Portal - Starting Your Adventure 🚀&lt;/strong&gt;&lt;br&gt;
Now, let's create a magical portal (server socket) on port 80. This portal will help us communicate with friends on the internet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Magical Portal - Starting Your Adventure
public static void main(String[] args) {
    // ... (Allow specifying the location of the www folder)
    ServerSocket serverSocket = new ServerSocket(80);
    while (true) {
        Socket clientSocket = serverSocket.accept();
        new Thread(() -&amp;gt; handleRequest(clientSocket)).start();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Think of the internet as a magical world. We're creating a portal (like a door) on our computer that listens on port 80. When a friend knocks on this door (client connects), we welcome them and handle their requests!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Section 3: Welcoming Magical Creatures - Handling Requests 🌟&lt;/strong&gt;&lt;br&gt;
When a magical creature (client) knocks, we welcome them and handle their requests in a new thread.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Welcoming Magical Creatures - Handling Requests
private static void handleRequest(Socket clientSocket) {
    // ... (Opening scrolls for communication with the magical creature)
    String request = in.readLine();
    String requestedPath = getRequestPath(request);

    if (requestedPath.endsWith(".cgi")) {
        serveCgiScript(requestedPath, writer);
    } else {
        serveHtmlFile(requestedPath, writer);
    }
    clientSocket.close();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a friend (client) comes to visit, we read their request on a magical scroll. Depending on what they ask for, we decide whether to share a magical tale (HTML file) or perform a special spell (CGI script)!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Section 4: Extracting Desires - Getting the Requested Path 🧭&lt;/strong&gt;&lt;br&gt;
Let's create a magical function to extract the desired path from the creature's request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Extracting Desires - Getting the Requested Path
private static String getRequestPath(String request) {
    String[] parts = request.split(" ");
    return (parts.length &amp;gt;= 2) ? parts[1] : "/";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We use a magical function to understand what our friend is asking for. The function extracts the path from their request, like telling us which book they want from our magical library!&lt;/p&gt;

&lt;p&gt;****Section 5: Sharing Magical Tales - HTML Files 📖&lt;br&gt;
We can share magical tales (HTML files) from our enchanted castle. If a friend asks for a specific tale, we find it and share the wonder!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Sharing Magical Tales - HTML Files
private static void serveHtmlFile(String requestedPath, PrintWriter writer) throws IOException {
    // ... (Constructing the magical path to the tale based on the creature's request)
    try (BufferedReader fileReader = new BufferedReader(new FileReader(file))) {
        writer.println("HTTP/1.1 200 OK");
        writer.println("Content-Type: text/html");
        writer.println();

        // Sending the magical content of the tale to the creature
        String line;
        while ((line = fileReader.readLine()) != null) {
            writer.println(line);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a friend asks for a magical tale, we find the tale in our enchanted library (HTML file) and share it with them. The friend can now see the magical content in their browser!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Section 6: Special Spells - CGI Scripts! 🧙‍♂️&lt;/strong&gt;&lt;br&gt;
For friends who love special spells (CGI scripts), we take them to a secret room and perform magical spells to create something special!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Special Spells - CGI Scripts
private static void serveCgiScript(String requestedPath, PrintWriter writer) throws IOException {
    // ... (Constructing the magical path to the script based on the creature's request)
    try {
        // Performing the special spell by executing the CGI script
        // ... (Sending the magical output of the special spell to the creature)
    } catch (IOException e) {
        // If there is an issue with the special spell, sending a message of internal error to the creature
        writer.println("HTTP/1.1 500 Internal Server Error");
        writer.println("Content-Type: text/plain");
        writer.println();
        writer.println("500 Internal Server Error");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some friends want more than just tales—they want special spells! CGI (Common Gateway Interface) scripts are like magical spells that can do amazing things. In our enchanted castle, we have a special room for these spells. When a friend asks for a special spell by requesting a path that ends with ".cgi," we perform the spell by executing the CGI script. The result is a magical output that we share with our friend.&lt;/p&gt;

&lt;p&gt;What is CGI?&lt;br&gt;
CGI is like a magic spellbook for web servers. It allows us to perform special actions on the server and create dynamic content. Instead of just sharing fixed tales (HTML files), CGI lets us perform spells (scripts) that can do calculations, show the current time, or even interact with other magical beings (databases). However, it's essential to know that CGI, while once widely used, is like an old spellbook that has been replaced by more modern magic (web frameworks and technologies). So, while we're learning about it for fun, many wizards now use different, more powerful spells for their web adventures! 🌟&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Conclusion: You're a Coding Wizard! 🌟Congratulations!&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Once Upon a Code Adventure: IoC and DI in the Land of Spring</title>
      <dc:creator>meenachan</dc:creator>
      <pubDate>Sun, 19 Nov 2023 13:50:28 +0000</pubDate>
      <link>https://dev.to/meenachan101/once-upon-a-code-adventure-ioc-and-di-in-the-land-of-spring-3plb</link>
      <guid>https://dev.to/meenachan101/once-upon-a-code-adventure-ioc-and-di-in-the-land-of-spring-3plb</guid>
      <description>&lt;p&gt;Hello👋✨, little coders! Today, let's dive into a magical coding story where we meet two special friends: IoC (Inversion of Control) and DI (Dependency Injection). Picture it like a fairy tale where coding toys come to life in the Spring kingdom.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Inversion of Control?
&lt;/h2&gt;

&lt;p&gt;Imagine you have a magical friend named IoC. Normally, you decide which toys to play with and when. But IoC flips the story! Now, IoC decides when it's playtime and how the toys play together. It's like a magical friend taking charge of the toy party schedule.&lt;/p&gt;

&lt;p&gt;Magic Words: Decoupling, Switching Toys Easily, Neat Toy Rooms, Testing Toys Easily&lt;/p&gt;

&lt;p&gt;How We Achieve This Magic:&lt;/p&gt;

&lt;p&gt;Strategy: Planning playtime strategies.&lt;br&gt;
Service Locator: Asking a special friend where toys are.&lt;br&gt;
Factory: A magical factory creating toys.&lt;br&gt;
Dependency Injection (DI): Toys are given as gifts!&lt;/p&gt;
&lt;h2&gt;
  
  
  What Is Dependency Injection?
&lt;/h2&gt;

&lt;p&gt;Now, let's talk about the magic of Dependency Injection (DI). Imagine your mom or dad giving you a special toy as a gift. DI is like receiving toys without making them yourself. Someone injects, or gives, toys into your toy box for you to play with.&lt;/p&gt;

&lt;p&gt;Magic Words: Getting Toy Gifts, No Toy-Making Stress, Playful Assembly&lt;/p&gt;

&lt;p&gt;Storytime in Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Traditional Way: Making a toy
public class Store {
    private Item item;

    public Store() {
        item = new ItemImpl1();
    }
}

// Magic Way: Receiving a toy gift
public class Store {
    private Item item;

    public Store(Item item) {
        this.item = item;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Spring Toy Kingdom
&lt;/h2&gt;

&lt;p&gt;In the Spring kingdom, there's a special toy organizer called the IoC Container. It's like the king of toys, managing everything from creating to organizing the toys (beans). The Spring kingdom has different areas for toys (ApplicationContexts): one for regular toys, one for toys that like to play alone, and one for web toys!&lt;/p&gt;

&lt;p&gt;Magical Words: ApplicationContext, King of Toys, Magical Toy Rooms&lt;/p&gt;

&lt;p&gt;How Toys Are Assembled:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Manually creating a toy room
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Constructor-Based Dependency Injection
&lt;/h2&gt;

&lt;p&gt;Now, let's talk about Constructor-Based Dependency Injection. It's like getting toys with specific instructions on how to play.&lt;/p&gt;

&lt;p&gt;Magic Words: Magic Instructions, Special Play Plans&lt;/p&gt;

&lt;p&gt;Storytime in Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Magic Instructions in Code
@Configuration
public class ToyPlans {

    @Bean
    public Item item1() {
        return new ItemImpl1();
    }

    @Bean
    public Store store() {
        return new Store(item1());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setter-Based Dependency Injection
&lt;/h2&gt;

&lt;p&gt;Next up is Setter-Based Dependency Injection. It's like getting toys and deciding how to play with them later.&lt;/p&gt;

&lt;p&gt;Magic Words: Play Plans Can Change, Decorating Toys Later&lt;/p&gt;

&lt;p&gt;Storytime in Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Changing play plans later
@Bean
public Store store() {
    Store store = new Store();
    store.setItem(item1());
    return store;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Field-Based Dependency Injection
&lt;/h2&gt;

&lt;p&gt;Now, let's talk about Field-Based Dependency Injection. It's like placing toys directly where they need to be.&lt;/p&gt;

&lt;p&gt;Magic Words: Toys Find Their Spots&lt;/p&gt;

&lt;p&gt;Storytime in Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Placing toys in their spots
public class Store {
    @Autowired
    private Item item; 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Autowiring Toys
&lt;/h2&gt;

&lt;p&gt;Autowiring is like letting the toy room organizer (Spring) decide how toys connect.&lt;/p&gt;

&lt;p&gt;Magic Words: Organized Toy Connections&lt;/p&gt;

&lt;p&gt;Storytime in Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Toy room organizer deciding connections
public class ToyPlans {
    @Bean(autowire = Autowire.BY_TYPE)
    public Store store() {
        return new Store();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Lazy Initialized Toys
&lt;/h2&gt;

&lt;p&gt;Lastly, Lazy Initialized Toys are like toys that wake up only when you want to play with them.&lt;/p&gt;

&lt;p&gt;Magic Words: Sleeping Toys, Surprise Playtime&lt;/p&gt;

&lt;p&gt;Storytime in Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Sleeping toys until playtime
&amp;lt;bean id="item1" class="store.ItemImpl1" lazy-init="true" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that, little coders, is our magical coding adventure with IoC and DI in the Spring kingdom! May your coding toy room always be filled with joy and surprises! 🚀✨&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>spring</category>
      <category>dependencyinversion</category>
      <category>java</category>
    </item>
    <item>
      <title>SpringBoot101: Configurations</title>
      <dc:creator>meenachan</dc:creator>
      <pubDate>Sat, 18 Nov 2023 15:14:45 +0000</pubDate>
      <link>https://dev.to/meenachan101/springboot101-configurations-3ki1</link>
      <guid>https://dev.to/meenachan101/springboot101-configurations-3ki1</guid>
      <description>&lt;p&gt;Configuring applications can be both exciting and challenging for developers. In this blog post, we'll dive into the intricacies of Spring configurations, exploring practical techniques like the @Value annotation, leveraging Spring Boot's features, YAML files, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using @Value Annotation:
&lt;/h2&gt;

&lt;p&gt;Injecting properties with the @Value annotation is a common practice. It's a concise way to pull in configuration values directly into our beans.&lt;br&gt;
java&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Value("${jdbc.url}")
private String jdbcUrl;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Properties with Spring Boot:
&lt;/h2&gt;

&lt;p&gt;Spring Boot simplifies configuration, offering conventions that reduce the need for explicit setup. The application.properties file is automatically detected, sparing us from manual registration. Runtime configurations are flexible, allowing alternative files or locations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java -jar app.jar --spring.config.location=classpath:/another-location.properties

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Environment-Specific and Test-Specific Properties:
&lt;/h2&gt;

&lt;p&gt;Spring Boot provides easy ways to handle environment-specific configurations and tests. Special files like application-environment.properties and @TestPropertySource annotations give granular control.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@TestPropertySource(properties = {"foo=bar"})
public class PropertyInjectionUnitTest {
    // Test implementation
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Hierarchical Properties:
&lt;/h2&gt;

&lt;p&gt;Managing grouped properties is streamlined with the @ConfigurationProperties annotation. It's a developer-friendly way to structure and organize configurations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@ConfigurationProperties(prefix = "database")
public class Database {
    // Fields and getters/setters
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  YAML Files:
&lt;/h2&gt;

&lt;p&gt;YAML files are a developer's delight for structured configuration. While they handle nested properties elegantly, keep in mind they don't play nice with the @PropertySource annotation.&lt;br&gt;
yaml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;database:
  url: jdbc:postgresql:/localhost:5432/instance
  username: foo
  password: bar
secret: foo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Importing Additional Configuration Files:
&lt;/h2&gt;

&lt;p&gt;Spring Boot 2.4.0 introduces the spring.config.import property, enabling easy inclusion of additional configuration files. It's a powerful tool for handling diverse configuration sources.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;spring.config.import=classpath:additional-application.properties,
  classpath:additional-application[.yml],
  optional:file:./external.properties,
  classpath:additional-application-properties/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Properties From Command Line Arguments and Environment Variables:
&lt;/h2&gt;

&lt;p&gt;Directly passing properties through the command line or environment variables is a developer's go-to for quick adjustments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java -jar app.jar --property="value"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export name=value
java -jar app.jar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Randomization of Property Values:
&lt;/h2&gt;

&lt;p&gt;Injecting a bit of randomness into property values is possible with Spring Boot's RandomValuePropertySource. It's a playful feature for scenarios where deterministic values aren't necessary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;random.number=${random.int}
random.long=${random.long}
random.uuid=${random.uuid}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Additional Types of Property Sources:
&lt;/h2&gt;

&lt;p&gt;Spring Boot supports a plethora of property sources, each with its own strengths. Developers looking for specific behavior should refer to the official documentation for a comprehensive understanding.&lt;/p&gt;

&lt;p&gt;Configuration Using Raw Beans — the PropertySourcesPlaceholderConfigurer:&lt;br&gt;
For developers who want complete control, manually defining the property configuration bean with PropertySourcesPlaceholderConfigurer provides flexibility.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Bean
public static PropertySourcesPlaceholderConfigurer properties(){
    // Bean configuration details
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Configuring properties is a daily task for developers, and mastering Spring's tools makes it a smoother experience. Armed with techniques like @Value, Spring Boot conventions, and YAML files, developers can confidently handle diverse configurations. So, developer comrades, venture forth with Spring configurations and conquer your application's setup challenges!&lt;/p&gt;

&lt;p&gt;Keep Coding!!!!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>springboot</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
