<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Abhinav Prakash | Blogs]]></title><description><![CDATA[I write about programming, AI, open-source tools, and my developer journey.  
From building side projects to solving real-world dev problems]]></description><link>https://blog.iamabhinav.dev</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1759199477016/04431d3f-459a-455a-a2c4-0eeea0aad55a.png</url><title>Abhinav Prakash | Blogs</title><link>https://blog.iamabhinav.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Fri, 15 May 2026 01:12:46 GMT</lastBuildDate><atom:link href="https://blog.iamabhinav.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[🤯 I Just Realized JavaScript Has WAY More Event Listeners Than I Ever Imagined]]></title><description><![CDATA[For the longest time, I thought I had JavaScript events pretty much figured out.
You know the usual ones:

click

input

submit

scroll

maybe keydown


And honestly? My work was getting done. Projects were shipping. Clients were happy.
So in my head...]]></description><link>https://blog.iamabhinav.dev/js-events</link><guid isPermaLink="true">https://blog.iamabhinav.dev/js-events</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[events]]></category><category><![CDATA[Javascript events]]></category><category><![CDATA[DOM]]></category><category><![CDATA[event listener ]]></category><category><![CDATA[Event listeners in JavaScript]]></category><dc:creator><![CDATA[Abhinav Prakash]]></dc:creator><pubDate>Sun, 18 Jan 2026 19:17:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1768764447804/6e12520c-3a1f-45d6-8a0f-e267b3991a50.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>For the longest time, I thought I had JavaScript events pretty much figured out.</p>
<p>You know the usual ones:</p>
<ul>
<li><p><code>click</code></p>
</li>
<li><p><code>input</code></p>
</li>
<li><p><code>submit</code></p>
</li>
<li><p><code>scroll</code></p>
</li>
<li><p>maybe <code>keydown</code></p>
</li>
</ul>
<p>And honestly? My work was getting done. Projects were shipping. Clients were happy.</p>
<p>So in my head, the logic was simple:</p>
<blockquote>
<p>“If these events are enough to build websites, why even bother learning the rest?”</p>
</blockquote>
<p>Turns out… that mindset was lazy 😅 And I didn’t realize it until very recently.</p>
<hr />
<h2 id="heading-how-i-ended-up-discovering-this">How I Ended Up Discovering This</h2>
<p>This whole realization started in a very normal way.</p>
<p>I was going through a GitHub repository, just reading someone else’s code. No tutorial, no blog - just raw production code. And that’s when I noticed <strong>event listeners I had literally never used before</strong>.</p>
<p>Stuff like:</p>
<ul>
<li><p><code>visibilitychange</code></p>
</li>
<li><p><code>pointer</code> events</p>
</li>
<li><p>animation and transition events</p>
</li>
</ul>
<p>At first, I ignored it.</p>
<p>Because deep down, I already <em>knew</em> JavaScript has a lot of events. I just assumed:</p>
<blockquote>
<p>“Yeah yeah, those are probably edge-case events. I don’t really need them.”</p>
</blockquote>
<p>But then I paused and thought:</p>
<p>What if I’m solving problems the <strong>hard way</strong>, while JavaScript already gives me <strong>better tools</strong>?</p>
<p>What if some things I’m doing with hacks, timers, or heavy logic could be done more cleanly using the <strong>right event</strong>?</p>
<p>That’s when I decided to dig deeper.</p>
<hr />
<h2 id="heading-the-big-realization">The Big Realization</h2>
<p>JavaScript doesn’t just react to clicks or inputs.</p>
<p>It literally listens to:</p>
<ul>
<li><p>user actions</p>
</li>
<li><p>browser state</p>
</li>
<li><p>network changes</p>
</li>
<li><p>page visibility</p>
</li>
<li><p>animations</p>
</li>
<li><p>media playback</p>
</li>
<li><p>device input</p>
</li>
<li><p>even tab switching</p>
</li>
<li><p>system behavior</p>
</li>
</ul>
<p>Basically, <strong>JavaScript is always watching</strong> 👀 You just need to know <em>what</em> to listen for.</p>
<hr />
<h2 id="heading-categories-of-javascript-events-the-eye-opener">Categories of JavaScript Events (The Eye-Opener)</h2>
<p>I’m not going to dump <em>every single event</em> here - that would be insane. But here’s a <strong>mental map</strong> that completely changed how I see events.</p>
<hr />
<h3 id="heading-mouse-events">🖱️ Mouse Events</h3>
<p>These are the basics, but there’s more than just <code>click</code>.</p>
<ul>
<li><p><code>click</code></p>
</li>
<li><p><code>dblclick</code></p>
</li>
<li><p><code>mouseenter</code> / <code>mouseleave</code></p>
</li>
<li><p><code>mouseover</code> / <code>mouseout</code></p>
</li>
<li><p><code>contextmenu</code> (right click)</p>
</li>
</ul>
<p>Useful for hover effects, menus, tooltips, custom interactions.</p>
<hr />
<h3 id="heading-keyboard-events">⌨️ Keyboard Events</h3>
<ul>
<li><p><code>keydown</code></p>
</li>
<li><p><code>keyup</code></p>
</li>
</ul>
<p>Great for shortcuts, accessibility, power-user features.</p>
<hr />
<h3 id="heading-form-amp-input-events">✍️ Form &amp; Input Events</h3>
<ul>
<li><p><code>input</code></p>
</li>
<li><p><code>change</code></p>
</li>
<li><p><code>focus</code></p>
</li>
<li><p><code>blur</code></p>
</li>
<li><p><code>submit</code></p>
</li>
</ul>
<p>These control almost every form interaction you see on the web.</p>
<hr />
<h3 id="heading-scroll-amp-viewport-events">📜 Scroll &amp; Viewport Events</h3>
<ul>
<li><p><code>scroll</code></p>
</li>
<li><p><code>resize</code></p>
</li>
<li><p><code>wheel</code></p>
</li>
</ul>
<p>Still useful, but many scroll-based problems are now better solved with <strong>Intersection Observer</strong> instead of raw <code>scroll</code>.</p>
<hr />
<h3 id="heading-network-events">🌐 Network Events</h3>
<p>Yes, this exists.</p>
<ul>
<li><p><code>online</code></p>
</li>
<li><p><code>offline</code></p>
</li>
</ul>
<p>You can literally detect when the user loses or regains network and update UI accordingly.</p>
<hr />
<h3 id="heading-page-visibility-amp-lifecycle">👁️ Page Visibility &amp; Lifecycle</h3>
<p>These are criminally underrated.</p>
<ul>
<li><p><code>visibilitychange</code></p>
</li>
<li><p><code>pageshow</code></p>
</li>
<li><p><code>pagehide</code></p>
</li>
<li><p><code>beforeunload</code></p>
</li>
</ul>
<p>Perfect for:</p>
<ul>
<li><p>pausing videos</p>
</li>
<li><p>stopping timers</p>
</li>
<li><p>saving state</p>
</li>
<li><p>analytics accuracy</p>
</li>
</ul>
<hr />
<h3 id="heading-drag-amp-drop">📦 Drag &amp; Drop</h3>
<ul>
<li><p><code>dragstart</code></p>
</li>
<li><p><code>dragover</code></p>
</li>
<li><p><code>drop</code></p>
</li>
<li><p><code>dragend</code></p>
</li>
</ul>
<p>Used for file uploads, dashboards, reorderable lists, You must have used these in drag &amp; drop.</p>
<hr />
<h3 id="heading-touch-amp-pointer-events">📱 Touch &amp; Pointer Events</h3>
<p>Instead of separating mouse and touch, modern browsers give:</p>
<ul>
<li><p><code>pointerdown</code></p>
</li>
<li><p><code>pointermove</code></p>
</li>
<li><p><code>pointerup</code></p>
</li>
<li><p><code>gotpointercapture</code></p>
</li>
<li><p><code>lostpointercapture</code></p>
</li>
</ul>
<p>One API → mouse, touch, pen.</p>
<hr />
<h3 id="heading-animation-amp-transition-events">🎬 Animation &amp; Transition Events</h3>
<p>These blew my mind a bit.</p>
<ul>
<li><p><code>animationstart</code></p>
</li>
<li><p><code>animationend</code></p>
</li>
<li><p><code>transitionend</code></p>
</li>
</ul>
<p>You can literally <strong>react to CSS finishing its job</strong> instead of guessing with timeouts.</p>
<hr />
<h3 id="heading-media-events">🎧 Media Events</h3>
<p>For audio &amp; video:</p>
<ul>
<li><p><code>play</code></p>
</li>
<li><p><code>pause</code></p>
</li>
<li><p><code>ended</code></p>
</li>
<li><p><code>timeupdate</code></p>
</li>
<li><p><code>volumechange</code></p>
</li>
<li><p><code>trackchange</code></p>
</li>
</ul>
<p>Used heavily in modern media-heavy websites.</p>
<h3 id="heading-page-browser-amp-system-level">🧠 Page, Browser &amp; System Level</h3>
<p>These events are about <strong>browser state</strong>, not UI clicks.</p>
<ul>
<li><p><code>visibilitychange</code><br />  Fires when the tab becomes hidden or visible.</p>
</li>
<li><p><code>pageshow</code> / <code>pagehide</code><br />  Triggered when navigating back/forward (especially with <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Glossary/bfcache">bfcache</a>).</p>
</li>
<li><p><code>beforeunload</code><br />  Fired before the user leaves the page.</p>
</li>
<li><p><code>storage</code><br />  Fired when <code>localStorage</code> changes in <strong>another tab</strong>.</p>
</li>
</ul>
<hr />
<h2 id="heading-why-this-actually-matters">Why This Actually Matters</h2>
<p>This isn’t about memorizing event names.</p>
<p>It’s about this shift in mindset:</p>
<blockquote>
<p>Instead of forcing logic with hacks, ask yourself: <strong>“Is there already an event for this?”</strong></p>
</blockquote>
<p>Chances are - yes, there is.</p>
<p>Using the right event:</p>
<ul>
<li><p>simplifies code</p>
</li>
<li><p>improves performance</p>
</li>
<li><p>makes behavior more predictable</p>
</li>
<li><p>reduces bugs</p>
</li>
</ul>
<hr />
<h2 id="heading-you-dont-need-to-know-them-all-seriously">You Don’t Need to Know Them All (Seriously)</h2>
<p>Let’s be real - nobody remembers all JavaScript events.</p>
<p>And that’s completely fine.</p>
<p>What <em>does</em> matter is:</p>
<ul>
<li><p>knowing these events <strong>exist</strong></p>
</li>
<li><p>knowing where to look when needed</p>
</li>
</ul>
<hr />
<h2 id="heading-where-you-should-learn-them-properly">Where You Should Learn Them Properly</h2>
<p>If you really want to explore events in depth:</p>
<ul>
<li><p>📘 <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Events"><strong>MDN Web Docs</strong></a> Best place to understand what each event does, with examples.</p>
</li>
<li><p>🌍 <a target="_blank" href="https://caniuse.com/"><strong>Can I Use</strong></a> Always check browser support before using advanced or newer events</p>
</li>
</ul>
<p>There are <strong>many more events</strong> than the ones mentioned in this blog.<br />If you’re curious, definitely explore the full MDN list here:</p>
<p>👉 <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Events?utm_source=chatgpt.com">https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Events</a></p>
<p>👉 <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/Window#events">https://developer.mozilla.org/en-US/docs/Web/API/Window#events</a></p>
]]></content:encoded></item><item><title><![CDATA[WebRTC, NAT, STUN, TURN  A Complete Beginner-Friendly Guide]]></title><description><![CDATA[Real-time communication powers everything we use today — video calls, voice calls, live streaming, multiplayer games, and even real-time chat.
But how do two devices talk directly over the internet?
The secret behind all of this is WebRTC.
In this bl...]]></description><link>https://blog.iamabhinav.dev/webrtc-nat-stun-turn-a-complete-beginner-friendly-guide</link><guid isPermaLink="true">https://blog.iamabhinav.dev/webrtc-nat-stun-turn-a-complete-beginner-friendly-guide</guid><category><![CDATA[WebRTC]]></category><category><![CDATA[WebRTC technology]]></category><category><![CDATA[beginnersguide]]></category><category><![CDATA[Developer]]></category><dc:creator><![CDATA[Abhinav Prakash]]></dc:creator><pubDate>Thu, 27 Nov 2025 13:00:51 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1764246947335/fe329644-7e49-4e0b-b4f0-e70e18a8991c.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Real-time communication powers everything we use today — video calls, voice calls, live streaming, multiplayer games, and even real-time chat.</p>
<p>But how do two devices talk directly over the internet?</p>
<p>The secret behind all of this is <strong>WebRTC</strong>.</p>
<p>In this blog, we’ll break down WebRTC from the ground up:</p>
<ul>
<li>What WebRTC really does</li>
<li>What Signaling, SDP, and ICE are</li>
<li>What Host, STUN, and TURN candidates are</li>
<li>Why NAT creates problems</li>
<li>Why mobile network users are always behind NAT</li>
<li>And why TURN sometimes becomes mandatory</li>
</ul>
<p>By the end, you’ll understand WebRTC like a pro.</p>
<h2 id="heading-what-is-webrtc"><strong>What is WebRTC?</strong></h2>
<p><strong>WebRTC (Web Real-Time Communication)</strong> is a technology that allows browsers and apps to communicate peer-to-peer without needing a server in the middle for audio/video/data transfer.</p>
<p>WebRTC makes possible:</p>
<ul>
<li>Video calling</li>
<li>Voice calling</li>
<li>Live screen sharing</li>
<li>File transfer</li>
<li>Real-time chat (via DataChannel)</li>
</ul>
<p>Once the connection is established → the data flows directly between devices.</p>
<p>But establishing that connection is the tricky part.</p>
<h2 id="heading-why-peer-to-peer-is-so-hard"><strong>Why Peer-to-Peer Is So Hard?</strong></h2>
<p>Because almost every device on the internet is behind a <strong>NAT</strong>.</p>
<p>It doesn’t matter if you're using:</p>
<ul>
<li>Home WiFi</li>
<li>Broadband</li>
<li>Mobile data (SIM)</li>
<li>Corporate network</li>
<li>Public WiFi</li>
</ul>
<p>All of these use some type of NAT or firewall.</p>
<p>To bypass this, WebRTC depends on:</p>
<ul>
<li><strong>Signaling</strong></li>
<li><strong>SDP (Offer/Answer)</strong></li>
<li><strong>ICE (Connectivity process)</strong></li>
<li><strong>ICE Candidates (Host / STUN / TURN)</strong></li>
</ul>
<h2 id="heading-1-what-is-signaling"><strong>1) What is Signaling?</strong></h2>
<p>Signaling is how two devices exchange the initial information needed to start a WebRTC connection.</p>
<p>This includes:</p>
<ul>
<li>Their SDP</li>
<li>Their ICE candidates</li>
<li>Their media settings</li>
<li>Their "Hey, I want to connect" messages</li>
</ul>
<p>Signaling is <strong>not part of WebRTC</strong> itself — it’s just the method of sending messages between peers.</p>
<p>You can use:</p>
<ul>
<li>WebSocket</li>
<li>Socket.io</li>
<li>Firebase</li>
<li>REST API</li>
<li>Even manual copy-paste (for testing)</li>
</ul>
<p>Once both devices exchange the required info → signaling is done.</p>
<pre><code class="lang-mermaid">flowchart LR
    A[Device A] --&gt;|Offer SDP + ICE| S(Signaling Server)
    S --&gt;|Forward| B[Device B]
    B --&gt;|Answer SDP + ICE| S
    S --&gt;|Forward| A
    classDef peer fill:#4da6ff,stroke:#333,stroke-width:1px;
    class A,B peer
