<?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 Aparna M on Medium]]></title>
        <description><![CDATA[Stories by Aparna M on Medium]]></description>
        <link>https://medium.com/@aparna.05101989?source=rss-684f7e318e29------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*mUoqHLtk9BprFUzj</url>
            <title>Stories by Aparna M on Medium</title>
            <link>https://medium.com/@aparna.05101989?source=rss-684f7e318e29------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 10:05:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aparna.05101989/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[Java: Memory Allocation(Stack & Heap)]]></title>
            <link>https://medium.com/@aparna.05101989/java-memory-allocation-stack-heap-28859a7b5d72?source=rss-684f7e318e29------2</link>
            <guid isPermaLink="false">https://medium.com/p/28859a7b5d72</guid>
            <category><![CDATA[stack]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[heap]]></category>
            <category><![CDATA[memory-management]]></category>
            <dc:creator><![CDATA[Aparna M]]></dc:creator>
            <pubDate>Sat, 24 Jan 2026 09:08:48 GMT</pubDate>
            <atom:updated>2026-01-24T09:08:48.847Z</atom:updated>
            <content:encoded><![CDATA[<p>In Java, memory is primarily split into Stack and Heap(plus few other areas like Metaspace). understanding these helps you predict performance and debug issues like <em>StackOverflowError </em>and <em>OutOfMemoryError.</em></p><h4>Stack Memory</h4><p>** What it Stores</p><ul><li>method Call frames (one frame per method call)</li><li>local variables (primitives like int, float, double, boolean)</li><li>reference to object (The address/reference, not the object itself)</li></ul><p>** How Allocation Works</p><ul><li>Allocation automatic when method is called</li><li>Deallocation when method returns</li><li>Stack follows LIFO(Last In First Out): last method called is removed first</li></ul><p>** Characteristics</p><ul><li>Very fast</li><li>Size is limited per thread</li><li>Each thread has its own stack</li><li>We can use -Xss to define stack memory size</li></ul><p>** Common Error</p><ul><li><strong>StackOverflowError: </strong>happens when stack frames keep growing (ofter due to recursion)</li></ul><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><h4>Heap Memory</h4><p>** What it Stores</p><ul><li>Objects</li><li>Instance variables(fields of objects)</li><li>String pool</li><li>Arrays</li><li>Almost everything that lives beyond method calls</li></ul><p>** How Allocation Works</p><ul><li>Objects are allocated when you do <strong>new</strong></li><li>When new string object is created(String str = ‘abc’), string value gets added to String pool</li><li>Objects are removed by Garbage Collection(GC) when no longer reachable.</li></ul><p>** Characteristics</p><ul><li>Slower than stack but designed for dynamic allocation.</li><li>Much larger than stack(but still limited by JVM settings)</li><li><strong>Its shared across thread</strong></li><li>We can use -Xms and -Xmx to define startup size and maximum size of heap memory</li></ul><p>** Common Error</p><ul><li><strong>OutOfMemoryError: </strong>When Java heap space is full and GC cant free enough</li></ul><h4>Java Code Example(Stack v/s Heap)</h4><pre>class Book {<br>    String name;<br>    int price;<br> <br>    public Book(String name, int price) {<br>        this.name = name;<br>        this.price = price;<br>    }<br> <br>    public void printBookDetails() {<br>        System.out.println(&quot;Book Name:&quot; + this.name + &quot; Price:&quot; + this.price);<br>    }<br>}<br> <br>public class Day1_MemoryAllocationBehaviorInJava {<br>    static public void main(String args[]) {<br>        // Primitive type example<br>        int num = 5;<br>        System.out.println(num);        // Output: 5<br>        method1(num);<br>        System.out.println(num);        // Output: 5 (unchanged)<br> <br>        // Object behavior examples<br>        Book b = new Book(&quot;The secret&quot;, 200);<br>        b.printBookDetails();           // Output: Book Name:The secret Price:200<br> <br>        method2(b);<br>        b.printBookDetails();           // Output: Book Name:The secret 2 Price:100<br> <br>        b.name = &quot;The secret&quot;;<br> <br>        method3(b);<br>        b.printBookDetails();           // Output: Book Name:The secret Price:100<br>    }<br> <br>    static void method1(int n) {<br>        ++n;                            // n becomes 6 (local copy)<br>        System.out.println(n);          // Output: 6<br>    }<br> <br>    static void method2(Book b) {<br>        b.name = &quot;The secret 2&quot;;<br>        b.price = 100;<br>        b.printBookDetails();           // Output: Book Name:The secret 2 Price:100<br>    }<br> <br>    static void method3(Book b) {<br>        b = new Book(&quot;Method3&quot;, 100);   // b now refers to new object<br>        b.printBookDetails();           // Output: Book Name:Method3 Price:100<br>    }<br>}</pre><p>## Step-by-Step Memory Analysis</p><pre># Java Memory Allocation Analysis<br><br>### 1. Primitive Type (Pass-by-Value)<br>```java<br>int num = 5;           // num = 5<br>method1(num);          // method1 receives copy (n = 5)<br>System.out.println(num); // num still = 5<br>```<br><br>**Memory during method1():**<br>```<br>Stack Memory:<br>┌─────────────────┐<br>│ method1()       │ ← Top of stack<br>├─────────────────┤<br>│ n = 6           │ ← Local copy modified<br>└─────────────────┘<br>┌─────────────────┐<br>│ main() method   │<br>├─────────────────┤<br>│ num = 5         │ ← Original unchanged<br>└─────────────────┘<br>```<br><br>### 2. Object Modification (method2)<br>```java<br>Book b = new Book(&quot;The secret&quot;, 200);<br>method2(b);          // Both references point to same object<br>```<br><br>**Memory during method2():**<br>```<br>Stack Memory:<br>┌─────────────────┐<br>│ method2()       │ ← Top of stack<br>├─────────────────┤<br>│ b = [ref@1001]  │ ← Copy of reference<br>└─────────────────┘<br>┌─────────────────┐<br>│ main() method   │<br>├─────────────────┤<br>│ b = [ref@1001]  │ ← Original reference<br>└─────────────────┘<br><br>Heap Memory:<br>┌─────────────────┐<br>│ Book Object      │<br>│ @1001            │<br>├─────────────────┤<br>│ name = &quot;The secret 2&quot; │ ← Modified by method2()<br>│ price = 100     │ ← Modified by method2()<br>└─────────────────┘<br>```<br><br>### 3. Reference Reassignment (method3)<br>```java<br>method3(b);          // Local reference reassigned to new object<br>```<br><br>**Memory during method3():**<br>```<br>Stack Memory:<br>┌─────────────────┐<br>│ method3()       │ ← Top of stack<br>├─────────────────┤<br>│ b = [ref@1002]  │ ← Reassigned to new object<br>└─────────────────┘<br>┌─────────────────┐<br>│ main() method   │<br>├─────────────────┤<br>│ b = [ref@1001]  │ ← Still points to original<br>└─────────────────┘<br><br>Heap Memory:<br>┌─────────────────┐<br>│ Book Object      │<br>│ @1001            │ ← Original object<br>├─────────────────┤<br>│ name = &quot;The secret 2&quot; │<br>│ price = 100     │<br>└─────────────────┘<br>┌─────────────────┐<br>│ Book Object      │<br>│ @1002            │ ← New object (eligible for GC)<br>├─────────────────┤<br>│ name = &quot;Method3&quot; │<br>│ price = 100     │<br>└─────────────────┘<br>```<br><br>## Output Sequence<br>1. `5` - Initial primitive value<br>2. `6` - Modified copy in method1()<br>3. `5` - Original primitive unchanged<br>4. `Book Name:The secret Price:200` - Initial object state<br>5. `Book Name:The secret 2 Price:100` - Modified object in method2()<br>6. `Book Name:The secret 2 Price:100` - Object remains modified<br>7. `Book Name:Method3 Price:100` - New object in method3()<br>8. `Book Name:The secret 2 Price:100` - Original object unchanged by method3()<br><br>## Memory Areas<br>- **Stack**: Stores primitive values and object references (LIFO order)<br>- **Heap**: Stores actual object instances<br>- **Stack Frames**: Created for each method call, destroyed on return</pre><pre><br>## Key Concepts Demonstrated<br> <br>1. **Pass-by-Value for Primitives**: Only the value is copied, original remains unchanged<br>2. **Pass-by-Value for References**: The reference value is copied, but both point to same object<br>3. **Object Mutability**: Changes through copied reference affect the original object<br>4. **Reference Reassignment**: Only affects local copy, not original reference<br>5. **Garbage Collection**: Objects with no references become eligible for GC<br> <br>## Memory Management Summary<br> <br>- **Stack**: Stores primitive values and object references<br>- **Heap**: Stores actual object instances<br>- **Method calls** create new stack frames<br>- **Local variables** exist only within their method&#39;s stack frame<br>- **Objects** persist until no references point to them</pre><p>The diagrams show how memory is allocated and modified at each step, demonstrating Java’s pass-by-value behavior for both primitives and object references.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28859a7b5d72" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 1: How HashMap Works Internally When Collision Happens (Using LinkedList)]]></title>
            <link>https://medium.com/@aparna.05101989/part-1-how-hashmap-works-internally-when-collision-happens-using-linkedlist-3064f37c9c4e?source=rss-684f7e318e29------2</link>
            <guid isPermaLink="false">https://medium.com/p/3064f37c9c4e</guid>
            <category><![CDATA[hashmap-in-java]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[hashmap]]></category>
            <category><![CDATA[hashmap-internal-working]]></category>
            <dc:creator><![CDATA[Aparna M]]></dc:creator>
            <pubDate>Tue, 01 Jul 2025 11:19:22 GMT</pubDate>
            <atom:updated>2025-07-01T11:19:22.766Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Note: This article focuses on how Java stores and retrieves data in a HashMap when a <strong>collision</strong> occurs. We’ll explore collision handling using <strong>LinkedList</strong> in this part. Handling with <strong>Tree-based structures</strong> will be covered in the next article</blockquote><h4>Basics of HashMap</h4><p>HashMap is a part of Java’s collection framework that allows storing data in a <strong>key-value</strong> format.</p><ul><li>put(key, value): Adds a key-value pair into the map.</li><li>get(key): Retrieves the value associated with the given key.</li></ul><h4>What is a Collision and How Does it Occur?</h4><p>Let’s understand it with a basic scenario:</p><ul><li>The first time a key-value pair is added:</li></ul><ol><li>A default Node array of size 16 is created. (Node is a static inner class inside HashMap)</li><li>A hash is computed for the key.</li><li>An index is derived using the formula:<br>index = (array length — 1) &amp; hash.</li><li>If the array slot at that index is null, a new Node object is created and inserted. Node structure: Node(hash, key, value, next) , Initially, next is set to null.</li></ol><ul><li>Now when another key-value pair is added:</li></ul><ol><li>A new hash is computed for the new key.</li><li>If the resulting index collides with an existing one (i.e., same index is calculated), a collision has occurred.</li><li>If the keys are equal, the value is simply updated.</li><li>If the keys are different (but have the same hash and index), Java handles the collision by linking the new node to the existing node using a linked list.</li></ol><h4>How java handles collision?</h4><p>When the calculated index already contains a node:</p><ul><li>Java retrieves the existing node.</li><li>It traverses the linked list at that index.</li><li>If it finds an equal key, it updates the value.</li><li>If not, it appends the new node at the end of the list.</li></ul><p>Lets deep dive into below code and learn hashmap collision</p><pre>class Employee{<br> <br> String name;<br> <br> Employee(String name){<br>  this.name= name;<br> }<br> <br> @Override<br> public int hashCode() {<br>  return 2;<br> }<br> <br> @Override<br> public String toString() {<br>  // TODO Auto-generated method stub<br>  return this.name;<br> }<br> <br>}<br><br>public static void learnHashMapCollision_part1() {<br>  <br>  HashMap&lt;Employee, String&gt; map = new HashMap&lt;&gt;();<br>  Employee e1 =  new Employee(&quot;John&quot;);<br>  Employee e2 = new Employee(&quot;Mary&quot;);<br>  Employee e4 = e1;<br>  map.put(e1, &quot;John&quot;);<br>  map.put(e2, &quot;Mary&quot;);<br>  <br>  System.out.println(map.get(e1));<br>  System.out.println(map.get(e2));<br>  System.out.println(map.get(e4));<br>  System.out.println(map);<br> }<br>public static void main(String[] args) {<br>  learnHashMapCollision();<br> }</pre><h3>Explanation</h3><p>Here, we’ve overridden the hashCode() method to always return 2, so both e1 and e2 will result in the same hash and thus collide.</p><ul><li>Created HashMap which accepts Employee as a Key and String as a value</li><li><strong><em>put(e1, “John”)</em></strong><br> Hash = 2<br> Index = (16–1) &amp; 2 = 2<br> Index 2 is empty → a new Node(hash=2, key=e1, value=”John”, next=null) is created and stored.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*MoZvfpiUmwt9RyJElYFyrQ.png" /></figure><ul><li><strong><em>put(e2, “Mary”)</em></strong><br> Hash = 2<br> Index = (16–1) &amp; 2 = 2<br> Index 2 already has a node (e1)<br> AND Keys are not equal (e1 != e2)<br> Java traverses the linked list at index 2 and appends a new node for e2.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*7jv0PEtc7DhBirfM_w2iOA.png" /></figure><h4>How get(key) Works in Case of Collision?</h4><ul><li><strong><em>map.get(e1)</em></strong><br> Hash = 2<br> Index = (16–1) &amp; 2 = 2<br> Node at index 2 is e1 → checks if keys are equals → its true → returns “John”</li><li><strong><em>map.get(e2)</em></strong><br> Hash = 2<br> Index = (16–1) &amp; 2 = 2<br> Node at index 2 is e1 → checks if keys are equals → its not → starts traversing LinkedList at index 2 → Moves to next node<br> Next node is e2 → checks if keys are equals → key matches → return “Mary”</li><li><strong><em>map.get(e4)</em></strong><br> Since e4 == e1, this is same as get(e1) → returns “John”</li></ul><h4>Conclusion</h4><p>In this article, we explored how HashMap works internally during collision scenarios using a linked list.</p><p>When multiple keys hash to the same index:</p><ul><li>If keys are equal, values are updated.</li><li>If keys are different, Java chains them using a singly linked list.</li><li>On retrieval, Java compares hashes and uses equals() to find the right key.</li></ul><p>In the next part, we’ll explore how collisions are handled using Tree-based structures (TreeNode) when the number of chained nodes exceeds a certain threshold.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3064f37c9c4e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Selenium: Difference between getDomAttribute() and getDomProperty()]]></title>
            <link>https://medium.com/@aparna.05101989/selenium-difference-between-getdomattribute-and-getdomproperty-c31886f07b54?source=rss-684f7e318e29------2</link>
            <guid isPermaLink="false">https://medium.com/p/c31886f07b54</guid>
            <dc:creator><![CDATA[Aparna M]]></dc:creator>
            <pubDate>Wed, 26 Mar 2025 11:56:40 GMT</pubDate>
            <atom:updated>2025-03-26T12:00:10.496Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s been a long time since I last used Selenium. Recently, I started brushing up on my Selenium skills and discovered that so many changes have been made to Selenium lib. I decided to explore it in more detail and share my findings with everyone.</p><p>So here is my first blog, which highlights the difference between Selenium’s new methods: getDomProperty() and getDomAttribute(). Before proceeding further, let’s first understand some fundamental concepts.</p><h3>What is HTML?</h3><p>HTML (HyperText Markup Language) is the standard language for creating documents that are intended to be displayed on web browsers.</p><h3>What is the DOM?</h3><p>The <strong>Document Object Model (DOM)</strong> is a tree representation of the HTML webpage, where each element is an object with properties and methods. JavaScript and Selenium interact with this DOM to retrieve and manipulate elements dynamically.</p><h3>What is an Attribute?</h3><p>An <strong>attribute</strong> is a value set in the HTML code that provides additional information about an element. Attributes are part of the static HTML document and are not updated automatically when changes happen in the page.</p><p><strong>Example:</strong></p><p>&lt;input id=”username” type=”text” value=”user123&quot; placeholder=”Enter username”&gt;</p><p>Here, value=”user123&quot;, type=”text”, and placeholder=”Enter username” are attributes.</p><h3>What is a Property?</h3><p>A <strong>property</strong> is a representation of an attribute in the DOM. Once the page is loaded, attributes are translated into properties, and the browser maintains them dynamically. Properties can change as the user interacts with the webpage.</p><p><strong>Example:</strong> If the user types “newUser” into the input field, the value property is updated, but the value attribute remains the same as initially defined in the HTML.</p><h3>Selenium’s deprecated method getAttribute()</h3><p>Selenium’s traditional getAttribute() method returns either the attribute or the property depending on the user’s input. Even if it’s deprecated, it’s still available for backward compatibility purposes.</p><p>Lets move to our original topic now.</p><h3>What is getDomProperty()?</h3><p>The getDomProperty() method is used to retrieve the <strong>current property value</strong> of an element from the <strong>DOM</strong>. It returns the <strong>real-time state</strong> of a property as interpreted by the browser.</p><h3>What is getDomAttribute()?</h3><p>The getDomAttribute() method retrieves the <strong>initial attribute value</strong> of an element as defined in the <strong>HTML source</strong>.</p><h3>Practical Example with a Login Form</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/0*S6fltYrdnv-Z60Kr" /></figure><h4>Consider an input field in HTML:</h4><blockquote><em>&lt;div&gt;TextBox&lt;input id=”input” type=”text” value=”htmlvalue”&gt;&lt;/div&gt;</em></blockquote><p>If we run the following Selenium code:</p><blockquote>WebElement q = driver.findElement(By.<em>id</em>(“input”));</blockquote><blockquote>//First get default output of these function</blockquote><blockquote>System.<strong><em>out</em></strong>.println(“Value attribute:” + q.getDomAttribut(“value”));</blockquote><blockquote>System.<strong><em>out</em></strong>.println(“Value property:” + q.getDomProperty(“value”));</blockquote><blockquote>//Type some text</blockquote><blockquote>q.clear();</blockquote><blockquote>q.sendKeys(“abcd”);</blockquote><blockquote>//Check how property value changes now</blockquote><blockquote>System.<strong><em>out</em></strong>.println(“\n Value attribute:” + q.getDomAttribute(“value”));</blockquote><blockquote>System.<strong><em>out</em></strong>.println(“Value property:” + q.getDomProperty(“value”));</blockquote><h3>Output Before User Input:</h3><blockquote>Value attribute:htmlvalue</blockquote><blockquote>Value property:htmlvalue</blockquote><blockquote>Value attribute:htmlvalue</blockquote><blockquote>Value property:abcd</blockquote><p>This shows that getDomProperty(“value”) reflects the updated value, whereas getDomAttribute(“value”) retains the original HTML attribute value.</p><h3>Difference Between getDomProperty() and getDomAttribute()</h3><p><strong>getDomProperty()</strong></p><blockquote><strong>Returns</strong>: The current property value from the DOM</blockquote><blockquote><strong>Reflects JS Changes? :</strong> Yes, it updates with the latest value</blockquote><blockquote><strong>Works Best For:</strong> Properties like value, checked, disabled</blockquote><p><strong>getDomAttribute()</strong></p><blockquote><strong>Returns</strong>: The initial attribute value from HTML</blockquote><blockquote><strong>Reflects JS Changes?</strong> : No, it might retain the original value</blockquote><blockquote><strong>Works Best For: </strong>Attributes like placeholder, type, maxlength</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c31886f07b54" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>