<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dio Pastina Heartlin B on Medium]]></title>
        <description><![CDATA[Stories by Dio Pastina Heartlin B on Medium]]></description>
        <link>https://medium.com/@heartlinbenit?source=rss-d00602accd9b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rNroiI-TAvq0884fCIn0Ng.jpeg</url>
            <title>Stories by Dio Pastina Heartlin B on Medium</title>
            <link>https://medium.com/@heartlinbenit?source=rss-d00602accd9b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 11:04:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@heartlinbenit/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[DSA Simplified: #2 Sliding Window]]></title>
            <link>https://medium.com/@heartlinbenit/dsa-simplified-2-sliding-window-48a36683793e?source=rss-d00602accd9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/48a36683793e</guid>
            <category><![CDATA[sliding-window-algorithm]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[time-complexity]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Dio Pastina Heartlin B]]></dc:creator>
            <pubDate>Sun, 26 Jul 2026 06:43:36 GMT</pubDate>
            <atom:updated>2026-07-26T06:43:36.490Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rhUltAULxnRlJXbBtApHpg.png" /></figure><p>When I first came across the <strong>Sliding Window</strong> technique, it felt like one of those concepts that everyone else understood except me.</p><p>I’d watch people solve problems in minutes while I was still writing nested loops and wondering why my solution was timing out.</p><p>But slowly, I realized that it’s not magic but it’s just about <strong>reusing work</strong> instead of recalculating every time. That’s when things started clicking.</p><p>So let’s break it down step by step.</p><h3>What is Sliding Window?</h3><p>Sliding window is a technique used for <strong>subarray or substring problems</strong>.<br> Instead of recomputing sums, counts, or conditions for every subarray, we just:</p><ul><li>Add the new element that enters the window</li><li>Remove the old element that leaves the window</li></ul><p>This way, the window<strong><em> “slides”</em></strong> forward in O(n).</p><h4>Types of Sliding Window</h4><p>We can split problems into two main categories:</p><ol><li><strong>Fixed Size Window</strong> : Window size is constant.</li><li><strong>Variable Size Window :</strong>Window expands and contracts depending on conditions.</li></ol><h3>Fixed Size Sliding Window</h3><p>Think of looking at the world through a <strong>camera frame that never changes size</strong>.<br> If the frame can only fit 4 <strong>elements</strong> at a time, you keep sliding it forward, one step at a time.</p><p>Example:<strong><em> Find the maximum sum of 4 continuous numbers in an array.</em></strong></p><ul><li><strong><em>Naive way</em></strong> → take every possible group of 4 and add them up (slow).</li><li><strong><em>Sliding Window</em></strong> → add the first 4, then when you move forward, just <strong>subtract the element going out</strong> and <strong>add the new one coming in</strong> (fast).</li></ul><p>The window size = fixed (always 4 in this case).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bRMOtY6jvtFGtdUuiOHt9w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6tR-Qn-2HOFY0xAea5tYlg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SGO24b8pn55rermcPuCxdQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ihX3Z6x7Oj2DXdCrFqc1uA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n1mLnVXu5pa2a3fTnOKiYA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G9-ts9d7zqETBd5hcRwPpw.png" /></figure><p><strong><em>Notice something?</em></strong></p><p>We never recalculate the entire sum. We simply update it.</p><p>That’s why <strong>Sliding Window</strong> is so <strong>fast</strong>.</p><h3>Variable Size Sliding Window</h3><p>Now imagine a <strong>rubber band frame</strong> that can <strong>stretch or shrink</strong> depending on the situation.<br> Sometimes you need a bigger window, sometimes smaller.</p><p><strong>Example:</strong> Longest substring without repeating characters.</p><p><strong><em>Naive way</em></strong> → check <strong>all possible substrings</strong> one by one, and for each substring check if it has duplicates.</p><p><strong><em>Sliding Window</em></strong> →</p><ul><li>Start with an empty window.</li><li>Keep <strong>expanding</strong> by adding new characters until you hit a duplicate.</li><li>Then <strong>shrink</strong> the window from the left until the rule is fixed.</li></ul><p>the more you shrink the sliding window the less will be the sum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*A8i6TyVWGOkUzjRv9maT4w.png" /></figure><p>We’ll use two pointers <strong><em>left </em></strong>and <strong><em>right </em></strong>to representing thesliding window. Initially,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/209/1*tj5YuLL4XVlz4EoBHNPyeQ.png" /></figure><p>We keep expanding the window until we find a duplicate. <br>Add a,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*z932GW-TPF5ba-y6xlGGPA.png" /></figure><p>Add b,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/1*ZiaXugZI6gcP45fFeNn09A.png" /></figure><p>Add c,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/1*o3t7rfbmBeRukI7uxXZEPQ.png" /></figure><p>Now the next character is <strong>a</strong>. Duplicate found!</p><p>Oops! <strong>a</strong> is already inside the window.</p><p>Instead of starting over, we <strong>shrink the window from the left</strong> until the duplicate is removed.</p><p>Remove <strong>a</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*7G4CVQQ_LHXwPekZLbQc1A.png" /></figure><p>Now we can safely add the new <strong>a</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*NLaSu7rYXWTd_Pg7Stx45Q.png" /></figure><p>We continue sliding. Next character is <strong>b</strong>. <strong>Duplicate again!</strong></p><p>Remove characters from the left until <strong>b</strong> is no longer inside the window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/1*ZGzAc20Ibe5tBuMfKM8HlA.png" /></figure><p>Add the new<strong> b</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*GMoDiJ8vFg7GgBTh72DsQw.png" /></figure><p>Now the next character is <strong>c.</strong></p><p>Remove characters from the left until <strong>c</strong> is no longer inside the window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*kxyOpxH9e5zRA_dIp-miVQ.png" /></figure><p>Add the new <strong>c</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*iesxzolSl0Zoag_E0QP0UA.png" /></figure><p>Moving forward again we encounter a duplicate,<strong> b</strong>.</p><p>Remove characters from the left until <strong>b</strong> is no longer inside the window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*NGobxn3XEh0pOTTTNwOmDA.png" /></figure><p>Still duplicate present so shrink the window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*yOFUZVuD5Gqdo5IFLPj7UA.png" /></figure><p>Longest length so far remains as <strong>3</strong>. Add the new <strong>b.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*jCmsGr6Szlp3MgBS6ra2fA.png" /></figure><p>Again we encounter a duplicate.</p><p>Remove characters from the left until <strong>b</strong> is no longer inside the window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/216/1*z5-m4XQh7QJocNvSn0HnbQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/209/1*tj5YuLL4XVlz4EoBHNPyeQ.png" /></figure><p>Now add the new<strong> b</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/230/1*xhewyZ1KTqHWgZWtn7Lm3w.png" /></figure><p>We’ve now reached the end of the string.</p><p>The longest substring without repeating characters is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/124/1*st0eNSoLifbr0ubiCRW6ZA.png" /></figure><p>Answer = 3</p><h3>How Do You Know Sliding Window Can Be Used?</h3><p>Whenever you see these clues, Sliding Window should come to mind:</p><ul><li>The problem involves a <strong>contiguous</strong> subarray or substring.</li><li>You’re checking every possible window.</li><li>You’re recalculating the same information repeatedly.</li><li>The window either has a fixed size or changes according to a condition.</li></ul><p>If you notice these patterns, there’s a good chance Sliding Window is the right approach.</p><h3>Time Complexity</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*N12GCHiHZsPb7b8G6HXdjg.png" /></figure><p><strong>Why?</strong></p><p>Because every element enters the window once and leaves it once.</p><p>No unnecessary recalculations.</p><h3>Final Thoughts</h3><p>When I first learned Sliding Window, I thought it was a complicated algorithm.</p><p>It isn’t.</p><p>It’s simply a smarter way of thinking.</p><p>The next time you see a question involving <strong>contiguous elements</strong>, don’t immediately reach for nested loops.</p><p>Ask yourself one question:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*f25m-8vI7AZaTQ8qMs40Uw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48a36683793e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DSA Simplified: #1 Beginner’s Guide to Coding Pattern Recognition]]></title>
            <link>https://medium.com/@heartlinbenit/dsa-simplified-1beginners-guide-to-coding-pattern-recognition-2270f8041e09?source=rss-d00602accd9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2270f8041e09</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-dsa]]></category>
            <category><![CDATA[problem-solving]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Dio Pastina Heartlin B]]></dc:creator>
            <pubDate>Mon, 25 Aug 2025 15:23:59 GMT</pubDate>
            <atom:updated>2025-08-25T15:24:19.247Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ULlZhC4LCFLSz0Ic-eARUw.png" /></figure><p>When I first started with DSA, I was fascinated by all the fancy names like the sliding window, two pointers, backtracking, dynamic programming. It felt like I had to memorize a thousand different tricks.</p><p>But while experimenting with problems, I noticed something: I often started with a <strong>naive approach</strong>, then while optimizing step by step, I ended up finding a <strong>more efficient approach</strong>. Over time, I realized that these optimizations were not random rather they were <strong>repeating patterns</strong>.</p><p>If you solve enough of them, your brain starts to form a kind of <strong>muscle memory</strong>. You look at a problem, and it clicks:<em> “Ah, this looks like a sliding window problem” </em>or <em>“This feels like two pointers.”</em></p><p>That’s when problem-solving becomes easier, faster, and way more efficient.<br> Instead of memorizing every solution, you start <strong>recognizing patterns</strong>.</p><p>In this post, I’ll share the most common <strong>beginner-friendly DSA patterns</strong> you should know. These patterns repeat so often that once you spot them, half the battle is already won.</p><h3>Beginner-Friendly Coding Patterns</h3><h3>1. Sliding Window</h3><p>Imagine looking through a small “window” that slides over an array/string even when window size is fixed or variable.<br>Good for problems that ask about <strong>subarrays or substrings</strong>.</p><ul><li><strong>Naive:</strong> Check every subarray and calculate sum (O(n*k)).</li><li><strong>Optimal:</strong> Slide the window, reuse previous sum (O(n)).<br> <strong>Example:</strong> Largest sum of numbers in any 3 continuous elements.</li></ul><h3>2. Two Pointers</h3><p>Use two pointers (start and end) to scan from both sides. <br>Works best on sorted arrays/strings, but also helps in tasks like reversing or partitioning.</p><ul><li><strong>Naive:</strong> Try all pairs → O(n²).</li><li><strong>Optimal:</strong> Use two pointers → O(n).<br> <strong>Example:</strong> Do two numbers add up to 10?</li></ul><h3>3. Fast &amp; Slow Pointers</h3><p>Like a rabbit and a turtle running in a circle.<br>If the rabbit (fast) and turtle (slow) meet → there’s a cycle.</p><ul><li><strong>Naive:</strong> Store visited nodes in a set (O(n) space).</li><li><strong>Optimal:</strong> Use fast &amp; slow pointers (O(1) space).<br> <strong>Example:</strong> Detect loop in a linked list.</li></ul><h3>4. Kadane’s Algorithm</h3><p>Keep track of the “best sum so far” as you move through the array.<br>Helps find the maximum sum of any subarray and works for arrays with positive and negative numbers..</p><ul><li><strong>Naive:</strong> Try all subarrays.</li><li><strong>Optimal:</strong> Carry forward best sum in one pass.<br> <strong>Example:</strong> Maximum subarray sum.</li></ul><h3>5. Prefix Sum</h3><p>Pre-store sums so you don’t add again and again.</p><ul><li><strong>Naive:</strong> Add each range from scratch.</li><li><strong>Optimal:</strong> Precompute prefix sums → O(1) queries.<br> <strong>Example:</strong> If 1+2+3+4=10, then sum prefix[4] — prefix[1] = 10–1 = 9.</li></ul><h3>6. HashMap / Hashing</h3><p>Think of it as a quick dictionary that remembers counts or positions.</p><ul><li><strong>Naive:</strong> Scan entire array every time.</li><li><strong>Optimal:</strong> Store counts/positions in a HashMap.<br> <strong>Example:</strong> First non-repeating character in a string.</li></ul><h3>7. Sorting + Binary Search</h3><p>First sort the data. Then cut the search space in half each time.</p><ul><li><strong>Naive:</strong> Linear search → O(n).</li><li><strong>Optimal:</strong> Binary search → O(log n).<br> <strong>Example:</strong> Guess a number between 1–100 by halving the range.</li></ul><h3>8. Recursion &amp; Backtracking</h3><p>Solve big problems by breaking them into smaller ones.<br>Backtracking = try a path, if it doesn’t work, go back and try another.</p><ul><li><strong>Naive:</strong> Manually list all possibilities.</li><li><strong>Optimal:</strong> Use recursion to explore all systematically.<br> <strong>Example:</strong> Generate all subsets of {a, b, c}, sudoku solving, n-queens.</li></ul><h3>9. Stack Problems</h3><p>Stack works like a pile of plates: last in, first out.<br> Great for brackets, undo, or next greater element.</p><ul><li><strong>Naive:</strong> Nested loops to compare elements.</li><li><strong>Optimal:</strong> Stack to track &amp; solve efficiently.<br> <strong>Example:</strong> Check if “{[()]}” is balanced.</li></ul><h3>10. Greedy Approach</h3><p>At each step, take the best available option.<br> Works when <strong>local best = global best</strong>.</p><ul><li><strong>Naive:</strong> Try all combinations.</li><li><strong>Optimal:</strong> Take best option at each step.<br> <strong>Example:</strong> To make ₹27 with {10, 5, 1}, take 2 tens, 1 five, 2 ones.</li></ul><p>These 10 patterns are the backbone of most beginner-level DSA problems. Once you start recognizing them, solving questions becomes less about memorizing and more about applying the right approach. In this series <strong>DSA Simplified</strong>, I’ll be solving problems step by step from naïve to optimal using Java, so you can clearly see how each pattern works in practice. Stay tuned, and let’s build that problem-solving muscle together.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2270f8041e09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Variables in Java]]></title>
            <link>https://medium.com/@heartlinbenit/variables-in-java-70c80249e6b6?source=rss-d00602accd9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/70c80249e6b6</guid>
            <category><![CDATA[static-variable]]></category>
            <category><![CDATA[variables]]></category>
            <category><![CDATA[instance-variables]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java8]]></category>
            <dc:creator><![CDATA[Dio Pastina Heartlin B]]></dc:creator>
            <pubDate>Thu, 03 Jul 2025 14:00:19 GMT</pubDate>
            <atom:updated>2025-07-03T14:00:19.906Z</atom:updated>
            <content:encoded><![CDATA[<p>Variables are like labeled boxes where your Java program stores data — names, numbers, anything you need. They’re the first thing you learn in programming because they’re used everywhere. In this post, we’ll break down Java variables, their types, real examples, and answer common beginner questions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aXhj1125pgAJsLG7urkEQg.png" /></figure><h3>1.Local Variables</h3><p>Defined inside a method or block. Only exists during that method’s execution.</p><pre>public class Example {<br>    public void greet() {<br>        String message = &quot;Hello, Java!&quot;;<br>        System.out.println(message);<br>    }<br>}</pre><h4>Common doubts:</h4><h4><em>1. Can I use </em><strong><em>message </em></strong><em>in another method?</em></h4><p>No, local variables live and die inside the method.</p><h4>2. <em>Do I need to initialize it?</em></h4><p>Yes! Java will throw an error if you try to use an uninitialized local variable.</p><h3><strong>2. Instance Variables (Non-static or Object Variables)</strong></h3><p>Defined inside a class but outside any method. Belongs to each object.</p><pre>public class Dog {<br>    String breed; // Instance variable<br><br>    public void bark() {<br>        System.out.println(&quot;The dog is a &quot; + breed);<br>    }<br>}<br>public class Main {<br>    public static void main(String[] args) {<br>        Dog d1 = new Dog();<br>        d1.breed = &quot;Labrador&quot;;<br>        d1.bark(); //The dog is a Labrador<br><br>        Dog d2 = new Dog();<br>        d2.breed = &quot;Beagle&quot;;<br>        d2.bark(); //The dog is a Beagle<br>    }<br>}</pre><h4>Common doubts:</h4><h4>1.Why does each object have its own value?</h4><p>Because instance variables belong to the object (not shared).</p><h4>2.<em>What’s the default value if I don’t assign anything?</em></h4><p>Default values depend on the type (e.g., <em>null, 0, false</em>).</p><h3>3.Static Variables (Class Variables)</h3><p><em>Defined with </em><strong><em>static </em></strong><em>keyword. Belongs to the class, shared across all objects.</em></p><pre>public class Student {<br>    static String school = &quot;ABC School&quot;; // static variable<br>    String name;<br><br>    public void printInfo() {<br>        System.out.println(name + &quot; studies in &quot; + school);<br>    }<br>}<br>public class Main {<br>    public static void main(String[] args) {<br>        Student s1 = new Student();<br>        s1.name = &quot;Alice&quot;;<br><br>        Student s2 = new Student();<br>        s2.name = &quot;Bob&quot;;<br><br>        s1.printInfo(); // Alice studies in ABC School<br>        s2.printInfo(); // Bob studies in ABC School<br><br>        // Change the school<br>        Student.school = &quot;XYZ School&quot;;<br><br>        s1.printInfo(); // Alice studies in XYZ School<br>        s2.printInfo(); // Bob studies in XYZ School<br>    }<br>}</pre><h4>Common doubts:</h4><h4>1.Why did both students get the updated school name?</h4><p>Because <strong><em>school </em></strong>is static variable, it’s shared across all instances.</p><h4>2.Can I access it without creating an object?</h4><p>Yes! You can do <strong><em>Student.school</em></strong> .</p><h3>4. Final Variables (Constants)</h3><p>Use <strong><em>final </em></strong>to<strong><em> </em></strong>declare a variable that cannot be changed once assigned.</p><pre>public class Circle {<br>    final double PI = 3.14159;<br><br>    public void calculateArea(double radius) {<br>        double area = PI * radius * radius;<br>        System.out.println(&quot;Area: &quot; + area);<br>    }<br>}</pre><h4>Common doubts:</h4><h4>1.Can I assign a new value to PI later?</h4><p>No it’s constant. Java will throw a compilation error.</p><h4>2.Can I declare it without assigning immediately?</h4><p>Yes, but you must assign it <strong>exactly once</strong>, either in a constructor or initializer block.</p><h3>Conclusion</h3><p>Understanding variables is the first big step toward mastering Java. Whether it’s local, instance, or static variables each plays a specific role in how your program stores and manages data. By knowing where and how to use them, you write cleaner, more efficient, and bug-free code. As you move forward, keep experimenting and questioning, that’s the best way to build a solid foundation in Java.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70c80249e6b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stack vs Heap Memory in Java]]></title>
            <link>https://medium.com/@heartlinbenit/stack-vs-heap-memory-in-java-ca3aa3eb4912?source=rss-d00602accd9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca3aa3eb4912</guid>
            <category><![CDATA[stack]]></category>
            <category><![CDATA[memory-management]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[stackoverflow]]></category>
            <category><![CDATA[heap-and-stack-memory]]></category>
            <dc:creator><![CDATA[Dio Pastina Heartlin B]]></dc:creator>
            <pubDate>Wed, 02 Jul 2025 01:03:52 GMT</pubDate>
            <atom:updated>2025-07-02T01:07:52.096Z</atom:updated>
            <content:encoded><![CDATA[<p>When you write Java code, memory management happens silently in the background. But behind that simplicity, Java uses two main memory areas to execute your programs efficiently (i.e.) the <strong>Stack</strong> and the <strong>Heap</strong>. Understanding these is crucial if you want to write optimized, bug-free Java applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*slVBivEca6hrwSOWyg4vLw.png" /></figure><h3>What is Stack Memory?</h3><p>Stack memory is the <strong>temporary memory</strong> that stores:</p><ol><li>Method calls</li><li>Local variables(like <strong><em>int x = 5</em></strong>)</li><li>References to objects (<em>not the objects themselves</em>)</li></ol><p>Each time a method is invoked, a <strong>new block</strong> (called a <strong>stack frame</strong>) is pushed onto the stack. When the method completes, that block is <strong>automatically removed</strong>.</p><h4>Characteristics of Stack:</h4><ol><li><strong><em>Memory allocation</em></strong> happens <strong>automatically </strong>as methods are called.</li><li><strong><em>Memory deallocation</em></strong> is also <strong>automatic </strong>when <strong>methods return.</strong></li><li>It follows the <strong>LIFO</strong>(<strong><em>Last In First Out</em></strong>) structure.</li><li>Each <strong>thread </strong>has its <strong>own stack</strong>.</li><li>The stack <strong><em>size </em></strong>is <strong>limited </strong>and <strong>fixed</strong>.</li><li>It is capable of very <strong>fast accessibility</strong> due to predictable allocation.</li><li>Its <strong><em>lifetime </em></strong>is <strong>short-lived </strong>and tied to <strong>method execution</strong></li></ol><h4>Example</h4><pre>public void calculate() {<br>    int a = 10;     <br>    int b = 20;     <br>    int sum = a + b;<br>}</pre><p>Here,<strong> <em>a, b</em></strong> and <strong><em>sum </em></strong>are stored in the <strong>stack frame</strong> for the <strong><em>calculate()</em> </strong>method. Once the method completes, all variables are wiped from memory.</p><h4>What is Heap Memory?</h4><p>Heap is the <strong>shared memory area</strong> where <strong>all Java objects</strong> are stored. Whenever you use the <strong>new </strong>keyword, you&#39;re allocating memory on the <strong>Heap</strong>.</p><p>This memory is <strong>not cleaned up automatically</strong> — instead, Java uses <strong>Garbage Collection (GC)</strong> to track and remove unused objects.</p><h4>Characteristics of Heap:</h4><ol><li><strong><em>Memory allocation</em></strong> happens when <strong><em>new </em></strong>is used to create objects.</li><li><strong><em>Memory deallocation</em></strong> is performed by the <strong>Garbage Collector (GC)</strong>.</li><li>It is divided into generations: <strong>Eden, Survivor, and Old Gen.</strong></li><li><strong>Shared across all threads</strong> (needs synchronization).</li><li>The stack <strong><em>size </em></strong>is large and expandable (controlled via <strong><em>-Xmx, -Xms</em></strong>).</li><li>It is s<strong>lower</strong> than stack due to dynamic nature and GC.</li><li>Its <strong><em>lifetime </em></strong>is <strong>long-lived</strong> — as long as the <strong>object is referenced.</strong></li></ol><h4>Example</h4><pre>public class Demo {<br>    public static void main(String[] args) {<br>        String name = new String(&quot;Java&quot;); <br>    }<br>}</pre><p>Here, the variable <strong><em>name</em></strong>(a reference) is stored in the <strong>stack</strong>, but the actual <strong>“Java” </strong>object lives in the <strong>heap</strong>.</p><p>When <strong>main()</strong> ends, the reference <strong><em>name </em></strong>is removed, and the object becomes <strong>eligible for GC</strong>.</p><h4>Common errors in Heap and Stack</h4><h4>STACK:</h4><p><strong><em>StackOverflowError </em></strong>occurs when the call stack exceeds its limit — usually due to deep or infinite recursion. Each method call adds a new frame to the stack, and if it grows too large, Java throws this error.</p><p>Example:</p><pre>public class StackError {<br>    public static void overflowfunction() {<br>        overflowfunction(); <br>    }<br><br>    public static void main(String[] args) {<br>        overflowfunction(); <br>    }<br>}</pre><h4>HEAP:</h4><p><strong><em>OutOfMemoryError</em></strong> happens in the heap when your application tries to allocate memory for a new object but the heap is full and Garbage Collection can’t reclaim enough space. This is often caused by memory leaks — holding references to unused objects.</p><pre>import java.util.*;<br><br>public class HeapError {<br>    public static void main(String[] args) {<br>        List&lt;int[]&gt; list = new ArrayList&lt;&gt;();<br><br>        while (true) {<br>            list.add(new int[1_000_000]); <br>        }<br>    }<br>}<br></pre><h4>Visual Analogy</h4><ul><li><strong>Stack = Whiteboard</strong><br> You write something, use it quickly, and erase it when done. It’s fast but limited in space.</li><li><strong>Heap = Bookshelf</strong><br> You store bigger things (books = objects) that stay longer and must be manually cleaned up (GC).</li></ul><h3>Conclusion</h3><p>Java developers don’t manage memory manually, but understanding how the <strong>stack and heap</strong> work helps you:</p><ul><li>Avoid memory leaks</li><li>Write efficient code</li><li>Debug faster</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca3aa3eb4912" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Garbage Collection in Java]]></title>
            <link>https://medium.com/@heartlinbenit/garbage-collection-in-java-fb7b40061d3b?source=rss-d00602accd9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb7b40061d3b</guid>
            <category><![CDATA[garbage-collection]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[heap-memory]]></category>
            <dc:creator><![CDATA[Dio Pastina Heartlin B]]></dc:creator>
            <pubDate>Thu, 26 Jun 2025 15:48:08 GMT</pubDate>
            <atom:updated>2025-06-26T15:48:08.266Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever wondered how Java clears memory without you doing <em>delete </em>like in C or C++? That magic is called <strong>Garbage Collection (GC)</strong> — one of Java’s most powerful features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rzdTO__N5V2KPseLFhJEuA.png" /></figure><p>In this post, we’ll explore:</p><ul><li>What Garbage Collection is</li><li>How it works in the JVM</li><li>Minor GC vs Major GC</li><li>Types of Garbage Collectors</li><li>How to trigger or tune it</li></ul><h4>What Is Garbage Collection?</h4><p>In Java, when an object is no longer <strong>reachable</strong>, the JVM automatically <strong>removes it from memory</strong> — freeing up space. This process is called <strong>Garbage Collection</strong>.</p><blockquote><em>1. GC prevents memory leaks and manual memory management.<br>2. The </em><strong><em>Heap</em></strong><em> is the only memory area managed by GC.</em></blockquote><h4>When Is an Object Garbage?</h4><p>An object becomes eligible for GC when:</p><ul><li><strong>No active references</strong> to it exist</li><li>It is <strong>unreachable</strong> from any running thread</li></ul><pre>Employee e = new Employee();  <br>e = null;                     </pre><p>Here, a new<strong> Employee</strong> object is created and referenced by the variable ‘<strong>e</strong>’. When ‘<strong>e’</strong> is set to <strong>null </strong>, the object no longer has any active references, making it <strong>eligible for garbage collection</strong>.</p><h4><strong>JVM Heap and GC Zones</strong></h4><p>The JVM divides the Heap into <strong>generations</strong> to manage GC more efficiently:</p><h4>1. Young Generation</h4><ul><li>Where <strong>new objects</strong> are created</li><li>Most objects die quickly</li><li>Garbage Collection here is called <strong>Minor GC</strong></li><li>Very frequent, very fast</li></ul><p>Further divided into:</p><ol><li><strong>Eden Space</strong>: where all new objects first go</li><li><strong>Survivor Spaces (S0 &amp; S1)</strong>: used for objects that survive GCs</li></ol><h4>2. Old Generation (Tenured)</h4><ul><li>Stores long-lived objects (promoted from Young)</li><li>Garbage Collection here is called <strong>Major GC</strong> (or Full GC)</li><li>Slower and more expensive</li></ul><h4>What Happens During a GC Cycle?</h4><ol><li><strong>Object created</strong> → Goes to <strong>Eden</strong></li><li>If it survives one GC → moves to <strong>Survivor S0</strong></li><li>Survives more → moves to <strong>Survivor S1</strong></li><li>Lives long enough → promoted to <strong>Old Generation</strong></li><li>Eventually, Old Gen fills → <strong>Major GC</strong> happens</li></ol><p><strong>Example</strong></p><pre>List&lt;Integer&gt; list = new ArrayList&lt;&gt;();<br>for(int i=0; i&lt;1000000; i++) {<br>    list.add(i); <br>}<br>list = null;     </pre><p>At this point, the list object has no references and is ready for garbage collection.</p><h3>Major GC Algorithms in Java</h3><p>When you install the <strong>JDK</strong>, you get the <strong>JVM (Java Virtual Machine)</strong> bundled with it. And this JVM already includes <strong>all the major garbage collection algorithms</strong>.</p><ul><li><strong>Serial GC</strong>:<br> Best for small applications. Uses a single thread to perform garbage collection. It pauses everything during cleanup.</li><li><strong>Parallel GC</strong>:<br> Uses multiple threads for faster garbage collection. Still pauses the application but works better for bigger programs.</li><li><strong>CMS (Concurrent Mark-Sweep)</strong>:<br> Runs mostly in the background with minimal pauses. Good for responsive apps. Now deprecated in newer Java versions.</li><li><strong>G1 GC (Garbage First)</strong>:<br> Splits the heap into regions and cleans them one by one. Balances speed and low pause time. Default from Java 9.</li><li><strong>ZGC (Z Garbage Collector)</strong>:<br> Designed for very large memory. Has ultra-low pause times. Best for apps where you can’t afford delays.</li><li><strong>Shenandoah GC</strong>:<br> Similar to ZGC. Focuses on very low pause times and concurrent collection. Ideal for real-time systems.</li></ul><h4>Can You Trigger GC?</h4><p>Yes, but JVM <strong>may ignore it</strong>:</p><pre>System.gc(); </pre><p>Use this only for learning or profiling — not in real apps.</p><h4>GC Tuning : How to set your own Collector?</h4><ul><li>Java gives you <strong>multiple built-in GC algorithms</strong>.</li><li><strong>By default</strong>, the JVM picks one (like G1 GC).</li><li>You can <strong>manually choose</strong> another GC using <strong>JVM flags</strong> when you run your program.</li></ul><pre>java -Xms512m -Xmx1024m -XX:+UseG1GC MyApp</pre><ul><li><strong><em>-Xms</em></strong><em> </em>: Initial heap size</li><li><strong><em>-Xmx </em></strong>: Max heap size</li><li><strong><em>-XX:+PrintGCDetails</em></strong> : Show GC logs</li><li><strong><em>-XX:+UseG1GC </em></strong>: Use G1 collector</li></ul><h4>Common GC-Related Errors</h4><ol><li><strong>OutOfMemoryError- </strong>Heap is full, GC couldn’t clean enough</li><li><strong>GC overhead limit exceeded- </strong>GC is taking too long</li><li><strong>Promotion failed- </strong>No room to promote survivors to Old Gen</li></ol><h4>Conclusion</h4><p>Java’s Garbage Collector is one of its biggest strengths which lets you focus on code while it handles memory. But the more you understand <strong>how Eden, Survivor, and Old Gen</strong> work, the better you can write high-performing, memory-safe applications.</p><h4>TL;DR</h4><ul><li>Java automatically removes unused objects using <strong>GC</strong></li><li>Heap is split into <strong>Young (Eden + Survivor)</strong> and <strong>Old Generation</strong></li><li><strong>Minor GC</strong> = fast, cleans Young Gen</li><li><strong>Major GC</strong> = slower, cleans Old Gen</li><li>GC types include <strong>Serial, G1, ZGC</strong>, and more</li></ul><p><em>Daily ideations about the Java I know — follow for more!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb7b40061d3b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compiling vs Running in Java]]></title>
            <link>https://medium.com/@heartlinbenit/compiling-vs-running-in-java-eafacaf3c791?source=rss-d00602accd9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/eafacaf3c791</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[compilers]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[beginner-coding]]></category>
            <category><![CDATA[java8]]></category>
            <dc:creator><![CDATA[Dio Pastina Heartlin B]]></dc:creator>
            <pubDate>Tue, 24 Jun 2025 14:32:24 GMT</pubDate>
            <atom:updated>2025-06-24T14:33:16.173Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re learning Java, you’ve probably used both the <em>javac </em>and <em>java </em>commands. But what do they really do? Aren’t they both just <strong>&quot;running&quot;</strong> the code?</p><p>Let’s clear the confusion — because understanding this is key to mastering how Java actually works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NGTcOZ5gVkO_wZKzbecycg.png" /></figure><h4><strong>What is Compilation?</strong></h4><p><strong>Compilation</strong> is the process where your <em>.java </em>source file is <strong>converted into bytecode</strong> (<em>.class</em> file) using the <em>javac </em>compiler.</p><p><strong>What it does?</strong></p><ul><li>It checks your code for <strong>syntax and type errors</strong></li><li>It does <strong>not</strong> run the code — it only prepares it</li><li>Output is a platform-independent <em>.class</em> file (bytecode)</li></ul><pre>javac Hi.java</pre><p>This creates <em>Hi.class,</em> which the JVM can understand.</p><h4>What is Running?</h4><p><strong>Running</strong> is when the compiled bytecode is <strong>executed</strong> by the <strong>Java Virtual Machine (JVM)</strong>.</p><h4>What it does?</h4><ul><li>JVM reads the <em>.class</em> file</li><li>Uses <strong>JIT (Just-In-Time)</strong> compilation to convert bytecode into machine code</li><li>Shows final output or <strong>runtime errors</strong></li></ul><pre>java HelloWorld</pre><p>Now your program runs and prints output .</p><h4>Key Differences</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*e6I6suxA0yLm7_EMO5KwJQ.png" /></figure><h4>Why This Matters</h4><ul><li>Compilation gives you a chance to fix mistakes <strong>before</strong> running</li><li>Running is where the actual logic is tested and the program <strong>comes alive</strong></li><li>Understanding this helps you debug faster and structure your code better</li></ul><h3>One-Liner Takeaway</h3><blockquote><strong><em>Compilation prepares your code. Running makes it work.</em></strong></blockquote><p><em>Daily ideations about the Java I know — follow for more!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eafacaf3c791" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compile, Interpret, or Both?]]></title>
            <link>https://medium.com/@heartlinbenit/compile-interpret-or-both-a2b427fb71bf?source=rss-d00602accd9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2b427fb71bf</guid>
            <category><![CDATA[compilers]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[beginner-coding]]></category>
            <category><![CDATA[java8]]></category>
            <dc:creator><![CDATA[Dio Pastina Heartlin B]]></dc:creator>
            <pubDate>Tue, 24 Jun 2025 13:47:12 GMT</pubDate>
            <atom:updated>2025-06-24T14:10:02.445Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever asked yourself:</p><blockquote>“When I click run, what actually happens to my code?”</blockquote><p>Whether you’re coding in C, Python, or Java — <strong>every language must turn your code into something the computer can understand: machine code (1s and 0s).</strong> But the way that happens isn’t the same for every language.</p><p>Let’s break it down in a way that finally makes sense.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hdB8-7B8Tf8e0x2skhkp7Q.png" /></figure><h3>The Three Models of Programming Languages</h3><h4>1.Compiled Languages</h4><p><strong>Example: </strong><em>C, C++, Go</em></p><ul><li>You <strong>manually compile</strong> the code using a compiler (like <em>gcc</em>).</li><li>The compiler converts your <em>.c</em> file into a full-fledged <strong>machine code file</strong> (<em>.exe </em>(i.e.)binary file).</li><li>This file runs <strong>directly on the CPU</strong> with no extra tools.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V99Q_DoeMOIP2bg607avWg.png" /></figure><p>✅ Very fast<br> ❌ Not portable. It only works on the OS it was compiled for.</p><h4><strong>2.Interpreted Languages</strong></h4><p><strong>Example: </strong><em>Python, JavaScript, Ruby</em></p><ul><li>No manual compilation needed.</li><li>No standalone <em>.exe </em>file created.</li><li>The interpreter <strong>reads and runs</strong> the code <strong>line by line</strong> at runtime.</li><li>Python, for example, quietly compiles code to bytecode (<em>.pyc</em>) behind the scenes, but you never touch it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hpaLgwucRzuN1RsHpGqfiw.png" /></figure><p>✅ Easy to test and write<br>❌ Slower. It reads and runs each line in real time<br>✅ Portable. It works wherever the interpreter is available</p><h4><strong>3.Hybrid Languages (Both!)</strong></h4><p><strong>Example: </strong><em>Java, C#, Kotlin</em></p><ul><li>You <strong>compile</strong> the code to an intermediate form (Java calls it <strong>bytecode</strong>).</li><li>This bytecode is <strong>not machine code</strong>, but it’s portable and safe.</li><li>At runtime, a virtual machine (like <strong>JVM</strong> or <strong>CLR</strong>) converts it to machine code and runs it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bO8ZLTnUbTXH_N5mG3n4CQ.png" /></figure><p>✅ Platform-independent (Write Once, Run Anywhere)<br>✅ Optimized using JIT (Just-In-Time compiler)<br>❌ Slightly more complex setup</p><h4><strong>TL;DR</strong></h4><p>We, as programmers, write code in <strong>high-level languages</strong> that are easy for humans to understand — like Python, Java, or C.<br>But computers don’t understand these directly. They only understand <strong>machine-level language</strong> — pure binary instructions (0s and 1s).</p><p>So, no matter what language you’re using, your code must go through a process:</p><ul><li>Either by <strong>compiling</strong> it all at once,</li><li><strong>Interpreting</strong> it step by step,</li><li>Or a mix of both (<strong>hybrid models</strong> like Java or C#).</li></ul><p>In some cases, the code is first translated into an <strong>intermediate form</strong> like <strong>bytecode</strong>, and then further converted into machine code by a runtime engine or interpreter.</p><p><strong>Ultimately, the goal is always the same:</strong></p><blockquote>To transform your logic into a language the <strong>CPU can execute</strong>, so your code can do real-world work.</blockquote><p><em>Daily ideations about the Java I know — follow for more!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2b427fb71bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JVM vs JRE vs JDK]]></title>
            <link>https://medium.com/@heartlinbenit/jvm-vs-jre-vs-jdk-861fd04055cb?source=rss-d00602accd9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/861fd04055cb</guid>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[jvm]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[jdk]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Dio Pastina Heartlin B]]></dc:creator>
            <pubDate>Mon, 23 Jun 2025 04:54:22 GMT</pubDate>
            <atom:updated>2025-06-23T04:54:22.034Z</atom:updated>
            <content:encoded><![CDATA[<p><em>“Write Once, Run Anywhere.”</em></p><p>This line defines Java’s power — and behind that power are three key players: <strong>JVM</strong>, <strong>JRE</strong>, and <strong>JDK</strong>.<br>But what exactly are they? And how do they work together when you write and run a Java program?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0wTnPnr_JyLBllPAEdEN4A.png" /></figure><p>If you want to:</p><ul><li>Write Java programs</li><li>Understand how Java runs on any OS</li></ul><p>…then you need to understand the <strong>Java ecosystem</strong>:<br> <strong>JDK = JRE + development tools</strong>,<br> <strong>JRE = JVM + libraries</strong>,<br> <strong>JVM = the core runner of your Java code.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k81JOxGURKTD2b8SUQ8qAw.png" /></figure><h3><strong>What Is JVM?</strong><br><em>Java Virtual Machine (JVM)</em></h3><p>The <strong>JVM</strong> is the heart of the Java ecosystem.<br> It takes your <em>.class</em> file (bytecode) and <strong>runs it</strong>, converting it to machine code specific to your system.</p><p><strong>Key Responsibilities of JVM</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*_vILuMxHEFzYycS0VnsDPw.png" /></figure><blockquote>The <strong>JVM is platform-specific</strong> (Windows/Linux/Mac), but it runs <strong>platform-independent bytecode</strong>.</blockquote><h3><strong>What Is JRE?</strong><br><em>Java Runtime Environment (JRE)</em></h3><p>The <strong>JRE</strong> is what allows you to <strong>run</strong> Java programs.</p><p>It includes:</p><ul><li>JVM</li><li>Core Java libraries (e.g., <em>java.util</em>, <em>java.lang</em>)</li><li>Other runtime components</li></ul><p><strong>What It Does NOT Have:</strong></p><ul><li>Compiler (<em>javac</em>)</li><li>Developer tools</li></ul><p><strong>When to Use JRE?</strong></p><ul><li>When you already have a <em>.class</em> or <em>.jar</em> file</li><li>You want to <strong>run</strong>, not write or compile Java code</li></ul><p><strong>Example</strong>: Running Java-based software like Minecraft or Eclipse</p><h3><strong>What Is JDK?</strong><br><em>Java Development Kit(JDK)</em></h3><p>The <strong>JDK</strong> is the full Java toolbox for <strong>developers</strong>.</p><p>It includes:</p><ul><li>Everything in the JRE</li><li>Compiler (javac)</li><li>Debugger (jdb)</li><li>Bytecode tools (javap)</li><li>Documentation tool (javadoc)</li><li>Development tools and headers</li></ul><p><strong>When to Use JDK?</strong></p><ul><li>When you’re <strong>writing, compiling, or debugging</strong> Java code</li><li>It’s what <strong>students, professionals, and interview candidates</strong> use</li></ul><p>Required if you’re coding in Java — students, devs, interviewees.</p><h3><strong>Nutshell comparison</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*ZO4yhuckMPjIHLqaiy9jSA.png" /></figure><h3><strong>TL;DR</strong></h3><p>If you’re writing Java → <strong>install JDK</strong><br>If you’re just running Java → <strong>JRE is enough</strong><br><strong>JVM </strong>is always running behind the scenes</p><p><em>Daily ideations about the Java I know — follow for more!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=861fd04055cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s Inside a .class File?]]></title>
            <link>https://medium.com/@heartlinbenit/whats-inside-a-class-file-7d5741f9cbc0?source=rss-d00602accd9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d5741f9cbc0</guid>
            <category><![CDATA[bytecode]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[jvm]]></category>
            <dc:creator><![CDATA[Dio Pastina Heartlin B]]></dc:creator>
            <pubDate>Fri, 20 Jun 2025 10:28:42 GMT</pubDate>
            <atom:updated>2025-06-20T10:28:42.981Z</atom:updated>
            <content:encoded><![CDATA[<h3>What’s Inside a .class File?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YnqapjpKAyyFxymzfTeHUg.png" /></figure><p>Every time we compile a Java program, a <strong><em>.class</em></strong> file is generated. But what really lives inside that file?</p><p>Why is it unreadable? What’s that <strong>CAFEBABE </strong>everyone talks about?</p><p>Let’s decode what’s inside a<strong><em> .class</em></strong> file — both in raw hexadecimal and in readable bytecode form — and understand how it enables Java’s famous <strong>“Write Once, Run Anywhere”</strong> magic.</p><p><strong>From <em>.java</em> to <em>.class</em> — A Quick Recap</strong></p><p>When we write this code,</p><pre>public class Hello {<br>    public static void main(String[] args) {<br>        System.out.println(&quot;Hi&quot;);<br>    }<br>}</pre><p>and compile using :</p><pre>javac Hello.java</pre><p>This produces:</p><p><strong><em>Hello.class </em></strong><em>— </em>a file containing <strong>bytecode</strong>, not your source code.</p><p><strong>What’s a <em>.class</em> File?</strong></p><ul><li>It contains <strong>Java bytecode</strong> (a universal format for JVM)</li><li>It’s not human-readable</li><li>But it’s <strong>platform-independent</strong> and optimized for execution</li><li>It’s what the <strong>JVM reads and runs</strong></li></ul><h3>A View at the Bytecode</h3><ol><li><strong>Opening the </strong><em>.class</em><strong> file in Hex View</strong></li></ol><p>Let’s open the .class file using a hex viewer by installing the <strong>Hex Editor</strong> extension in VS code. This gives us:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jWHl5M5kftToecr4g0XP6g.png" /></figure><p><strong>CA FE BA BE</strong> 00 00 00 44 …</p><p>Yes, it’s literally spelled like <strong>CAFE BABE</strong> 😄<br> This is a fixed value that marks every <strong><em>.class</em></strong> file so the JVM can recognize and validate it.</p><p><strong>What does this mean?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AKy8WrtFbVpZCu1Mb9U9yg.png" /></figure><p>This confirms to the JVM:<strong><em> “Yes, this is a valid class file!”</em></strong></p><h3>So, What’s Actually Inside?</h3><p>A <strong><em>.class</em></strong> file contains:</p><ul><li>A <strong>constant pool</strong> (strings, class names, method refs)</li><li><strong>Field &amp; method definitions</strong></li><li><strong>Bytecode instructions</strong></li><li>Metadata (like line numbers, attributes)</li></ul><p>2. <strong>Disassembling with </strong><em>javap -c</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*Rimgmx_qN0uEABMGcMZF2g.png" /></figure><p>To inspect it in a readable format:</p><pre>javap -c Hello</pre><p>You’ll get output like:</p><pre>public class Hello {<br>  public static void main(String[] args);<br>    Code:<br>       0: getstatic     #7   // System.out<br>       3: ldc           #13  // Load &quot;Hi&quot;<br>       5: invokevirtual #15  // Call println<br>       8: return<br>}</pre><p>This is <strong>Java bytecode</strong>, the exact instructions executed by the JVM.</p><h3>Why This Matters</h3><ul><li><strong>Security</strong>: You can’t reverse-engineer <em>.class</em> files easily.</li><li><strong>Portability</strong>: Same <em>.class </em>runs on Windows, Mac, Linux, etc.</li><li><strong>Performance</strong>: JVM uses a <strong>Just-In-Time (JIT)</strong> compiler to optimize execution on the fly.</li></ul><p>That <strong><em>.class</em></strong> file may look unreadable at first, but it holds the heart of Java’s power: a universal, secure, and efficient format that lets your code run anywhere.</p><p>Now when you compile your code and see <strong><em>Hello.class</em></strong> , you know — you&#39;re looking at bytecode, built to travel the world.</p><p><em>Daily ideations about the Java I know — follow for more!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d5741f9cbc0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Java Code Runs ?]]></title>
            <link>https://medium.com/@heartlinbenit/how-java-code-runs-fc7d79d6bf37?source=rss-d00602accd9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc7d79d6bf37</guid>
            <category><![CDATA[bytecode]]></category>
            <category><![CDATA[beginner-coding]]></category>
            <category><![CDATA[jvm]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[oop]]></category>
            <dc:creator><![CDATA[Dio Pastina Heartlin B]]></dc:creator>
            <pubDate>Thu, 19 Jun 2025 14:00:34 GMT</pubDate>
            <atom:updated>2025-06-19T14:00:34.294Z</atom:updated>
            <content:encoded><![CDATA[<h3>How Java Code Runs ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FZFpzFqbbHO5fIIr9LHaoQ.png" /></figure><p>If you’ve just written your first Java program, you might be wondering what really happens when you hit <strong>“Run”</strong>.<br> Let’s break it down step by step — this is where Java’s <strong>magic of platform independence</strong> begins.</p><p><strong>What is a </strong><em>.java</em><strong> file?</strong></p><p>A <strong><em>.java</em></strong><em> </em>file is a plain text file that contains your source code — the code you write in the Java language.</p><p>For example,</p><pre>public class HelloWorld {<br>    public static void main(String[] args) {<br>        System.out.println(&quot;Hello, Java!&quot;);<br>    }<br>}</pre><p>This file is readable to you — but not to your computer. It needs to be <strong>compiled</strong> into something the machine (or the <strong>Java Virtual Machine</strong>) can understand.</p><p><strong>Compilation with </strong><em>javac</em></p><p>You use the Java compiler to compile the <em>.java</em> file:</p><pre>javac HelloWorld.java</pre><p>This produces a <em>.class</em> file like this :</p><pre>HelloWorld.class</pre><p>The <em>.class</em> file contains something called bytecode.</p><h3>What Is Bytecode?</h3><p><strong>Bytecode</strong> is a set of low-level, optimized instructions. It is not tied to any specific OS or machine.<br>It’s not human-readable, but the <strong>Java Virtual Machine (JVM)</strong> knows exactly what to do with it.</p><p>This is the secret behind Java’s <strong>“Write Once, Run Anywhere”</strong> philosophy.</p><p><strong>Running the Program with </strong><em>java</em></p><pre>java HelloWorld</pre><p>This does <strong>not</strong> run the <em>.java</em> file directly instead:</p><ul><li>The <strong>JVM</strong> reads the <strong>bytecode</strong> in the <em>.class</em> file</li><li>It converts it to machine code (specific to your OS)</li><li>Then it executes the program</li></ul><p>The output?</p><pre>Hello, Java!</pre><h3>Java’s Platform Independence</h3><p>Other languages like C or C++ compile your code <strong>directly to machine code</strong>, which is OS-specific.<br>But Java compiles to <strong>bytecode</strong>, which can run <strong>anywhere</strong> the JVM is available (e.g.)Windows, Mac, Linux, Android, etc.</p><h3>A Quick Flowchart</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yYiqMqAfJEkC-ZZy8J2VMA.png" /></figure><p>Every time you compile and run a Java program, you’re tapping into decades of smart design — turning code into bytecode, and bytecode into action.</p><p><em>Daily ideations about the Java I know — follow for more!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc7d79d6bf37" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>