</code></pre>
<h2 id="heading-2-what-is-sdp"><strong>2) What is SDP?</strong></h2>
<p><strong>SDP (Session Description Protocol)</strong> is a long text description containing:</p>
<ul>
<li>Audio/Video codecs</li>
<li>Encryption details</li>
<li>Number of media tracks</li>
<li>DataChannel info</li>
<li>Network capabilities</li>
<li>Offer/Answer details</li>
</ul>
<p>SDP basically tells:</p>
<blockquote>
<p><strong>“Here is how I want to communicate. Tell me how you want to respond.”</strong></p>
</blockquote>
<p>WebRTC uses:</p>
<ul>
<li><strong>Offer SDP</strong> → created by the first device</li>
<li><strong>Answer SDP</strong> → created by the second device</li>
</ul>
<p>Without SDP, devices won’t understand each other’s capabilities.</p>
<pre><code class="lang-mermaid">sequenceDiagram
    participant A as Device A
    participant S as Signaling Server
    participant B as Device B

    A-&gt;&gt;S: Offer SDP
    S-&gt;&gt;B: Offer SDP
    B-&gt;&gt;S: Answer SDP
    S-&gt;&gt;A: Answer SDP
</code></pre>
<h2 id="heading-3-what-is-ice"><strong>3) What is ICE?</strong></h2>
<p><strong>ICE = Interactive Connectivity Establishment</strong></p>
<p>It’s a smart process WebRTC uses to discover:</p>
<ul>
<li>How devices can reach each other</li>
<li>Which path is the fastest</li>
<li>Which path is even possible</li>
</ul>
<p>ICE collects different candidates (possible connection routes).</p>
<p>There are 3 types:</p>
<ol>
<li><strong>Host Candidate</strong> → local network address</li>
<li><strong>STUN Candidate</strong> → public IP address</li>
<li><strong>TURN Candidate</strong> → relay server (last resort)</li>
</ol>
<p>ICE tests all possibilities and automatically selects the best one.</p>
<pre><code class="lang-mermaid">flowchart TD
    subgraph Candidates
      H[Host Candidate]
      S[STUN Candidate]
      T[TURN Candidate]
    end

    A[Device A] --&gt;|gathers| H
    A --&gt;|gathers| S
    A --&gt;|gathers| T
    B[Device B] --&gt;|gathers| H
    B --&gt;|gathers| S
    B --&gt;|gathers| T

    H -- fastest --&gt; Direct[Direct P2P]
    S -- possible --&gt; Direct
    T -- relay --&gt; Relay[TURN Relay]
