<?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 Prajaktadendge on Medium]]></title>
        <description><![CDATA[Stories by Prajaktadendge on Medium]]></description>
        <link>https://medium.com/@prajaktadendge22?source=rss-df51c379abc9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*gnXTiJnCT9kL6tMh</url>
            <title>Stories by Prajaktadendge on Medium</title>
            <link>https://medium.com/@prajaktadendge22?source=rss-df51c379abc9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 14:13:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prajaktadendge22/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[Stack vs Queue in Java: When Should You Use Each?]]></title>
            <link>https://medium.com/@prajaktadendge22/stack-vs-queue-in-java-when-should-you-use-each-be456358dec1?source=rss-df51c379abc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/be456358dec1</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Prajaktadendge]]></dc:creator>
            <pubDate>Sat, 05 Sep 2026 18:54:27 GMT</pubDate>
            <atom:updated>2026-09-05T18:54:27.853Z</atom:updated>
            <content:encoded><![CDATA[<p>Understand LIFO and FIFO with simple Java examples, real-world analogies, time complexity, and practical DSA use cases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OgGL7THsIld8titO3eDPQA.png" /></figure><p>Imagine you’re managing a pile of books. Would you pick the book you placed last, or the one you placed first?</p><h3>*Introduction</h3><p>In programming, we often need to store and organize data in a way that makes it easy to access and process. This is where <strong>data structures</strong> become important. They help us manage data efficiently and make our programs easier to design and understand.</p><p>Two fundamental data structures that every Java and DSA beginner should know are <strong>Stack</strong> and <strong>Queue</strong>. Both are used to store and manage collections of elements, but they follow different rules for adding and removing data.</p><p>A <strong>Stack</strong> follows the <strong>LIFO (Last In, First Out)</strong> principle, while a <strong>Queue</strong> follows the <strong>FIFO (First In, First Out)</strong> principle. Understanding this difference helps us choose the right data structure for a particular problem.</p><p>In this article, we will explore <strong>Stack and Queue in Java</strong>, understand how they work, look at their basic operations, see real-world applications, compare their differences, and learn when we should use a Stack or a Queue in DSA problems.</p><h3><strong>*What is stack?</strong></h3><p>A <strong>Stack</strong> is a linear data structure that stores and manages elements according to the <strong>LIFO (Last In, First Out)</strong> principle.</p><p>In a Stack, the element that is <strong>added last is removed first</strong>. All insertion and deletion operations take place at one end, called the <strong>top</strong>.</p><h3>LIFO — Last In, First Out</h3><p>LIFO means that the most recently added element gets removed first.</p><p>For example, if we add three elements:</p><pre>10 → 20 → 30</pre><p>The last element added is 30, so it will be the first element removed.</p><pre>TOP<br>        ↓<br>      ┌────┐<br>      │ 30 │  ← Removed first<br>      ├────┤<br>      │ 20 │<br>      ├────┤<br>      │ 10 │<br>      └────┘</pre><h3>*Real-Life Example: Stack of Plates</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dQylT3AW8bl5TCL03d7cig.png" /></figure><p>A simple real-life example of a Stack is a <strong>stack of plates</strong>.</p><p>When you place a new plate, you put it on the top. When you need a plate, you also take the top plate first.</p><p>So:</p><p><strong>Last plate placed → First plate removed</strong></p><p>This is exactly how the LIFO principle works.</p><h3>*Basic Stack Operations</h3><p>A Stack mainly provides these operations:</p><ul><li><strong>push()</strong> — Adds an element to the top.</li><li><strong>pop()</strong> — Removes the top element.</li><li><strong>peek()</strong> — Returns the top element without removing it.</li><li><strong>isEmpty()</strong> — Checks whether the Stack is empty.</li></ul><h3>*Stack Implementation in Java</h3><p>In modern Java code, a Deque such as ArrayDeque is commonly used when we need Stack behavior.</p><pre>import java.util.ArrayDeque;<br>import java.util.Deque;</pre><pre>public class StackExample {<br>    public static void main(String[] args) {</pre><pre>        Deque&lt;Integer&gt; stack = new ArrayDeque&lt;&gt;();</pre><pre>        // Adding elements<br>        stack.push(10);<br>        stack.push(20);<br>        stack.push(30);</pre><pre>        // View the top element<br>        System.out.println(&quot;Top: &quot; + stack.peek());</pre><pre>        // Remove the top element<br>        System.out.println(&quot;Removed: &quot; + stack.pop());</pre><pre>        // Display remaining elements<br>        System.out.println(&quot;Stack: &quot; + stack);<br>    }<br>}</pre><h3>Output</h3><pre>Top: 30<br>Removed: 30<br>Stack: [20, 10]</pre><p>Here, 30 was added last, so it was removed first. This demonstrates the <strong>LIFO</strong> principle of a Stack.</p><p>In the next section, we will look at <strong>where Stacks are used in real-world applications and DSA problems</strong>.</p><h3>Stack Operations</h3><p>A Stack mainly performs four basic operations: <strong>push, pop, peek, and isEmpty</strong>. These operations allow us to add, remove, and check elements in a Stack.</p><h3>1. push() — Add an Element</h3><p>The push() operation is used to <strong>add an element to the top of the Stack</strong>.</p><p>For example:</p><pre>stack.push(10);<br>stack.push(20);<br>stack.push(30);</pre><p>The Stack becomes:</p><pre>TOP<br> ↓<br>30<br>20<br>10</pre><p>Here, 30 is at the top because it was added last.</p><h3>2. pop() — Remove an Element</h3><p>The operation <strong>pop() removes and returns the top element</strong> from the Stack.</p><pre>System.out.println(stack.pop());</pre><p>Output:</p><pre>30</pre><p>After :pop()</p><pre>TOP<br> ↓<br>20<br>10</pre><p>Since Stack follows <strong>LIFO</strong>, the last element added (30) is removed first.</p><h3>3. peek() — View the Top Element</h3><p>The peek() operation <strong>returns the top element without removing it</strong>.</p><pre>System.out.println(stack.peek());</pre><p>Output:</p><pre>20</pre><p>The Stack remains unchanged:</p><pre>TOP<br> ↓<br>20<br>10</pre><p>So, remember:</p><p><strong>peek() → See the top element</strong><br><strong>pop() → Remove the top element</strong></p><h3>4. isEmpty() — Check the Stack</h3><p>The isEmpty() operation checks whether the Stack contains any elements.</p><pre>System.out.println(stack.isEmpty());</pre><p>If the Stack contains elements:</p><pre>false</pre><p>If the Stack has no elements:</p><pre>true</pre><h3>Complete Example</h3><p>Here is a simple Java program demonstrating all four operations:</p><pre>import java.util.ArrayDeque;<br>import java.util.Deque;</pre><pre>public class StackOperations {<br>    public static void main(String[] args) {</pre><pre>        Deque&lt;Integer&gt; stack = new ArrayDeque&lt;&gt;();</pre><pre>        // push() - add elements<br>        stack.push(10);<br>        stack.push(20);<br>        stack.push(30);</pre><pre>        System.out.println(&quot;Stack: &quot; + stack);</pre><pre>        // peek() - view top element<br>        System.out.println(&quot;Top element: &quot; + stack.peek());</pre><pre>        // pop() - remove top element<br>        System.out.println(&quot;Removed element: &quot; + stack.pop());</pre><pre>        // isEmpty() - check Stack<br>        System.out.println(&quot;Is stack empty? &quot; + stack.isEmpty());</pre><pre>        System.out.println(&quot;Remaining stack: &quot; + stack);<br>    }<br>}</pre><h3>Output</h3><pre>Stack: [30, 20, 10]<br>Top element: 30<br>Removed element: 30<br>Is stack empty? false<br>Remaining stack: [20, 10]</pre><h3>Quick Summary</h3><p>OperationWhat it doesTime Complexity <strong>push()</strong>Adds an elementO(1) amortized <strong>pop()</strong>Removes the top elementO(1) amortized <strong>peek() </strong>Views the top elementO(1)<strong> isEmpty() </strong>Checks whether Stack is emptyO(1)</p><p>The key idea is simple: <strong>push adds to the top, pop removes from the top, peek looks at the top, and isEmpty checks whether anything is left.</strong></p><h3>*Where Do We Use a Stack?</h3><p><strong>1. Undo/Redo</strong><br> Stacks can store recent actions performed by a user. When the user clicks Undo, the most recent action is removed first, following the LIFO principle.</p><p><strong>2. Browser History</strong><br> Browser navigation can use stack-like behavior to keep track of recently visited pages. When going back, the most recently visited page is accessed first.</p><p><strong>3. Function Calls</strong><br> Programming languages use a <strong>call stack</strong> to manage function execution. When a function calls another function, the new function is placed on top and is completed before returning to the previous one.</p><p><strong>4. Parentheses Matching</strong><br> A stack can be used to check whether brackets such as (), {}, and [] are correctly balanced. Opening brackets are pushed onto the stack, and matching closing brackets remove them.</p><p><strong>5. Depth-First Search (DFS)</strong><br> DFS uses a stack to explore a graph or tree by going as deep as possible before backtracking. It can be implemented using an explicit stack or through recursion.</p><h3><strong>*What is a Queue?</strong></h3><p>A <strong>Queue</strong> is a linear data structure that follows the <strong>FIFO (First In, First Out)</strong> principle. This means the element that is added <strong>first is removed first</strong>.</p><p>Unlike a Stack, where insertion and deletion happen at the same end, a Queue generally adds elements from the <strong>rear</strong> and removes them from the <strong>front</strong>.</p><h3>FIFO — First In, First Out</h3><p>FIFO means that the element that enters the Queue first will leave first.</p><p>For example, if we add three elements:</p><pre>10 → 20 → 30</pre><p>The first element added is 10, so it will be removed first.</p><pre>FRONT                    REAR<br>  ↓                        ↓<br>[10] → [20] → [30]<br> ↑<br>Removed first</pre><h3>Real-Life Example: Ticket Counter</h3><p>A Queue can be compared to people waiting in line at a ticket counter.</p><p>The person who arrives first is served first, while people who arrive later wait behind them.</p><p><strong>First person in line → First person served</strong></p><p>This is exactly how the <strong>FIFO</strong> principle works.</p><h3>Basic Queue Operations</h3><p>A Queue mainly provides these operations:</p><ul><li><strong>offer()</strong> — Adds an element to the rear of the Queue.</li><li><strong>poll()</strong> — Removes and returns the front element.</li><li><strong>peek()</strong> — Returns the front element without removing it.</li><li><strong>isEmpty()</strong> — Checks whether the Queue is empty.</li></ul><h3>Queue Implementation in Java</h3><p>In Java, Queue is an interface. A common implementation is ArrayDeque.</p><pre>import java.util.ArrayDeque;<br>import java.util.Queue;</pre><pre>public class QueueExample {<br>    public static void main(String[] args) {</pre><pre>        Queue&lt;Integer&gt; queue = new ArrayDeque&lt;&gt;();</pre><pre>        // Adding elements<br>        queue.offer(10);<br>        queue.offer(20);<br>        queue.offer(30);</pre><pre>        // View the front element<br>        System.out.println(&quot;Front: &quot; + queue.peek());</pre><pre>        // Remove the front element<br>        System.out.println(&quot;Removed: &quot; + queue.poll());</pre><pre>        // Display remaining elements<br>        System.out.println(&quot;Queue: &quot; + queue);<br>    }<br>}</pre><h3>Output</h3><pre>Front: 10<br>Removed: 10<br>Queue: [20, 30]</pre><p>Here, 10 was added first, so it was removed first. This demonstrates the <strong>FIFO</strong> principle of a Queue.</p><h3>*Queue Operations in Java</h3><p>A Queue provides several operations to add, remove, and check elements. The four basic operations are offer(), poll(), peek(), and isEmpty().</p><h3>1. offer() — Add an Element</h3><p>The offer() method is used to <strong>add an element to the rear of the Queue</strong>.</p><pre>queue.offer(10);<br>queue.offer(20);<br>queue.offer(30);</pre><p>The Queue becomes:</p><pre>FRONT              REAR<br> ↓                    ↓<br>[10] → [20] → [30]</pre><p>Here, 30 is added at the rear.</p><h3>2. poll() — Remove an Element</h3><p>The poll() method <strong>removes and returns the front element</strong> of the Queue.</p><pre>System.out.println(queue.poll());</pre><p>Output:</p><pre>10</pre><p>After removing 10:</p><pre>FRONT        REAR<br> ↓             ↓<br>[20] → [30]</pre><p>Because Queue follows <strong>FIFO</strong>, the first element added (10) is removed first.</p><h3>3. peek() — View the Front Element</h3><p>The peek() method <strong>returns the front element without removing it</strong>.</p><pre>System.out.println(queue.peek());</pre><p>If the Queue is:</p><pre>[20] → [30]<br> ↑<br>FRONT</pre><p>The output is:</p><pre>20</pre><p>The Queue remains unchanged.</p><p><strong>Remember:</strong><br>peek()→ View the front element<br>poll() → Remove the front element</p><h3>4. isEmpty() — Check the Queue</h3><p>The isEmpty method checks whether the Queue contains any elements.</p><pre>System.out.println(queue.isEmpty());</pre><p>If elements are present:</p><pre>false</pre><p>If the Queue contains no elements:</p><pre>true</pre><h3>Quick Summary</h3><p>OperationPurposeTime Complexity offer() Adds an element to the rearO(1) amortized poll() Removes the front elementO(1) amortized peek()cViews the front elementO(1) isEmpty() Checks whether Queue is emptyO(1)</p><p>The easiest way to remember Queue operations is:</p><p><strong>offer() → Add</strong><br><strong>poll()→ Remove</strong><br><strong>peek()→ See</strong><br><strong>isEmpty()→ Check</strong></p><h3><strong>*Stack vs Queue Comparison</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*0ezagNPZenyWnVD3QlHtWQ.png" /></figure><h3>*Where Do We Use a Queue?</h3><p><strong>1. Printer Queue</strong><br> Print requests are stored in a queue and are usually processed in the order they arrive. This follows the FIFO principle.</p><p><strong>2. CPU Scheduling</strong><br> Processes waiting for CPU time can be managed using queue-based scheduling. Processes are handled according to the scheduling method being used.</p><p><strong>3. Customer Service</strong><br> Customers can be placed in a queue and served in the order they arrive. The first customer to join the line is generally served first.</p><p><strong>4. Breadth-First Search (BFS)</strong><br> BFS uses a queue to visit nodes level by level in a tree or graph. The node discovered first is processed first.</p><p><strong>5. Task Processing</strong><br> Tasks waiting to be processed can be stored in a queue. This helps process tasks in an organized order.</p><h3>1. When Should You Use a Stack?</h3><p>Use a Stack when you need the <strong>most recently added element to be processed first</strong>.</p><p>A Stack is useful when your problem involves reversing actions, going backward, or tracking the most recent operation.</p><p>Common examples include:</p><ul><li><strong>Undo/Redo operations</strong></li><li><strong>Backtracking</strong></li><li><strong>Depth-First Search (DFS)</strong></li><li><strong>Parentheses matching</strong></li><li><strong>Expression evaluation</strong></li></ul><p>A simple rule to remember:</p><blockquote><strong><em>If you need Last In, First Out (LIFO) behavior, think of a Stack.</em></strong></blockquote><h3>2. When Should You Use a Queue?</h3><p>Use a Queue when you need the <strong>first added element to be processed first</strong>.</p><p>A Queue is useful when elements need to be handled in the order they arrive.</p><p>Common examples include:</p><ul><li><strong>Breadth-First Search (BFS)</strong></li><li><strong>Task scheduling</strong></li><li><strong>Printer queues</strong></li><li><strong>Customer service systems</strong></li><li><strong>Request processin</strong></li></ul><p>A simple rule to remember:</p><blockquote><strong><em>If you need First In, First Out (FIFO) behavior, think of a Queue.</em></strong></blockquote><h3>3. Stack and Queue Using Deque in Java</h3><p>Java provides the Deque interface, which stands for <strong>Double-Ended Queue</strong>. It allows elements to be added or removed from both ends.</p><p>A Deque can be used as a Stack:</p><pre>Deque&lt;Integer&gt; stack = new ArrayDeque&lt;&gt;();</pre><pre>stack.push(10);<br>stack.push(20);<br>stack.push(30);</pre><pre>System.out.println(stack.pop());</pre><p>Output:</p><pre>30</pre><p>It can also be used as a Queue:</p><pre>Deque&lt;Integer&gt; queue = new ArrayDeque&lt;&gt;();</pre><pre>queue.offer(10);<br>queue.offer(20);<br>queue.offer(30);</pre><pre>System.out.println(queue.poll());</pre><p>Output:</p><pre>10</pre><p>This makes ArrayDeque a useful choice when you need Stack or Queue behavior in Java.</p><h3>4. Time Complexity</h3><p>For typical ArrayDeque operations, adding and removing elements from the appropriate end is <strong>O(1) amortized</strong>, while accessing the next element with peek() is <strong>O(1)</strong>.</p><p>OperationStackQueueInsertO(1) amortizedO(1) amortizedRemoveO(1) amortizedO(1) amortizedPeekO(1)O(1)SearchO(n)O(n)</p><p>Understanding time complexity helps us choose an efficient data structure for a particular problem.</p><h3>5. Common Beginner Mistakes</h3><p>When learning Stack and Queue, beginners often confuse their operations and behavior.</p><h3>Mistake 1: Confusing LIFO and FIFO</h3><p>Remember:</p><p><strong>Stack → LIFO</strong><br><strong>Queue → FIFO</strong></p><h3>Mistake 2: Confusing pop() and peek()</h3><p>pop() removes the top element, while peek() only looks at the top element.</p><h3>Mistake 3: Confusing poll() and peek()</h3><p>poll() removes the front element of a Queue, while peek() only views it.</p><h3>Mistake 4: Choosing the wrong data structure</h3><p>Before choosing Stack or Queue, ask yourself:</p><blockquote><strong><em>Should the newest element come out first, or should the oldest element come out first?</em></strong></blockquote><p>This simple question can help you choose the correct structure.</p><h3>6. Stack &amp; Queue in DSA</h3><p>Stack and Queue are not just theoretical concepts. They are used extensively in <strong>Data Structures and Algorithms (DSA)</strong>.</p><h3>Stack in DSA</h3><p>Stacks are commonly used for:</p><ul><li><strong>DFS (Depth-First Search)</strong></li><li><strong>Backtracking</strong></li><li><strong>Monotonic Stack problems</strong></li><li><strong>Parentheses problems</strong></li><li><strong>Next Greater Element problems</strong></li></ul><h3>Queue in DSA</h3><p>Queues are commonly used for:</p><ul><li><strong>BFS (Breadth-First Search)</strong></li><li><strong>Binary Tree Level Order Traversal</strong></li><li><strong>Shortest path in unweighted graphs</strong></li><li><strong>Task scheduling</strong></li><li><strong>Level-by-level processing</strong></li></ul><p>Recognizing whether a DSA problem requires LIFO or FIFO behavior can make the solution much easier to design.</p><h3>7. Conclusion</h3><p>Stack and Queue are two fundamental data structures that every Java and DSA beginner should understand.</p><p>A <strong>Stack follows LIFO</strong>, making it useful when the most recently added element needs to be processed first. A <strong>Queue follows FIFO</strong>, making it useful when elements should be processed in the order they arrive.</p><p>The most important thing is not simply memorizing methods like push(), pop(), offer(), and poll(). Instead, understand <strong>when and why to use each data structure</strong>.</p><p>Once you understand the difference between LIFO and FIFO, choosing between a Stack and a Queue becomes much easier.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be456358dec1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Java OOPs Concepts: The 4 Pillars Every Beginner Should Understand”.]]></title>
            <link>https://medium.com/@prajaktadendge22/java-oops-concepts-the-4-pillars-every-beginner-should-understand-fdcc06475c7d?source=rss-df51c379abc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/fdcc06475c7d</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[objectorientedprogramming]]></category>
            <category><![CDATA[oops-in-java]]></category>
            <dc:creator><![CDATA[Prajaktadendge]]></dc:creator>
            <pubDate>Tue, 01 Sep 2026 15:20:48 GMT</pubDate>
            <atom:updated>2026-09-01T15:20:48.599Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*udJsHnlYvrShlxVh4FEzwQ.png" /></figure><h3><strong>*What is oops?</strong></h3><p>Introduction:- Object-Oriented Programming (OOPs) is a programming approach that organizes code around <strong>objects and classes</strong> rather than just functions and logic. In Java, OOPs is one of the most important concepts because it helps developers create code that is <strong>organized, reusable, secure, and easier to maintain</strong>.</p><p>Instead of thinking only about <em>what the program should do</em>, OOPs encourages us to think about <strong>objects, their properties, and their behaviors</strong>.</p><p>For example, in a student management system, a <strong>Students</strong> can be an object with properties like <strong>name</strong>, <strong>age,</strong> and<strong> marks</strong>, along with behaviors such as <strong>study()</strong> or <strong>displayDetails().</strong></p><p>In Java, OOPs is mainly built around <strong>four important pillars: Encapsulation, Inheritance, Polymorphism, and Abstraction</strong>. These concepts form the foundation for writing structured and scalable Java applications.</p><h3><strong>*Why OOPs is important in Java?</strong></h3><p>OOPs is important in Java because it helps developers build programs that are <strong>organized, reusable, secure, and easier to maintain</strong>. Instead of writing everything in one place, OOPs divides a program into <strong>classes and objects</strong>, making complex applications easier to understand and manage.</p><p>Here are some key benefits of OOPs in Java:</p><ul><li><strong>Code Reusability:</strong> Inheritance allows us to reuse existing code instead of writing it again.</li><li><strong>Data Security:</strong> Encapsulation helps protect data by restricting direct access to it.</li><li><strong>Flexibility:</strong> Polymorphism allows the same method or interface to behave differently in different situations.</li><li><strong>Easy Maintenance:</strong> Code is organized into classes and objects, making it easier to modify and debug.</li><li><strong>Scalability:</strong> OOPs makes it easier to expand applications as they become larger and more complex.</li><li><strong>Real-World Modeling:</strong> Objects can represent real-world entities such as ,Student, BankAccount, car, or Employee.</li></ul><h3><strong>*Class and Object in Java.</strong></h3><h4>What is a Class?</h4><p>A <strong>class</strong> is a blueprint or template used to create objects. It defines the <strong>properties (data)</strong> and <strong>behaviors (methods)</strong> that an object can have.</p><p>For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*0U4kTxYy3-plqWyKeTrCWQ.png" /></figure><p>Here, Students is a class. It defines the data (name, age) and behavior (Study()).</p><h4>What is an Object?</h4><p>An <strong>object</strong> is a real instance of a class. It is created using the <strong>new </strong>keyword.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*F76hzSPxWSAyXnH2rbPwyg.png" /></figure><p>Here,<strong> s1</strong> is an object of the Students class.</p><p><strong>Simple Real-Life Example:</strong></p><p>Think of a <strong>class as a blueprint of a house</strong> 🏠 and an <strong>object as the actual house</strong> built from that blueprint.</p><ul><li><strong>Class</strong> → Blueprint</li><li><strong>Object</strong> → Real instance</li><li><strong>Variables</strong> → Properties</li><li><strong>Methods</strong> → Behaviors</li></ul><h4>simple you remember: <strong><em>class = Blueprint | Object = Instance of that Blueprint.</em></strong></h4><h3>*The 4 Pillars of<strong> OOPS.</strong></h3><ul><li>Encapsulation</li><li>Inheritance</li><li>Polymorphism</li><li>Abstraction</li></ul><h3><strong>*Real Life Example</strong></h3><p>A simple way to understand OOPs is to think about a <strong>Bank Account</strong>.</p><p>Imagine a bank application where every customer has a bank account. We can represent a bank account using a <strong>class</strong>, and each customer’s account can be represented as an <strong>object</strong>.</p><p>For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*Pipwt3L9T5fxI3lkBjX6Vg.png" /></figure><p>create an object:</p><p>BankAccount account1 = new BankAccount();</p><p>Here:</p><ul><li><strong>Class</strong> → <strong>BankAccount </strong>is the blueprint.</li><li><strong>Object</strong> → account1 is a real instance of the class.</li><li><strong>Properties</strong> → <strong>holdername</strong> and balance.</li><li><strong>Methods</strong> → <strong>deposite()</strong> and <strong>showbalance().</strong></li></ul><p>This example also shows <strong>Encapsulation</strong>, because the balance is declared private, so it cannot be accessed directly from outside the class.</p><h3>*Connecting It to the 4 Pillars</h3><p>The same bank application can demonstrate all four OOPs concepts:</p><p>🔒 <strong>Encapsulation</strong> → Protecting account balance and customer data.</p><p>♻️ <strong>Inheritance</strong> → Creating <strong>SavingAccount </strong>and <strong>CurrentAccount</strong> from a common <strong>BankAccount</strong> class.</p><p>🔄 <strong>Polymorphism</strong> → Different account types can have different implementations of methods such as <strong>calculateinterest()</strong>.</p><p>🎯 <strong>Abstraction</strong> → Showing essential banking operations while hiding their internal implementation.</p><h3>*Small Java Program Combining OOPs Concepts</h3><p>Let’s combine the <strong>four pillars of OOPs-</strong>Encapsulation, Inheritance, Polymorphism, and Abstraction</p><p>simple java program:</p><p>abstract class Animal {<br> // Abstraction<br> abstract void sound();</p><p>void eat() {<br> System.out.println(“Animal is eating”);<br> }<br>}</p><p>// Inheritance<br>class Dog extends Animal {</p><p>private String name; // Encapsulation</p><p>Dog(String name) {<br> this.name = name;<br> }</p><p>// Polymorphism — Method Overriding<br> <a href="http://twitter.com/Override">@Override</a><br> void sound() {<br> System.out.println(name + “ says: Woof!”);<br> }<br>}</p><p>public class Main {<br> public static void main(String[] args) {</p><p>// Object creation<br> Dog dog = new Dog(“Bruno”);</p><p>dog.eat();<br> dog.sound();<br> }<br>}</p><p>OUTPUT:</p><p>Animal is eating<br>Bruno says: Woof!</p><h3>How the 4 Pillars Are Used</h3><ul><li><strong>Abstraction:</strong> <strong><em>Animal</em></strong><em> </em>is an abstract class and <strong><em>sound()</em></strong>is an abstract method.</li><li><strong>Inheritance:</strong> <strong><em>Dog</em></strong> inherits from <strong><em>Animal</em></strong> using <strong><em>extends</em></strong>.</li><li><strong>Encapsulation:</strong> <strong><em>name</em></strong> is declared <strong><em>private </em></strong>and accessed within the class.</li><li><strong>Polymorphism:</strong> <strong><em>Dog</em></strong> provides its own implementation of the <strong><em>sound()</em></strong> method.</li></ul><h3><strong>Conclusion:</strong></h3><p>Object-Oriented Programming is one of the most important foundations of Java. By understanding <strong>Classes, Objects, Encapsulation, Inheritance, Polymorphism, and Abstraction</strong>, beginners can start writing more structured and maintainable programs.</p><p>The four pillars of OOPs are not just theoretical concepts — they help us solve real-world problems by organizing code in a clear and reusable way.</p><p>As you continue learning Java, understanding OOPs will make advanced topics such as <strong>Collections, Exception Handling, Multithreading, and Frameworks</strong> much easier to understand.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fdcc06475c7d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why 0.1 + 0.2 Is Not Exactly 0.3 in Java]]></title>
            <link>https://medium.com/@prajaktadendge22/why-0-1-0-2-is-not-exactly-0-3-in-java-3e472c4b6df1?source=rss-df51c379abc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e472c4b6df1</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[computer-science-coding]]></category>
            <dc:creator><![CDATA[Prajaktadendge]]></dc:creator>
            <pubDate>Sat, 29 Aug 2026 11:41:01 GMT</pubDate>
            <atom:updated>2026-08-29T11:41:01.332Z</atom:updated>
            <content:encoded><![CDATA[<p>In mathematics, we know:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LKm6SWrYYg6e-XCzYooZpw.png" /></figure><pre>0.1 + 0.2 = 0.3</pre><p>So, if we write this in Java:</p><pre>double result = 0.1 + 0.2;<br>System.out.println(result);</pre><p>we might expect:</p><pre>0.3</pre><p>But Java prints:</p><pre>0.30000000000000004</pre><p>And this:</p><pre>System.out.println(result == 0.3);</pre><p>prints:</p><pre>false</pre><p>So, what is happening? 🤔</p><h3>* The Real Reason</h3><p>The problem is <strong>not the calculation</strong>.</p><p>The problem is <strong>how computers store numbers</strong>.</p><p>Humans normally use the <strong>decimal system (Base 10)</strong>. Numbers like 0.1, 0.2, and 0.3 are easy for us to represent.</p><p>Computers, however, use the <strong>binary system (Base 2)</strong>, which only works with 0 and 1.</p><p>Some decimal numbers cannot be represented exactly in binary.</p><p>For example, 0.1 has a repeating representation when converted to binary. Since a computer has limited storage, it cannot keep that representation forever.</p><p>So, it stores the <strong>closest possible value</strong>.</p><p>The same thing happens with 0.2 .</p><h3>* What Happens During Addition?</h3><p>When Java calculates:</p><pre>0.1 + 0.2</pre><p>it is actually adding the stored approximations of those numbers.</p><p>Because those values are not perfectly exact, the result can become:</p><pre>0.30000000000000004</pre><p>It is extremely close to 0.3, but it is not exactly the same value.</p><p>That’s why:</p><pre>0.1 + 0.2 == 0.3</pre><p>returns:</p><pre>false</pre><h3>* A Simple Way to Think About It</h3><p>Imagine you want to measure exactly <strong>1 meter</strong>, but your measuring tool can only measure up to a certain precision.</p><p>You might get:</p><pre>1.00000001 meters</pre><p>That is practically 1 meter, but technically it is not exactly 1 meter.</p><p>Floating-point numbers work in a similar way.</p><h3>* How Should We Compare Floating-Point Numbers?</h3><p>Instead of checking exact equality with == we can check whether the difference is small enough:</p><pre>double a = 0.1 + 0.2;<br>double b = 0.3;</pre><pre>double epsilon = 0.000001;</pre><pre>if (Math.abs(a - b) &lt; epsilon) {<br>    System.out.println(&quot;Values are almost equal&quot;);<br>}</pre><p>Here, we are not asking:</p><blockquote><em>“Are these numbers exactly the same?”</em></blockquote><p>We are asking:</p><blockquote><em>“Is the difference between them so small that we can consider them equal?”</em></blockquote><h3>* What About Money?</h3><p>For financial calculations, even a tiny rounding difference can matter.</p><p>That’s why Java provides BigDecimal for accurate decimal calculations.</p><pre>BigDecimal a = new BigDecimal(&quot;0.1&quot;);<br>BigDecimal b = new BigDecimal(&quot;0.2&quot;);</pre><pre>System.out.println(a.add(b));</pre><p>Output:</p><pre>0.3</pre><h3>* Final Takeaway</h3><h3>0.1 + 0.2 is mathematically 0.3.</h3><p>The unexpected result happens because double uses <strong>binary floating-point representation</strong>, and some decimal values cannot be stored exactly.</p><p>So, remember:</p><p><strong>The mathematics is correct. The difference comes from how the computer represents the numbers.</strong></p><p>For normal calculations, double is useful. When exact decimal precision is important, use BigDecimal.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e472c4b6df1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Time Complexity VS Space Complexity What Should We Focus on ?]]></title>
            <link>https://medium.com/@prajaktadendge22/time-complexity-vs-space-complexity-what-should-we-focus-on-941dd465fd86?source=rss-df51c379abc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/941dd465fd86</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[space-complexity]]></category>
            <category><![CDATA[time-complexity]]></category>
            <category><![CDATA[time-vs-space]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Prajaktadendge]]></dc:creator>
            <pubDate>Wed, 19 Aug 2026 15:38:38 GMT</pubDate>
            <atom:updated>2026-08-19T15:38:38.420Z</atom:updated>
            <content:encoded><![CDATA[<h3>* <strong>Time complexity :</strong></h3><p>Time Complexity tells us how the running time of an algorithm grows as the input size increases.<br>It does not mean the exact time in seconds.<br>Instead, it describes how the number of operations grows when the input becomes larger.</p><p>example: Method 1. checking everyone</p><p>You start from the first student and check one by one.<br>If there are 10 students, you may check up to 10 students.<br>If there are 1,000 students, you may need to check up to 1,000 students.</p><p>Method 2. Looking up directly</p><p>Now imagine that every student has a unique roll number and you have an organized system that directly tells you where that student is.<br>You can find the student without checking everyone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SAZPve6yDNqFzbMCI5Nbkg.png" /></figure><h3><strong>*Space complexity :</strong></h3><p>Alower space complexity means the program uses less memory. Space Complexity becomes especially important when the available memory is limited.</p><p>Example: Option 1: Carry only the essentials.</p><p>you carry:</p><p>phone ,Wallet, Water bottle.</p><p>You use very little space.</p><p>Option 2: Carry Everything</p><p>you dicide to carry:</p><p>Extra clothes , Multiple books, Extra bags,Many unnecessary items.</p><p>Now you need much more storage space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9gLwVWB3UlxC3QSdl5cxFQ.png" /></figure><h3><strong>*Time-Space Trade-off :</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F8zSEtfXoj5Lpm4I7neMuA.jpeg" /></figure><p>In real-world programming, we don’t always try to minimize only time or only space.<br>Instead, we try to find a good balance.<br>Example:<br>Algorithm A<br>Time → O(n)<br>Space → O(n)<br>Algorithm B<br>Time → O(n²)<br>Space → O(1)<br>Which one is better?<br>There is no universal answer.<br>If speed is critical and memory is available, Algorithm A may be preferable.<br>If memory is extremely limited, Algorithm B may sometimes be considered.<br>The correct choice depends on the problem and its constraints.</p><h3><strong>* What Should We Focus On?</strong></h3><h4>My answer is: Time Complexity should usually get higher priority, especially when the input size is large.<br>While solving coding problems, first think about:<br>Is my algorithm correct?<br>How much time does it take?<br>Can I reduce unnecessary operations?<br>What happens when the input becomes very large?<br>Does the algorithm remain efficient for large inputs?<br>After that, consider:<br>How much extra memory does it use?<br>Can I reduce unnecessary memory usage?</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=941dd465fd86" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>