</code></pre>
<h2 id="heading-4-ice-candidate-types-explained"><strong>4) ICE Candidate Types Explained</strong></h2>
<h3 id="heading-a-host-candidates">A) Host Candidates</h3>
<p>These are local IP addresses, like:</p>
<ul>
<li>192.168.x.x</li>
<li>10.x.x.x</li>
</ul>
<p>Used when both devices are:</p>
<ul>
<li>On the same WiFi</li>
<li>On the same LAN</li>
</ul>
<p>Fastest possible connection.</p>
<h3 id="heading-b-stun-candidates">B) STUN Candidates</h3>
<p>A STUN server’s job:</p>
<blockquote>
<p><strong>“Tell me what my public IP looks like on the internet.”</strong></p>
</blockquote>
<p>Because NAT hides your real public address, STUN helps your device discover it.</p>
<p>Used for normal real-world P2P.</p>
<p>But STUN can fail on:</p>
<ul>
<li>Strict firewalls</li>
<li>Mobile networks</li>
<li>Corporate networks</li>
</ul>
<pre><code class="lang-mermaid">sequenceDiagram
    participant C as Client
    participant ST as STUN Server

    C-&gt;&gt;ST: Binding request ("what is my public IP?")
    ST--&gt;&gt;C: Binding response (public IP:port)
</code></pre>
<h3 id="heading-c-turn-candidates-relay">C) TURN Candidates (Relay)</h3>
<p>If direct P2P is impossible, a <strong>TURN server</strong> becomes a relay:</p>
<p><strong>Device A → TURN → Device B</strong></p>
<p>TURN is slower but <strong>guarantees connection</strong>.</p>
<p>Required in:</p>
<ul>
<li>Mobile data networks</li>
<li>Corporate networks</li>
<li>Public WiFi</li>
<li>CGNAT (Carrier-grade NAT)</li>
<li>Very strict firewalls</li>
</ul>
<p>TURN is the <strong>last hope</strong> of WebRTC.</p>
<pre><code class="lang-mermaid">flowchart LR
    classDef peer fill:#4da6ff,stroke:#222,stroke-width:1px,color:#000;

    A[Device A]:::peer --&gt;|Encrypted Media| TURN[TURN Server]:::peer
    TURN --&gt;|Encrypted Media| B[Device B]:::peer

    Note["TURN relays RTP/DTLS packets"]:::peer
    TURN -.-&gt; Note
</code></pre>
<h2 id="heading-nat-in-mobile-data-sim-internet"><strong>NAT in Mobile Data (SIM Internet)</strong></h2>
<p>Most people think:</p>
<blockquote>
<p><strong>“I don’t have a router, so I don’t have NAT.”</strong></p>
</blockquote>
<p>Wrong.</p>
<p>Mobile networks use a massive NAT system called:</p>
<h3 id="heading-cgnat-carrier-grade-nat"><strong>CGNAT (Carrier-Grade NAT)</strong></h3>
<p>Your phone actually gets a private IP like <strong>10.x.x.x</strong>, not a real public IP.</p>
<p>Millions of users share a few public IPs.</p>
<p>This makes mobile networks extremely strict:</p>
<ul>
<li>Direct P2P usually fails</li>
<li>STUN candidates may not work</li>
<li>TURN becomes necessary</li>
</ul>
<p>This is why WebRTC sometimes struggles on 4G/5G networks without TURN.</p>
<pre><code class="lang-mermaid">    flowchart LR
Phone["Mobile Phone (10.x.x.x)"] --&gt;|private| CGN["Carrier NAT"]
CGN --&gt;|shared public| Internet["Public Internet"]
Internet --&gt;|routes| Service["Remote Peer"]

Note["Millions of phones share a few public IPs"]
CGN -.-&gt; Note

classDef box fill:#4da6ff,stroke:#222,stroke-width:1px,color:#000;
class Phone,CGN,Internet,Service,Note box;
</code></pre>
<h2 id="heading-ice-connectivity-check-how-candidates-are-tested"><strong>ICE Connectivity Check (how candidates are tested)</strong></h2>
<pre><code class="lang-mermaid">sequenceDiagram
    participant A as Device A
    participant B as Device B

    A-&gt;&gt;B: STUN connectivity check (candidate pair)
    B--&gt;&gt;A: STUN success
    A-&gt;&gt;B: Confirm and switch media path
</code></pre>
<p>This process repeats across candidate pairs until a working pair is found.</p>
<hr />
<h2 id="heading-summary"><strong>Summary</strong></h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Concept</td><td>Meaning</td><td>When Used</td></tr>
</thead>
<tbody>
<tr>
<td><strong>Signaling</strong></td><td>Exchange connection info</td><td>Before connecting</td></tr>
<tr>
<td><strong>SDP</strong></td><td>Media + network description</td><td>Offer/Answer</td></tr>
<tr>
<td><strong>ICE</strong></td><td>Finds best connection path</td><td>NAT traversal</td></tr>
<tr>
<td><strong>Host Candidate</strong></td><td>Local IP</td><td>Same network</td></tr>
<tr>
<td><strong>STUN Candidate</strong></td><td>Public IP discovery</td><td>Normal P2P</td></tr>
<tr>
<td><strong>TURN Candidate</strong></td><td>Relay server</td><td>Strict networks</td></tr>
<tr>
<td><strong>Mobile Data</strong></td><td>Always behind CGNAT</td><td>Requires TURN</td></tr>
</tbody>
</table>
</div><h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>WebRTC is incredibly powerful — enabling P2P communication without needing a central media server.</p>
<p>But to make this work, it must deal with:</p>
<ul>
<li>NAT</li>
<li>Firewalls</li>
<li>Mobile network restrictions</li>
<li>Different internet conditions</li>
</ul>
<p>That’s why WebRTC uses:</p>
<ul>
<li><strong>SDP</strong></li>
<li><strong>ICE</strong></li>
<li><strong>STUN</strong></li>
<li><strong>TURN</strong></li>
</ul>
<p>Together, they create a stable P2P connection under almost every condition.</p>
]]></content:encoded></item><item><title><![CDATA[Learn the Basics of GitHub CLI]]></title><description><![CDATA[1. Installation
Windows

Download installer from the GitHub CLI releases

Or install via Scoop:


scoop install gh

Or via Chocolatey:

choco install gh
macOS

Install via Homebrew:

brew install gh
Linux

Debian/Ubuntu:

sudo apt install gh

Fedora:...]]></description><link>https://blog.iamabhinav.dev/learn-the-basics-of-github-cli</link><guid isPermaLink="true">https://blog.iamabhinav.dev/learn-the-basics-of-github-cli</guid><category><![CDATA[GitHub]]></category><dc:creator><![CDATA[Abhinav Prakash]]></dc:creator><pubDate>Mon, 29 Sep 2025 12:05:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1759198865370/7f4d00c2-63e0-4c99-b4ae-e0c2c16457d5.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-1-installation"><strong>1. Installation</strong></h2>
<h3 id="heading-windows"><strong>Windows</strong></h3>
<ul>
<li><p>Download installer from the <a target="_blank" href="https://github.com/cli/cli/releases">GitHub CLI releases</a></p>
</li>
<li><p>Or install via Scoop:</p>
</li>
</ul>
<p>scoop install gh</p>
<ul>
<li>Or via Chocolatey:</li>
</ul>
<p>choco install gh</p>
<h3 id="heading-macos"><strong>macOS</strong></h3>
<ul>
<li>Install via Homebrew:</li>
</ul>
<p>brew install gh</p>
<h3 id="heading-linux"><strong>Linux</strong></h3>
<ul>
<li>Debian/Ubuntu:</li>
</ul>
<p>sudo apt install gh</p>
<ul>
<li>Fedora:</li>
</ul>
<p>sudo dnf install gh</p>
<ul>
<li>Arch Linux:</li>
</ul>
<p>sudo pacman -S github-cli</p>
<h2 id="heading-2-authenticate-with-github"><strong>2. Authenticate with GitHub</strong></h2>
<p>Run:</p>
<p>gh auth login</p>
<ul>
<li><p>Select GitHub.com or GitHub Enterprise.</p>
</li>
<li><p>Choose HTTPS or SSH as preferred.</p>
</li>
<li><p>Use a personal access token or OAuth for authentication.</p>
</li>
</ul>
<p>Verify authentication:</p>
<p>gh auth status</p>
<h2 id="heading-3-basic-commands"><strong>3. Basic Commands</strong></h2>
<ul>
<li><strong>Version Check:</strong></li>
</ul>
<p>gh --version</p>
<ul>
<li><strong>Configure Editor:</strong></li>
</ul>
<p>gh config set editor "vim"</p>
<h2 id="heading-4-working-with-repositories"><strong>4. Working with Repositories</strong></h2>
<ul>
<li><strong>Create a New Repository:</strong></li>
</ul>
<p>gh repo create my-new-repo --public</p>
<ul>
<li><strong>Clone a Repository:</strong></li>
</ul>
<p>gh repo clone /</p>
<ul>
<li><strong>View Repository Details:</strong></li>
</ul>
<p>gh repo view my-repo --web</p>
<h2 id="heading-5-managing-issues"><strong>5. Managing Issues</strong></h2>
<ul>
<li><strong>List Issues:</strong></li>
</ul>
<p>gh issue list</p>
<ul>
<li><strong>Create a New Issue:</strong></li>
</ul>
<p>gh issue create --title "Bug in login system" --body "User cannot log in with valid credentials."</p>
<ul>
<li><strong>View Issue Details:</strong></li>
</ul>
<p>gh issue view</p>
<h2 id="heading-6-managing-pull-requests-prs"><strong>6. Managing Pull Requests (PRs)</strong></h2>
<ul>
<li><strong>List Pull Requests:</strong></li>
</ul>
<p>gh pr list</p>
<ul>
<li><strong>Create a New PR:</strong></li>
</ul>
<p>gh pr create --title "Fix memory leak" --body "This PR fixes the memory leak in X module."</p>
<ul>
<li><strong>View PR Details:</strong></li>
</ul>
<p>gh pr view</p>
<ul>
<li><strong>Merge a PR:</strong></li>
</ul>
<p>gh pr merge --merge</p>
<h2 id="heading-7-managing-gists"><strong>7. Managing Gists</strong></h2>
<ul>
<li><strong>Create a New Gist:</strong></li>
</ul>
<p>gh gist create file.txt --public</p>
<ul>
<li><strong>List Gists:</strong></li>
</ul>
<p>gh gist list</p>
<ul>
<li><strong>View a Gist:</strong></li>
</ul>
<p>gh gist view</p>
<h2 id="heading-8-github-actions-and-workflows"><strong>8. GitHub Actions and Workflows</strong></h2>
<ul>
<li><strong>List Workflow Runs:</strong></li>
</ul>
<p>gh run list</p>
<ul>
<li><strong>View a Specific Workflow Run:</strong></li>
</ul>
<p>gh run view</p>
<ul>
<li><strong>Trigger a Workflow:</strong></li>
</ul>
<p>gh workflow run</p>
<h2 id="heading-9-github-cli-aliases"><strong>9. GitHub CLI Aliases</strong></h2>
<ul>
<li><strong>Create an Alias:</strong></li>
</ul>
<p>gh alias set myrepos 'repo list --limit 10'</p>
<h2 id="heading-10-logging-out"><strong>10. Logging Out</strong></h2>
<ul>
<li><strong>Log Out:</strong></li>
</ul>
<p>gh auth logout</p>
]]></content:encoded></item><item><title><![CDATA[Step-by-Step LAMP Stack Installation on Ubuntu]]></title><description><![CDATA[Follow these steps to set up a LAMP (Linux, Apache, MySQL, PHP) stack on your Ubuntu server. Copy commands directly and get started quickly! 😎

🛠️ Step 1: Update and Upgrade System
sudo apt update && sudo apt upgrade -y

📌 What to Do: Keep your sy...]]></description><link>https://blog.iamabhinav.dev/lamp-stack-setup-guide</link><guid isPermaLink="true">https://blog.iamabhinav.dev/lamp-stack-setup-guide</guid><category><![CDATA[Linux]]></category><category><![CDATA[apache]]></category><category><![CDATA[PHP]]></category><category><![CDATA[MySQL]]></category><category><![CDATA[LAMP stack project]]></category><category><![CDATA[Ubuntu]]></category><dc:creator><![CDATA[Abhinav Prakash]]></dc:creator><pubDate>Mon, 29 Sep 2025 11:46:47 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1759201143365/5a3fd989-4ae3-4c87-8d86-bd8a90406eb5.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Follow these steps to set up a LAMP (Linux, Apache, MySQL, PHP) stack on your Ubuntu server. Copy commands directly and get started quickly! 😎</p>
<hr />
<h3 id="heading-step-1-update-and-upgrade-system"><strong>🛠️ Step 1: Update and Upgrade System</strong></h3>
<pre><code class="lang-bash">sudo apt update &amp;&amp; sudo apt upgrade -y
</code></pre>
<p>📌 <strong>What to Do</strong>: Keep your system up to date with this single command.</p>
<hr />
<h3 id="heading-step-2-install-apache"><strong>🌐 Step 2: Install Apache</strong></h3>
<pre><code class="lang-bash">sudo apt install apache2 -y
</code></pre>
<p>📌 <strong>What to Do</strong>: Install Apache, the web server.</p>
<ul>
<li><strong>Check Apache Status</strong>:</li>
</ul>
<pre><code class="lang-bash">sudo systemctl status apache2
</code></pre>
<ul>
<li><strong>Test Apache</strong>:<br />  Open your browser and navigate to <code>http://your-server-ip</code> to see the Apache default page.</li>
</ul>
<hr />
<h3 id="heading-step-3-install-mysql"><strong>🐬 Step 3: Install MySQL</strong></h3>
<pre><code class="lang-bash">sudo apt install mysql-server -y
</code></pre>
<p>📌 <strong>What to Do</strong>: Install MySQL for database management.</p>
<ul>
<li><strong>Secure MySQL</strong>:</li>
</ul>
<pre><code class="lang-bash">sudo mysql_secure_installation
</code></pre>
<p>👉 <strong>Detailed Guide</strong>: <a target="_blank" href="https://gist.github.com/Rishiyaduwanshi/06c3594322bd50678b0447d78c86ff67">MySQL Secure Installation</a></p>
<ul>
<li><strong>Login to MySQL</strong>:</li>
</ul>
<pre><code class="lang-bash">sudo mysql
</code></pre>
<hr />
<h3 id="heading-step-4-install-php"><strong>💻 Step 4: Install PHP</strong></h3>
<pre><code class="lang-bash">sudo apt install php libapache2-mod-php php-mysql -y
</code></pre>
<p>📌 <strong>What to Do</strong>: Install PHP and its modules.</p>
<ul>
<li><p><strong>Test PHP</strong>:</p>
<ul>
<li><p>Create a test file:</p>
<pre><code class="lang-bash">  sudo nano /var/www/html/info.php
</code></pre>
</li>
<li><p>Add the following code:</p>
<pre><code class="lang-php">  <span class="hljs-meta">&lt;?php</span>
  phpinfo();
  <span class="hljs-meta">?&gt;</span>
</code></pre>
</li>
<li><p>Visit <code>http://your-server-ip/info.php</code> in your browser to confirm PHP installation.</p>
</li>
</ul>
</li>
</ul>
<hr />
<h3 id="heading-step-5-adjust-firewall-optional"><strong>🛡️ Step 5: Adjust Firewall (Optional)</strong></h3>
<pre><code class="lang-bash">sudo ufw allow <span class="hljs-keyword">in</span> <span class="hljs-string">"Apache Full"</span>
</code></pre>
<p>📌 <strong>What to Do</strong>: Allow Apache through the firewall for proper access.</p>
<hr />
<h3 id="heading-step-6-enable-modules-and-restart-apache"><strong>🔄 Step 6: Enable Modules and Restart Apache</strong></h3>
<pre><code class="lang-bash">sudo a2enmod rewrite  
sudo systemctl restart apache2
</code></pre>
<p>📌 <strong>What to Do</strong>: Enable Apache modules for better functionality.</p>
<hr />
<h3 id="heading-step-7-verify-installation"><strong>✅ Step 7: Verify Installation</strong></h3>
<ul>
<li><p><strong>Apache</strong>: Navigate to <code>http://your-server-ip</code> in your browser.</p>
</li>
<li><p><strong>PHP Info</strong>: Navigate to <code>http://your-server-ip/info.php</code> in your browser.</p>
</li>
</ul>
<hr />
<h3 id="heading-optional-install-phpmyadmin"><strong>📊 Optional: Install phpMyAdmin</strong></h3>
<pre><code class="lang-bash">sudo apt install phpmyadmin -y
</code></pre>
<p>📌 <strong>What to Do</strong>: Install phpMyAdmin to manage MySQL databases via a web interface.</p>
<ul>
<li><p><strong>Configure</strong>: Follow the installation prompts and integrate it with Apache.</p>
</li>
<li><p><strong>Access</strong>: Visit <code>http://your-server-ip/phpmyadmin</code> in your browser.</p>
</li>
</ul>
<hr />
<h3 id="heading-congratulations-your-lamp-stack-is-ready-to-use"><strong>🎉 Congratulations! Your LAMP stack is ready to use.</strong></h3>
]]></content:encoded></item><item><title><![CDATA[Ultimate Cheat Sheet for Java Collections]]></title><description><![CDATA[Ever felt lost in the jungle of Java Collections? Don't worry, I've got your back! This guide will take you through Lists, Sets, Maps, Queues, and Stacks with all their cool methods. Plus, you'll get a super handy table at the end! Let's roll. 💪

📌...]]></description><link>https://blog.iamabhinav.dev/ultimate-cheat-sheet-for-java-collections</link><guid isPermaLink="true">https://blog.iamabhinav.dev/ultimate-cheat-sheet-for-java-collections</guid><category><![CDATA[Java]]></category><category><![CDATA[cheatsheet]]></category><dc:creator><![CDATA[Abhinav Prakash]]></dc:creator><pubDate>Mon, 29 Sep 2025 11:35:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1759202849078/aae1fb46-4dfe-41fc-b339-1154d4b38489.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Ever felt lost in the jungle of Java Collections? Don't worry, I've got your back! This guide will take you through <strong>Lists, Sets, Maps, Queues, and Stacks</strong> with all their cool methods. Plus, you'll get a <strong>super handy table</strong> at the end! Let's roll. 💪</p>
<hr />
<h2 id="heading-1-list-ordered-amp-duplicates-allowed"><strong>📌 1. List – Ordered &amp; Duplicates Allowed</strong></h2>
<p>Think of a <strong>List</strong> as a VIP guest list at a party. Everyone comes in a specific order, and duplicates are totally fine. You can <strong>add, remove, and find elements at specific positions.</strong></p>
<h3 id="heading-arraylist-the-fast-one"><strong>🍕</strong> <code>ArrayList&lt;E&gt;</code> – The Fast One</h3>
<ul>
<li><p><strong>Best for:</strong> Fast random access, but slow insertions/removals.</p>
</li>
<li><p><strong>Think of it as:</strong> A <strong>resizable array</strong>.</p>
</li>
</ul>
<p><strong>Common Methods:</strong></p>
<pre><code class="lang-java">ArrayList&lt;String&gt; list = <span class="hljs-keyword">new</span> ArrayList&lt;&gt;();
list.add(<span class="hljs-string">"A"</span>);          <span class="hljs-comment">// Adds at the end</span>
list.add(<span class="hljs-number">1</span>, <span class="hljs-string">"B"</span>);       <span class="hljs-comment">// Adds at index 1</span>
list.get(<span class="hljs-number">0</span>);            <span class="hljs-comment">// Returns "A"</span>
list.set(<span class="hljs-number">1</span>, <span class="hljs-string">"C"</span>);       <span class="hljs-comment">// Replaces "B" with "C"</span>
list.remove(<span class="hljs-number">1</span>);         <span class="hljs-comment">// Removes index 1</span>
list.contains(<span class="hljs-string">"A"</span>);     <span class="hljs-comment">// Returns true</span>
list.indexOf(<span class="hljs-string">"A"</span>);      <span class="hljs-comment">// Returns index of "A"</span>
list.lastIndexOf(<span class="hljs-string">"A"</span>);  <span class="hljs-comment">// Returns last occurrence of "A"</span>
list.isEmpty();         <span class="hljs-comment">// Returns true if empty</span>
list.size();            <span class="hljs-comment">// Returns size</span>
list.clear();           <span class="hljs-comment">// Removes all elements</span>
</code></pre>
<hr />
<h3 id="heading-linkedlist-the-smooth-operator"><strong>🛤</strong> <code>LinkedList&lt;E&gt;</code> – The Smooth Operator</h3>
<ul>
<li><p><strong>Best for:</strong> Fast insertions/deletions, but slow random access.</p>
</li>
<li><p><strong>Think of it as:</strong> A <strong>train with connected compartments</strong>.</p>
</li>
</ul>
<p><strong>Common Methods:</strong></p>
<pre><code class="lang-java">LinkedList&lt;Integer&gt; linkedList = <span class="hljs-keyword">new</span> LinkedList&lt;&gt;();
linkedList.add(<span class="hljs-number">10</span>);  
linkedList.addFirst(<span class="hljs-number">5</span>);  <span class="hljs-comment">// Adds at the beginning</span>
linkedList.addLast(<span class="hljs-number">20</span>);  <span class="hljs-comment">// Adds at the end</span>
linkedList.get(<span class="hljs-number">1</span>);       <span class="hljs-comment">// Returns element at index 1</span>
linkedList.removeFirst(); <span class="hljs-comment">// Removes first element</span>
linkedList.removeLast();  <span class="hljs-comment">// Removes last element</span>
linkedList.peekFirst();   <span class="hljs-comment">// Returns first element without removing</span>
linkedList.peekLast();    <span class="hljs-comment">// Returns last element without removing</span>
linkedList.isEmpty();     <span class="hljs-comment">// Returns true if empty</span>
linkedList.size();        <span class="hljs-comment">// Returns size</span>
</code></pre>
<hr />
<h2 id="heading-2-set-unique-elements-only-no-duplicates-allowed"><strong>📌 2. Set – Unique Elements Only (No Duplicates Allowed!)</strong></h2>
<p>A <strong>Set</strong> is like your <strong>ex’s blocklist</strong>—every name is unique, and order doesn't matter (except for TreeSet).</p>
<h3 id="heading-hashset-the-speed-demon"><strong>🔥</strong> <code>HashSet&lt;E&gt;</code> – The Speed Demon</h3>
<ul>
<li><p><strong>Best for:</strong> Super-fast searches.</p>
</li>
<li><p><strong>Think of it as:</strong> A <strong>randomly ordered bag of unique elements</strong>.</p>
</li>
</ul>
<p><strong>Common Methods:</strong></p>
<pre><code class="lang-java">HashSet&lt;String&gt; set = <span class="hljs-keyword">new</span> HashSet&lt;&gt;();
set.add(<span class="hljs-string">"Java"</span>);       <span class="hljs-comment">// Adds element</span>
set.add(<span class="hljs-string">"Python"</span>);
set.remove(<span class="hljs-string">"Java"</span>);    <span class="hljs-comment">// Removes "Java"</span>
set.contains(<span class="hljs-string">"Python"</span>); <span class="hljs-comment">// Returns true</span>
set.isEmpty();         <span class="hljs-comment">// Returns true if empty</span>
set.size();            <span class="hljs-comment">// Returns number of elements</span>
set.clear();           <span class="hljs-comment">// Removes all elements</span>
</code></pre>
<hr />
<h3 id="heading-treeset-the-sorted-scholar"><strong>🌲</strong> <code>TreeSet&lt;E&gt;</code> – The Sorted Scholar</h3>
<ul>
<li><p><strong>Best for:</strong> When you need elements in <strong>sorted order</strong>.</p>
</li>
<li><p><strong>Think of it as:</strong> A <strong>self-sorting list</strong>.</p>
</li>
</ul>
<p><strong>Common Methods:</strong></p>
<pre><code class="lang-java">TreeSet&lt;Integer&gt; treeSet = <span class="hljs-keyword">new</span> TreeSet&lt;&gt;();
treeSet.add(<span class="hljs-number">10</span>);
treeSet.add(<span class="hljs-number">5</span>);
treeSet.add(<span class="hljs-number">20</span>);
treeSet.first();     <span class="hljs-comment">// Returns smallest element (5)</span>
treeSet.last();      <span class="hljs-comment">// Returns largest element (20)</span>
treeSet.higher(<span class="hljs-number">10</span>);  <span class="hljs-comment">// First element greater than 10</span>
treeSet.lower(<span class="hljs-number">10</span>);   <span class="hljs-comment">// First element smaller than 10</span>
treeSet.remove(<span class="hljs-number">5</span>);   <span class="hljs-comment">// Removes 5</span>
</code></pre>
<hr />
<h2 id="heading-3-map-key-value-storage"><strong>📌 3. Map – Key-Value Storage</strong></h2>
<p>A <strong>Map</strong> is like a <strong>real-life dictionary</strong>—you look up a <strong>key</strong> to find its <strong>value</strong>.</p>
<h3 id="heading-hashmap-the-fast-look-up-boss"><strong>🗺</strong> <code>HashMap&lt;K, V&gt;</code> – The Fast Look-up Boss</h3>
<ul>
<li><p><strong>Best for:</strong> Fast key-value lookups, but unordered.</p>
</li>
<li><p><strong>Think of it as:</strong> A <strong>messy but super-fast key-value storage</strong>.</p>
</li>
</ul>
<p><strong>Common Methods:</strong></p>
<pre><code class="lang-java">HashMap&lt;Integer, String&gt; map = <span class="hljs-keyword">new</span> HashMap&lt;&gt;();
map.put(<span class="hljs-number">1</span>, <span class="hljs-string">"One"</span>);        <span class="hljs-comment">// Adds key-value pair</span>
map.put(<span class="hljs-number">2</span>, <span class="hljs-string">"Two"</span>);
map.get(<span class="hljs-number">1</span>);               <span class="hljs-comment">// Returns "One"</span>
map.remove(<span class="hljs-number">2</span>);            <span class="hljs-comment">// Removes key 2</span>
map.containsKey(<span class="hljs-number">1</span>);       <span class="hljs-comment">// Returns true</span>
map.containsValue(<span class="hljs-string">"Two"</span>); <span class="hljs-comment">// Returns false (since we removed it)</span>
map.keySet();             <span class="hljs-comment">// Returns all keys</span>
map.values();             <span class="hljs-comment">// Returns all values</span>
map.entrySet();           <span class="hljs-comment">// Returns key-value pairs</span>
map.getOrDefault(<span class="hljs-number">10</span>, <span class="hljs-string">"Not Found"</span>);  <span class="hljs-comment">// If key 10 not present, returns "Not Found"</span>
</code></pre>
<hr />
<h3 id="heading-treemap-the-sorted-organizer"><strong>🌳</strong> <code>TreeMap&lt;K, V&gt;</code> – The Sorted Organizer</h3>
<ul>
<li><p><strong>Best for:</strong> Keeping keys <strong>sorted</strong>.</p>
</li>
<li><p><strong>Think of it as:</strong> A <strong>well-organized, auto-sorting dictionary</strong>.</p>
</li>
</ul>
<p><strong>Common Methods:</strong></p>
<pre><code class="lang-java">TreeMap&lt;Integer, String&gt; treeMap = <span class="hljs-keyword">new</span> TreeMap&lt;&gt;();
treeMap.put(<span class="hljs-number">3</span>, <span class="hljs-string">"Three"</span>);
treeMap.put(<span class="hljs-number">1</span>, <span class="hljs-string">"One"</span>);
treeMap.put(<span class="hljs-number">2</span>, <span class="hljs-string">"Two"</span>);
treeMap.firstKey();   <span class="hljs-comment">// Returns 1</span>
treeMap.lastKey();    <span class="hljs-comment">// Returns 3</span>
treeMap.higherKey(<span class="hljs-number">2</span>); <span class="hljs-comment">// Returns 3 (next larger key)</span>
treeMap.lowerKey(<span class="hljs-number">2</span>);  <span class="hljs-comment">// Returns 1 (previous smaller key)</span>
treeMap.remove(<span class="hljs-number">1</span>);    <span class="hljs-comment">// Removes key 1</span>
treeMap.getOrDefault(<span class="hljs-number">10</span>, <span class="hljs-string">"Not Found"</span>);  <span class="hljs-comment">// If key 10 not present, returns "Not Found"</span>
</code></pre>
<hr />
<h2 id="heading-4-queue-amp-stack-fifo-amp-lifo-masters"><strong>📌 4. Queue &amp; Stack – FIFO &amp; LIFO Masters</strong></h2>
<h3 id="heading-queue-the-waiting-line"><strong>🎟</strong> <code>Queue&lt;E&gt;</code> – The Waiting Line</h3>
<ul>
<li><strong>Best for:</strong> First-In-First-Out (FIFO) operations.</li>
</ul>
<p><strong>Common Methods:</strong></p>
<pre><code class="lang-java">Queue&lt;String&gt; queue = <span class="hljs-keyword">new</span> LinkedList&lt;&gt;();
queue.add(<span class="hljs-string">"A"</span>);   <span class="hljs-comment">// Adds to queue</span>
queue.poll();     <span class="hljs-comment">// Removes and returns front element</span>
queue.peek();     <span class="hljs-comment">// Shows front element without removing</span>
queue.size();     <span class="hljs-comment">// Returns queue size</span>
</code></pre>
<hr />
<h3 id="heading-priorityqueue-the-smart-sorter"><strong>🎯</strong> <code>PriorityQueue&lt;E&gt;</code> – The Smart Sorter</h3>
<ul>
<li><p><strong>Best for:</strong> When you need <strong>automatic sorting</strong> while inserting elements.</p>
</li>
<li><p><strong>Think of it as:</strong> A <strong>VIP entry system</strong>—smallest (or largest) element always gets out first!</p>
</li>
</ul>
<p><strong>Common Methods:</strong></p>
<pre><code class="lang-java">PriorityQueue&lt;Integer&gt; pq = <span class="hljs-keyword">new</span> PriorityQueue&lt;&gt;(); <span class="hljs-comment">// Min-Heap (Default)</span>
pq.add(<span class="hljs-number">5</span>);
pq.add(<span class="hljs-number">1</span>);
pq.add(<span class="hljs-number">3</span>);
pq.poll();    <span class="hljs-comment">// Removes &amp; returns the smallest element (1)</span>
pq.peek();    <span class="hljs-comment">// Shows the smallest element without removing (3)</span>
pq.size();    <span class="hljs-comment">// Returns size</span>
pq.isEmpty(); <span class="hljs-comment">// Checks if empty</span>

<span class="hljs-comment">// Max-Heap using Comparator</span>
PriorityQueue&lt;Integer&gt; maxHeap = <span class="hljs-keyword">new</span> PriorityQueue&lt;&gt;(Collections.reverseOrder());
maxHeap.add(<span class="hljs-number">5</span>);
maxHeap.add(<span class="hljs-number">1</span>);
maxHeap.add(<span class="hljs-number">3</span>);
maxHeap.poll(); <span class="hljs-comment">// Removes &amp; returns the largest element (5)</span>
</code></pre>
<p><strong>💡 Default = Min-Heap (smallest comes out first). If you want a Max-Heap, use</strong> <code>Collections.reverseOrder()</code>. 🚀</p>
<h3 id="heading-stack-the-last-minute-cramming-machine"><strong>🧱</strong> <code>Stack&lt;E&gt;</code> – The Last-Minute Cramming Machine</h3>
<ul>
<li><strong>Best for:</strong> Last-In-First-Out (LIFO) operations.</li>
</ul>
<p><strong>Common Methods:</strong></p>
<pre><code class="lang-java">Stack&lt;String&gt; stack = <span class="hljs-keyword">new</span> Stack&lt;&gt;();
stack.push(<span class="hljs-string">"Book"</span>);   <span class="hljs-comment">// Adds to stack</span>
stack.pop();         <span class="hljs-comment">// Removes and returns top element</span>
stack.peek();        <span class="hljs-comment">// Shows top element without removing</span>
stack.size();        <span class="hljs-comment">// Returns stack size</span>
</code></pre>
<hr />
<h2 id="heading-master-table-java-collections-at-a-glance"><strong>📊 Master Table – Java Collections at a Glance</strong></h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Type</strong></td><td><strong>Best For</strong></td><td><strong>Allows Duplicates?</strong></td><td><strong>Sorted?</strong></td><td><strong>Fastest For?</strong></td></tr>
</thead>
<tbody>
<tr>
<td><code>ArrayList</code></td><td>Random access</td><td>✅ Yes</td><td>❌ No</td><td>Fast retrieval</td></tr>
<tr>
<td><code>LinkedList</code></td><td>Insertions/deletions</td><td>✅ Yes</td><td>❌ No</td><td>Fast modifications</td></tr>
<tr>
<td><code>HashSet</code></td><td>Unique elements</td><td>❌ No</td><td>❌ No</td><td>Fast lookups</td></tr>
<tr>
<td><code>TreeSet</code></td><td>Sorted unique elements</td><td>❌ No</td><td>✅ Yes</td><td>Ordered retrieval</td></tr>
<tr>
<td><code>HashMap</code></td><td>Key-value pairs</td><td>❌ Keys unique</td><td>❌ No</td><td>Fast key-value lookup</td></tr>
<tr>
<td><code>TreeMap</code></td><td>Sorted key-value pairs</td><td>❌ Keys unique</td><td>✅ Yes</td><td>Sorted key retrieval</td></tr>
<tr>
<td><code>Queue</code></td><td>FIFO operations</td><td>✅ Yes</td><td>❌ No</td><td>First-in-first-out processing</td></tr>
<tr>
<td><code>Stack</code></td><td>LIFO operations</td><td>✅ Yes</td><td>❌ No</td><td>Last-in-first-out processing</td></tr>
</tbody>
</table>
</div><hr />
<h3 id="heading-bonus-table-similar-methods-across-collections"><strong>🤩 Bonus Table – Similar Methods Across Collections</strong></h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Method</strong></td><td><strong>ArrayList</strong></td><td><strong>LinkedList</strong></td><td><strong>HashSet</strong></td><td><strong>TreeSet</strong></td><td><strong>HashMap</strong></td><td><strong>TreeMap</strong></td></tr>
</thead>
<tbody>
<tr>
<td><code>add()</code></td><td>✅</td><td>✅</td><td>✅</td><td>✅</td><td>✅ (<code>put</code>)</td><td>✅ (<code>put</code>)</td></tr>
<tr>
<td><code>remove()</code></td><td>✅</td><td>✅</td><td>✅</td><td>✅</td><td>✅</td><td>✅</td></tr>
<tr>
<td><code>contains()</code></td><td>✅</td><td>✅</td><td>✅</td><td>✅</td><td>✅ (<code>containsKey</code>)</td><td>✅ (<code>containsKey</code>)</td></tr>
<tr>
<td><code>size()</code></td><td>✅</td><td>✅</td><td>✅</td><td>✅</td><td>✅</td><td>✅</td></tr>
<tr>
<td><code>clear()</code></td><td>✅</td><td>✅</td><td>✅</td><td>✅</td><td>✅</td><td>✅</td></tr>
</tbody>
</table>
</div><hr />
<h3 id="heading-wrap-up"><strong>😎 Wrap-Up</strong></h3>
<p>And that's a <strong>wrap</strong> on Java Collections! 🚀 Now, whether you're dealing with lists, sets, maps, queues, or stacks, you've got this <strong>handy cheat sheet</strong> to refer to anytime. <strong>Bookmark it, star it, share it!</strong> 🎯</p>
]]></content:encoded></item><item><title><![CDATA[Java References Made Easy: Explore the Box Analogy]]></title><description><![CDATA[Intro
If you want to fully understand Java classes, objects, and linked list references, this blog is for you.I used to be confused about when to use new and how references work. Let’s clear it using the box analogy.
The new keyword
Node n = new Node...]]></description><link>https://blog.iamabhinav.dev/java-references-made-easy-explore-the-box-analogy</link><guid isPermaLink="true">https://blog.iamabhinav.dev/java-references-made-easy-explore-the-box-analogy</guid><category><![CDATA[Java]]></category><dc:creator><![CDATA[Abhinav Prakash]]></dc:creator><pubDate>Mon, 29 Sep 2025 11:30:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1759203426576/fea2ad23-193a-4aa2-9ad5-f0052370127a.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-intro">Intro</h2>
<p>If you want to fully understand <strong>Java classes, objects, and linked list references</strong>, this blog is for you.<br />I used to be confused about when to use <code>new</code> and how references work. Let’s clear it using the <strong>box analogy</strong>.</p>
<h2 id="heading-the-new-keyword">The <code>new</code> keyword</h2>
<pre><code class="lang-java">Node n = <span class="hljs-keyword">new</span> Node(<span class="hljs-number">10</span>);
</code></pre>
<ul>
<li><p><strong>Right side (</strong><code>new Node(10)</code>) → creates a <strong>new box (object)</strong> in memory with <code>data=10</code> and <code>next=null</code></p>
</li>
<li><p><strong>Left side (</strong><code>n</code>) → a <strong>reference variable</strong> storing the box’s <strong>address</strong></p>
</li>
</ul>
<p><strong>Analogy:</strong><br /><code>n</code> holds the address of a box with <code>10</code> inside.</p>
<pre><code class="lang-plaintext">[ data=10 | next=null ]  &lt;-- box
       ^
       |
       n
</code></pre>
<hr />
<h2 id="heading-reference-without-new">Reference without <code>new</code></h2>
<pre><code class="lang-java">Node temp = head;
</code></pre>
<ul>
<li><p>No new box is created.</p>
</li>
<li><p><code>temp</code> just copies the <strong>address</strong> that <code>head</code> has.</p>
</li>
<li><p>Both <code>head</code> and <code>temp</code> point to the <strong>same object</strong>.</p>
</li>
</ul>
<pre><code class="lang-plaintext">[ data=5 | next=null ]  &lt;-- box
       ^       ^
       |       |
      head    temp
</code></pre>
<hr />
<h2 id="heading-linked-list-example">Linked List Example</h2>
<pre><code class="lang-java">Node head = <span class="hljs-keyword">new</span> Node(<span class="hljs-number">5</span>);      <span class="hljs-comment">// new box1</span>
Node temp = head;             <span class="hljs-comment">// temp points to box1</span>
temp.data = <span class="hljs-number">20</span>;               <span class="hljs-comment">// update box1's data</span>
temp.next = <span class="hljs-keyword">new</span> Node(<span class="hljs-number">30</span>);     <span class="hljs-comment">// create new box2 and link it</span>
</code></pre>
<p><strong>Memory:</strong></p>
<pre><code class="lang-plaintext">[ data=20 | next--&gt; ]  &lt;-- box1
       ^       ^
       |       |
      head    temp
                 \
                  [ data=30 | next=null ]  &lt;-- box2
</code></pre>
<p><strong>Linked List:</strong></p>
<pre><code class="lang-plaintext">head → 20 → 30 → null
</code></pre>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759141662339/3037b0db-090f-4310-80cf-638e43b9ce4e.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-rule-of-thumb">Rule of Thumb</h2>
<ul>
<li><p><strong>Use</strong> <code>new</code> → When you want a <strong>new object/box</strong></p>
</li>
<li><p><strong>Do not use</strong> <code>new</code> → When you want to <strong>point to an existing object/box</strong></p>
</li>
</ul>
<hr />
<h2 id="heading-tricky-example">Tricky Example</h2>
<pre><code class="lang-java">Node temp = head;
temp = <span class="hljs-keyword">new</span> Node(<span class="hljs-number">50</span>);
</code></pre>
<ul>
<li><p><code>temp</code> now points to a <strong>new box</strong></p>
</li>
<li><p><code>head</code> still points to the <strong>old box</strong></p>
</li>
</ul>
<hr />
<h2 id="heading-conclusion">Conclusion</h2>
<ol>
<li><p><code>new</code> = create new box</p>
</li>
<li><p><strong>No</strong> <code>new</code> = copy existing box’s address</p>
</li>
<li><p>Linked list traversal uses <strong>references</strong>, insertion uses <strong>new</strong></p>
</li>
</ol>
<h3 id="heading-tldr">TL;DR</h3>
<p>Understanding Java <strong>references and</strong> <code>new</code> keyword is just about <strong>knowing the difference between a box’s content and its address</strong>.</p>
<ul>
<li><p><code>new</code> = create fresh box</p>
</li>
<li><p>Reference = point to existing box</p>
</li>
</ul>
<hr />
]]></content:encoded></item></channel></rss>