<?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 Saugat Mudbhari on Medium]]></title>
        <description><![CDATA[Stories by Saugat Mudbhari on Medium]]></description>
        <link>https://medium.com/@smudbhari85?source=rss-a52b177f5028------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Mcic5-6ucY8vqQLi</url>
            <title>Stories by Saugat Mudbhari on Medium</title>
            <link>https://medium.com/@smudbhari85?source=rss-a52b177f5028------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 02:27:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@smudbhari85/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[From Singleton to JVM Memory: A Deep Dive into Class Loading, Object Layout, and Why Inheritance Is…]]></title>
            <link>https://medium.com/@smudbhari85/from-singleton-to-jvm-memory-a-deep-dive-into-class-loading-object-layout-and-why-inheritance-is-34100e644e78?source=rss-a52b177f5028------2</link>
            <guid isPermaLink="false">https://medium.com/p/34100e644e78</guid>
            <category><![CDATA[singleton]]></category>
            <category><![CDATA[inheritance]]></category>
            <category><![CDATA[jvm]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Saugat Mudbhari]]></dc:creator>
            <pubDate>Sun, 19 Apr 2026 14:31:21 GMT</pubDate>
            <atom:updated>2026-04-20T07:02:18.612Z</atom:updated>
            <content:encoded><![CDATA[<h3>From Singleton to JVM Memory: A Deep Dive into Class Loading, Object Layout, and Why Inheritance Is Not Shared Memory</h3><p>In my <strong>Java development journey</strong>, I have found that in enterprise Java development, it is common to find dozens or hundreds of <strong>JPA entities</strong> extending a single AbstractEntity base class. This design pattern, while ubiquitous, often triggers a subtle but profound confusion:</p><blockquote><em>If the base class contains shared fields like </em><em>createdDate and </em><em>modifiedBy, are we duplicating memory across all subclasses? Would a </em><strong><em>Singleton</em></strong><em> be more efficient?</em></blockquote><h3>The “Aha” Moment: Seeing the Code</h3><p>I often encountered this specific structure in my projects:</p><pre>@Setter<br>@Getter<br>@MappedSuperclass<br>@EntityListeners(AuditingEntityListener.class)<br>public abstract class AbstractEntity implements Serializable {<br><br>    @Basic<br>    @CreatedDate<br>    @Column(updatable = false, name = &quot;created_date&quot;)<br>    @JsonIgnore<br>    private LocalDateTime createdDate;<br><br>    @Basic<br>    @LastModifiedDate<br>    @Column(name = &quot;modified_date&quot;)<br>    @JsonIgnore<br>    private LocalDateTime modifiedDate;<br><br>    @Basic<br>    @CreatedBy<br>    @Column(updatable = false, name = &quot;created_by&quot;)<br>    @JsonIgnore<br>    private Long createdBy;<br><br>    @Basic<br>    @LastModifiedBy<br>    @Column(name = &quot;modified_by&quot;)<br>    @JsonIgnore<br>    private Long modifiedBy;<br>}</pre><p>Seeing hundreds of entities extending this AbstractEntity made me stop and think. If every single subclass carries these four fields, are we just bloating the heap? My mind immediately jumped to the <strong>Bill Pugh Singleton </strong>the gold standard for memory efficiency through static inner classes.</p><blockquote>It’s a silly thought but it came all on the neuron receptors that I carry all blame on that.</blockquote><pre>public class AuditManager {<br>    private AuditManager() {}<br><br>    private static class SingletonHelper {<br>        private static final AuditManager INSTANCE = new AuditManager();<br>    }<br><br>    public static AuditManager getInstance() {<br>        return SingletonHelper.INSTANCE;<br>    }<br>}</pre><p>I found myself questioning: <em>If a Singleton can share a single instance across the entire application, why are we “duplicating” these fields thousands of times?</em></p><p>This article traces the intellectual journey from the <strong>Bill Pugh Singleton</strong> pattern to the <strong>Java Memory Model (JMM)</strong>, explaining class loading mechanics, heap object layout, and runtime method dispatch. Through this narrative, I clarify why inheritance is a <strong>compile-time structural relationship</strong>, not a runtime instance-sharing mechanism, and why the <strong>JVM</strong> intentionally <strong>flattens object memory</strong> to ensure correctness and performance.</p><h3>1. The Catalyst: Why the Bill Pugh Singleton Makes You Ask Harder Questions</h3><p>Most of developers encounter the Bill Pugh Singleton as an elegant solution to thread-safe lazy initialization.</p><p>The explanation usually given is satisfying: the JVM guarantees that a class is loaded only when it is first referenced, and class loading is inherently thread-safe. Therefore, Holder.INSTANCE is created exactly once, without explicit synchronization.</p><p>But this explanation contains a seed that grows into a much larger question.</p><p>The thought process goes like this:</p><blockquote><em>If the JVM loads a class only once, and that class contains static state… then what happens when I use </em><em>extends instead of an inner class? If class </em><em>B is loaded once, and </em><em>A extends B, does </em><em>A somehow &quot;share&quot; the loaded </em><em>B? If I have 100 entities extending </em><em>AbstractEntity, is there one </em><em>AbstractEntity instance that they all point to?</em></blockquote><p>This is the exact moment where a design pattern question becomes a JVM architecture question.</p><h3>2. The Class Loading illusion: What “Loaded Once” Actually Means</h3><p>To understand why the <strong>Singleton question connected into inheritance</strong>, we must first connect a common thought: <strong>The desire for efficiency.</strong></p><p>In my mind, the link looked like this:</p><ul><li><strong>Inheritance</strong> is about “sharing” a <strong>template</strong>.</li><li><strong>Singletons</strong> are about “sharing” an <strong>instance</strong>.</li></ul><p>When we say “Class B is loaded once,” we are talking about the class definition, not an instance of the class. The JVM divides this into three distinct phases:</p><ol><li>Loading: Reading the .class file and creating a Class object in the Metaspace (or PermGen in older JVMs).</li><li>Linking: Verification, preparation (allocating static variable slots), and resolution.</li><li>Initialization: Executing static initializers and static variable assignments.</li></ol><h4>2.1 The Inheritance Loading Chain</h4><p>Consider:</p><pre>class B {<br>    // 1. Static initialization (Metaspace)<br>    static { System.out.println(&quot;1. Class B: Static Block (Class Loading)&quot;); }<br><br>    // 3. Instance variable (Heap)<br>    private long bField = 100;<br><br>    // 4. Constructor (Execution)<br>    B() {<br>        System.out.println(&quot;3. Class B: Constructor Running&quot;);<br>    }<br>}<br><br>class A extends B {<br>    // 2. Static initialization (Metaspace)<br>    static { System.out.println(&quot;2. Class A: Static Block (Class Loading)&quot;); }<br><br>    // 5. Instance variable (Heap)<br>    private long aField = 200;<br><br>    // 6. Constructor (Execution)<br>    A() {<br>        super(); // Implicitly calls B&#39;s constructor<br>        System.out.println(&quot;4. Class A: Constructor Running&quot;);<br>    }<br>}<br><br>public class Main {<br>    public static void main(String[] args) {<br>        System.out.println(&quot;--- Triggering new A() ---&quot;);<br>        A myObject = new A();<br>    }<br>}</pre><p>When you execute new A(), the JVM does not simply load A. Because of the is-a relationship, the JVM must ensure that B is fully initialized before A can be initialized. The order is:</p><pre>1. Load B&#39;s bytecode into Metaspace<br>2. Initialize B (run static blocks)<br>3. Load A&#39;s bytecode into Metaspace<br>4. Initialize A (run static blocks)<br>5. Allocate memory for A on the Heap<br>6. Run B&#39;s constructor<br>7. Run A&#39;s constructor</pre><p><strong>Critical insight</strong>: Step 5 allocates one contiguous block of heap memory. The JVM does not allocate a B object and then attach an A object to it. It allocates an A object that <em>contains</em> the fields of B.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q1e0OK4QHtuIT5Tl3_l0Fg.png" /><figcaption>Diagram generated by Gemini to visualize the JVM inheritance flattening.</figcaption></figure><p>This is the first major correction to our mental model. Class loading happens in Metaspace. Object creation happens in the Heap. They are completely unrelated.</p><h3>3. The 100-Entity Problem: A Real-World Scenario</h3><p>Let us go through this in the exact scenario that sparked this investigation. You have an enterprise application with roughly 100 JPA entities:</p><pre>@Getter<br>@Setter<br>@MappedSuperclass<br>@EntityListeners(AuditingEntityListener.class)<br>public abstract class AbstractEntity implements Serializable {<br><br>    @CreatedDate<br>    @Column(updatable = false, name = &quot;created_date&quot;)<br>    @JsonIgnore<br>    private LocalDateTime createdDate;<br><br>    @LastModifiedDate<br>    @Column(name = &quot;modified_date&quot;)<br>    @JsonIgnore<br>    private LocalDateTime modifiedDate;<br><br>    @CreatedBy<br>    @Column(updatable = false, name = &quot;created_by&quot;)<br>    @JsonIgnore<br>    private Long createdBy;<br><br>    @LastModifiedBy<br>    @Column(name = &quot;modified_by&quot;)<br>    @JsonIgnore<br>    private Long modifiedBy;<br>}</pre><p>And then:</p><pre>class User extends AbstractEntity { ... }<br>class Order extends AbstractEntity { ... }<br>class Product extends AbstractEntity { ... }<br>// ... 97 more</pre><p>If you come from the Singleton mindset, youmight think:</p><blockquote><em>If </em><em>AbstractEntity is loaded once, and all 100 entities extend it, do they all share the same </em><em>createdDate? If </em><em>User sets </em><em>createdBy = 1 and </em><em>Order sets </em><em>createdBy = 2, won&#39;t they overwrite each other? And if not if each has its own copy doesn&#39;t that mean </em><em>AbstractEntity is duplicated 100 times in memory? Should I instead inject a single shared instance?&quot;</em></blockquote><p>This confusion is the collision of three distinct concepts:</p><ul><li>Class loading (once per classloader)</li><li>Object instantiation (every new creates a new object)</li><li>Memory layout (how fields are physically arranged)</li></ul><h3>4. The JVM Object Model: How Memory Is Actually Laid Out</h3><p>To resolve the confusion, we must look at the Heap representation of an object. In the JVM, every object is an Ordinary Object Pointer (OOP) with the following structure:</p><pre>[ Object Header ] + [ Instance Fields ] + [ Alignment Padding ]</pre><h4>4.1 The Object Header</h4><p>On a 64-bit JVM with compressed OOPs (since Java 8):</p><ul><li>Mark Word: 8 bytes (identity hash code, GC age, lock state)</li><li>Class Pointer: 4 bytes (points to the Class object in Metaspace)</li><li>Array Length (if array): 4 bytes</li></ul><p>Total header: 12 bytes for regular objects.</p><h4>4.2 Instance Fields: The Flattening Principle</h4><p>Inheritance in Java is implemented as field flattening, not object composition.</p><p>When we write:</p><pre>class B {<br>    int x;<br>}<br><br>class A extends B {<br>    int y;<br>}</pre><p>The JVM does not create a pointer graph like this:</p><pre>[A object] ---&gt; [B object]</pre><p>Instead, it creates a single, contiguous memory block:</p><pre>[A object in Heap]<br><br>| Offset 0-11  | Object Header      | 12 bytes |<br>| Offset 12-15 | int x (from B)     | 4 bytes  |<br>| Offset 16-19 | int y (from A)     | 4 bytes  |<br>| Offset 20-23 | Padding (alignment)| 4 bytes  |<br>|----------------------------------------------|<br>| Total        |                    | 24 bytes |</pre><p>There is no embedded B object. The fields of B are <em>copied into the layout</em> of A at the bytecode level. At runtime, they are indistinguishable from A&#39;s own fields.</p><h4>4.3 Why the JVM Does This</h4><p>The JVM flattens inheritance for three hard technical reasons:</p><ol><li>Cache Locality: CPU caches work on contiguous memory. If accessing obj.x required dereferencing a pointer to a separate B object, you would run into cache misses and pointer-chasing penalties.</li><li>Deterministic Offset: The JVM compiler (and JIT) knows that x is always at a fixed offset from the object header. It can generate direct memory access instructions rather than indirect lookups.</li><li>Object Identity Correctness: If A, C, and D all extended B and shared a single B instance, then createdBy would be global mutable state. This would violate encapsulation and make concurrent modification trivially unsafe.</li></ol><h3>5. Calculating Real Memory: The AbstractEntity Example</h3><p>Let us calculate the actual memory footprint of our AbstractEntity pattern.</p><h4>5.1 Field Sizes</h4><p>On a 64-bit JVM with compressed OOPs:</p><ul><li>LocalDateTime: 4 bytes (reference) → points to a separate LocalDateTime object on the heap (~24 bytes itself)</li><li>Long (wrapper): 4 bytes (reference) → points to a separate Long object (~16 bytes)</li><li>If using long (primitive): 8 bytes inline</li><li>If using primitive long for timestamps (epoch millis): 8 bytes inline</li></ul><p>But for our JPA entity with LocalDateTime and Long:</p><pre>AbstractEntity field layout (per instance):<br>- createdDate:    4 bytes (reference)<br>- modifiedDate:   4 bytes (reference)<br>- createdBy:      4 bytes (reference)<br>- modifiedBy:     4 bytes (reference)</pre><p>Subtotal fields: 16 bytes.</p><h4>5.2 Full Object Size</h4><p>For a User entity extending AbstractEntity with no additional fields:</p><pre>[ Object Header ]     12 bytes<br>[ AbstractEntity ]    16 bytes (4 references)<br>[ User fields ]        0 bytes (in this example)<br>[ Padding ]            4 bytes (align to 8-byte boundary)<br>-------------------------------------------------<br>Total per User object: 32 bytes (shallow)</pre><p>This is only the object itself. Each LocalDateTime field points to an object (~24 bytes + data), and each Long points to an object (~16 bytes). If all four fields are populated, the deep size is significantly larger.</p><h4>“+ data” means what?</h4><p>This is the <strong>actual content stored inside the object</strong></p><pre>Long x = 10L;</pre><p>Memory includes:</p><ul><li>Object header (~16 bytes)</li><li>One long value (8 bytes)</li></ul><p>So total = <strong>24 bytes</strong></p><p>base object overhead + stored primitive value</p><h4>5.3 Realization</h4><p>Whether we use inheritance or manually duplicate the fields:</p><pre>// Option A: Inheritance<br>class User extends AbstractEntity { }<br><br>// Option B: Manual Duplication<br>class User {<br>    private LocalDateTime createdDate;<br>    private LocalDateTime modifiedDate;<br>    private Long createdBy;<br>    private Long modifiedBy;<br>}</pre><p>The memory layout is identical. Inheritance does not add overhead. It does not create a “shadow” AbstractEntity object. It simply instructs the compiler to include those fields in User&#39;s layout.</p><h3>6. The “Shared Instance” Lie</h3><p>Just a though as a developer</p><blockquote><em>“If the class is loaded once, why can’t the instances share the parent class’s fields through a single shared object? Like a Singleton inside each instance?”</em></blockquote><p>This is a confusion between composition and inheritance.</p><h4>6.1 Composition (The Reference Model)</h4><pre>class User {<br>    private AbstractEntity entity; // composition<br>}</pre><p>Memory layout:</p><pre>[User object] ---&gt; [AbstractEntity object]</pre><p>Here, User contains a reference. Multiple User objects could theoretically point to the same AbstractEntity instance (though this would be bizarre and dangerous for domain models).</p><h4>6.2 Inheritance (The Flattening Model)</h4><pre>class User extends AbstractEntity { }</pre><p>Memory layout:</p><pre>[User object]<br><br>| createdDate   |<br>| modifiedDate  |<br>| createdBy     |<br>| modifiedBy    |<br>| ...User stuff |</pre><p>There is no arrow. There is no reference. The fields are <em>inside</em>.</p><blockquote>Why this matters for the 100-entity design: If Java used the composition model for inheritance, then user.setCreatedBy(1L) would modify a shared AbstractEntity instance, and order.getCreatedBy() would suddenly return 1L. This would make domain objects useless. By flattening fields, Java ensures each object maintains independent state.</blockquote><h3>7. Class Loading vs. Object Creation: The Duality</h3><p>To solidify the mental model, we must separate two timelines:</p><pre>Phase            | Location   | What Happens                                                                 | Frequency<br>-----------------|------------|------------------------------------------------------------------------------|--------------------<br>Class Loading    | Metaspace  | Bytecode is loaded, static structures are defined, and Class object created  | Once per ClassLoader<br>Object Creation  | Heap       | Instance is allocated and constructor is executed                            | Every time &quot;new&quot; is used</pre><p>When we have:</p><pre>class A extends B {}<br>class C extends B {}<br>class D extends B {}</pre><p>And you execute:</p><pre>new A();<br>new C();<br>new D();<br>new B();</pre><p><strong>Metaspace contains:</strong></p><ul><li>One B.class definition</li><li>One A.class definition</li><li>One C.class definition</li><li>One D.class definition</li></ul><p><strong>Heap contains:</strong></p><ul><li>Four distinct objects</li><li>Each object has its own copy of B&#39;s instance fields</li><li>Zero shared B instances</li></ul><p>The class definition is shared. The object state is never shared unless explicitly designed (e.g., Singleton, static fields, or composition with shared references).</p><h3>8. Method Dispatch: Why Behaviour Is Not Memory</h3><p>Having resolved the memory layout, we face the final puzzle. If the JVM flattens <strong>fields </strong>into a single object, why do we need @Override? Why does polymorphism exist?</p><p>Consider:</p><pre>class B {<br>    void show() { System.out.println(&quot;B&quot;); }<br>}<br><br>class A extends B {<br>    @Override<br>    void show() { System.out.println(&quot;A&quot;); }<br>}</pre><p>And then:</p><pre>B obj = new A();<br>obj.show(); // prints &quot;A&quot;</pre><h4>8.1 The Separation of Structure and Behaviour</h4><ul><li>Structure (Fields): Merged into the object at compile time. Fixed offsets. Deterministic i.e. <em>When an object is created, </em><strong><em>all its fields (including inherited ones)</em></strong><em> are placed directly inside that object’s memory block.</em></li></ul><p>JVM treats it as:</p><blockquote>One single object memory block containing all fields</blockquote><ul><li>Behaviour (Methods): Not stored in the object. Methods reside in the Metaspace as part of the class definition. The JVM resolves which method to execute at runtime based on the actual class of the object.</li></ul><h4>8.2 Virtual Method Table (vtable)</h4><p>Internally, the JVM maintains a method table for each class:</p><pre>B&#39;s vtable:<br>  show -&gt; B.show()<br><br>A&#39;s vtable:<br>  show -&gt; A.show()  (overrides)</pre><p>When obj.show() is called:</p><ol><li>The JVM looks at the object header to find its true class (A).</li><li>It looks up show in A&#39;s vtable.</li><li>It jumps to A.show().</li></ol><p>This is Dynamic Method Dispatch. The memory layout of the object (its fields) has nothing to do with method resolution. The object header contains a class pointer; that pointer determines behaviour.</p><h4>8.3 Why @Override Exists</h4><p>@Override is not for the JVM. The JVM ignores it at runtime. It is a compile-time contract for the developer.</p><p>Without @Override:</p><pre>class A extends B {<br>    void shwo() { ... } // typo: accidentally a new method<br>}</pre><p>The compiler is silent. You think you overrode show(), but you didn&#39;t. At runtime:</p><pre>B obj = new A();<br>obj.show(); // calls B.show(), not your &quot;shwo&quot;</pre><p>With @Override:</p><pre>class A extends B {<br>    @Override<br>    void shwo() { ... } // Compile-time error!<br>}</pre><p>The purpose: @Override bridges the gap between the developer&#39;s intent and the compiler&#39;s verification. It has no runtime cost because method dispatch is already handled by the vtable mechanism.</p><h3>9. The Complete Model</h3><p>After this entire journey, the corrected flow/model looks like this:</p><pre>DEVELOPMENT TIME (Compile)<br>  |<br>  |  Inheritance = &quot;include these fields and methods in my type&quot;<br>  v<br>BYTECODE<br>  |<br>  |  Class definitions link via extends<br>  v<br>METASPACE (Runtime)<br>  |<br>  |  Class B loaded once<br>  |  Class A loaded once (with pointer to B&#39;s metadata)<br>  v<br>HEAP (Object Creation)<br>  |<br>  |  new A() -&gt; allocates ONE object<br>  |  Header + B_fields + A_fields + padding<br>  |<br>  |  Methods NOT inside object<br>  |  Behavior resolved via vtable at runtime</pre><p>Three Rules:</p><ol><li>Classes are definitions; they load once.</li><li>Objects are instances; they allocate independently.</li><li>Inheritance merges field layout, not object identity.</li></ol><h3>10. Conclusion: The Philosophy Behind the Design</h3><p>The JVM loads class definitions into a shared, read-only area (Metaspace) because they are immutable blueprints. It allocates instance data into isolated heap blocks because objects must maintain independent, mutable state. Inheritance is the compiler’s tool for code reuse; it is not the runtime’s tool for memory sharing.</p><p>When you write class User extends AbstractEntity, you are not saying <em>&quot;User has an AbstractEntity.&quot;</em> You are saying <em>&quot;User is an entity, and therefore contains the structural properties of one.&quot;</em> The JVM honors this by flattening those properties directly into User&#39;s memory layout, ensuring fast access, cache efficiency, and state isolation.</p><p>The Singleton pattern solves the problem of controlled instance cardinality. Inheritance solves the problem of structural type reuse. They are not competitors; they operate on entirely different planes of the Java runtime.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34100e644e78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker: From a beginner’s eye.]]></title>
            <link>https://medium.com/@smudbhari85/docker-from-a-beginners-eye-1ef256641ef7?source=rss-a52b177f5028------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ef256641ef7</guid>
            <dc:creator><![CDATA[Saugat Mudbhari]]></dc:creator>
            <pubDate>Thu, 07 Dec 2023 07:14:41 GMT</pubDate>
            <atom:updated>2023-12-07T07:14:41.159Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*o6SdceCJzQykDplP.png" /></figure><p>Before we dive in what is docker. must know the few basic elements and why this platform came into existence.</p><p>we are in the era of the cloud nearly every thing we as a techie or a computer science student is directly related to the cloud before that we must know about the cloud platforms. The term cloud refers as a network of remote servers hosted on the internet to store, manage, and process data, rather than using a local server or a personal computer. In other word we can say that it a type of personal computer which is available on the internet that existed some where that we as a user also have no idea of. With the advance of technology like 5G is gaining popularity. As there lots of advantages in the cloud platform we also can have a lots of problem in the filed of cloud.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/0*NNTMjBgfy_geFQhs.jpg" /><figcaption>cloud computing</figcaption></figure><p>As the cloud platform have gain popularity the culture of collaboration also have increased in the Dev community, with the increase in the collaboration the goals set can be achieved faster, can share the technology they are using and with this we have the another problem like to run some application we need the specific version to run like if I am sharing some of my application to other collaborators and they needed to run on their machine the program won’t be running on their devices but it runs butter smooth on my device. The source of problem lies in the version, packages, OS, catches generated by the program and operating system</p><p>So to all of this kind of problems we have the this piece of technology called Docked.</p><p>Docker is a Software as a service software (SaaS) platform as a service for a developers and system admins that simplifies the process of developing, packaging, and deploying applications. It uses containerization technology to encapsulate applications and their dependencies into portable units called containers.</p><p>These containers can run consistently across different environments, making it easier to build, ship, and run applications seamlessly from development to production.</p><p>There are few concepts that we must know before diving further. The concepts that we must know are :-</p><h4>Docker Container</h4><p>A container is a collection of docker Images. which includes the packages, OS. A container is a packages of software, all of the dependencies that runs the software independently in the isolated environment / encapsulated. A container Images becomes container at the run time in the Docker engine. This docker container are portable meaning they can run same on every every operation system like Unix, windows etc.</p><h4>Docker Image</h4><p>A Docker image is the standalone packages that include every thing needed for the application to run. Which includes code, runtime, libraries, system tools. we can say the docker image is a blue print for the docker image. when the docker images are executed in the docker engine then the images becomes the docker container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*PE9JXHLnecGyO8lXmYsdAQ.png" /><figcaption>Docker Images and</figcaption></figure><h4>Docker Volume</h4><p>Docker volumes are used for storing the instances of persisted data outside the container. when installing the docker we will give the path in that location the data is used for storing the instances of the data.</p><p>when the container is created it typically runs in an isolation environment and any change in the container lasts for very short period of time the data existed in the container is lost when the container is terminated. The container stores its data in the thin writable layer as show in the figure.</p><p>So, the docker volumes provides a solution for sharing Persistent data between the containers. Volumes are mounted to the file system path the changes will be mounted to the volumes instead of container’s writable layer.</p><p>The volumes will be stored in the host it can be remounted to anther container or can access using manual tool.</p><p>We use the docker volume for</p><p>Database storage</p><p>Application Data</p><p>Essential caches</p><p>Convent data backup</p><p>share data between container</p><h4>Docker composition</h4><h4>Docker networking</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ef256641ef7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Collaboration: GIT]]></title>
            <link>https://medium.com/@smudbhari85/introduction-to-collaboration-git-5df8bfa69a0f?source=rss-a52b177f5028------2</link>
            <guid isPermaLink="false">https://medium.com/p/5df8bfa69a0f</guid>
            <dc:creator><![CDATA[Saugat Mudbhari]]></dc:creator>
            <pubDate>Wed, 06 Dec 2023 03:44:57 GMT</pubDate>
            <atom:updated>2023-12-06T03:44:57.507Z</atom:updated>
            <content:encoded><![CDATA[<p>When we talk about collaboration we must know what is and what its purpose is.</p><p>Git branching is just a series of snapshots pointing to our changes.</p><p>when we are working on a large project and we want to tweak the project without disturbing the main project in here we need the concept of branching and the ease of collaboration it brings with it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*kO9YuzS9R34iRpNVGjXfTg.png" /><figcaption>branching in git</figcaption></figure><p>The diagram here visualizes the repository with two isolated lines of development, one for a little feature and one for a longer-running feature. As we saw in the figure above working on the branch it’s not possible to work on them parallelly but keep away from the main branch to prevent it from being messy.</p><p>The implementation behind the git branches is much more lightweight than other VCs. Instead of copying files from the directory, Git stores a branch as a reference to a commit.</p><p>when we talk about the branching we must talk about Merge and Rebase.</p><h4>Git Merge</h4><p>Mergin is a git’s way of putting a forked history back together. The git merge command lets you take the independent lines of development created by the git branch and integrate them into a single branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*uL1t7KMLautY-vD2UM9_jQ.png" /><figcaption>A visualization of a merge in a git</figcaption></figure><p>There are two types of merge in a git</p><p>Fast Forward merge</p><p>this method is just like a git merge but we must know about this if we truly want to learn about git.</p><p>we can achieve the Fast-Forward merge by</p><pre> git merge --ff &lt;source-branch&gt;</pre><p>after we merge in the fast-forward merge we can get this type of graph in the git internally</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*GP9AuERS_bYB_H7PKlnzRg.png" /></figure><p>no Fast-Forward Merge</p><p>we need no fast-forward merge when one of our teammate merges in a new feature or change to master while we a working in our branch.</p><p>often what happens is, that we will be working on our branch let’s name a branch bug. In the meantime, additional work happens on the master branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*4tqNavIZwT5_MZkc24JPNQ.png" /></figure><p>often what happens is, that we will be working in a bug branch in the meantime additional work happens on the master branch.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5df8bfa69a0f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git: A Basic Introduction to Version Control]]></title>
            <link>https://medium.com/@smudbhari85/git-a-basic-introduction-to-version-control-82f8605c38c6?source=rss-a52b177f5028------2</link>
            <guid isPermaLink="false">https://medium.com/p/82f8605c38c6</guid>
            <dc:creator><![CDATA[Saugat Mudbhari]]></dc:creator>
            <pubDate>Tue, 05 Dec 2023 04:44:52 GMT</pubDate>
            <atom:updated>2023-12-05T04:44:52.379Z</atom:updated>
            <content:encoded><![CDATA[<p>This meticulous recording of changes forms the backbone of version control, providing developers with a safety net and a reliable compass as they navigate the complexities of software development. Beyond the fundamental capability of tracking alterations, version control serves as a collaborative compass, facilitating teamwork in a dynamic environment can be called as version control.</p><h3>What is Version Control?</h3><p>Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. there are many types of version control that we have let have a look at some of the version control.</p><h4>Local version control system</h4><p>Many people’s version-control method of choice is to copy files into another directory. his approach is very common because it is so simple, but it is also incredibly error-prone. It is easy to forget which directory you’re in and accidentally write to the wrong file or copy over files you don’t mean to. To deal with this issue, programmers long ago developed local VCSs that had a simple database that kept all the changes to files under revision control.</p><h4><strong>Centralized Version Control Systems</strong></h4><p>The next major issue that people encounter is that they need to collaborate with developers on other systems. For many years this has been practiced in the community. Due to its limitations like Limited Offline Access, Slower Performance, Difficulty in Branching, Limited Flexibility, Scalability Issues, etc.</p><h4><strong>Distributed Version Control Systems</strong></h4><p>This is where Distributed Version Control Systems (DVCSs) step in. In a DVCS (such as Git, Mercurial, or Darcs), clients don’t just check out the latest snapshot of the files rather, they fully mirror the repository, including its full history.</p><p>This meticulous recording of changes forms the backbone of version control, providing developers with a safety net and a reliable compass as they navigate the complexities of software development. Beyond the fundamental capability of tracking alterations, version control serves as a collaborative compThis paradigm shift in version control architecture introduces a new dimension of efficiency and resilience. In a Distributed Version Control System (DVCS), the traditional notion of a centralized repository transforms. Platforms like Git, Mercurial, or Darcs redefine collaboration by empowering developers with a full-fledged mirror of the entire repository, history, and all. ass, facilitating teamwork in a dynamic environment.</p><h3><strong>Installation of git in the machine</strong></h3><h4>For Linux</h4><pre>sudo apt install git-all</pre><p><strong>Setting up the GIT</strong></p><blockquote><strong>View all the settings in the git</strong></blockquote><pre>git config --list --show-origin</pre><blockquote><strong>Setting up your ID in the git</strong></blockquote><pre>git config --global user.name &quot;Your name&quot;<br>git config --global user.email youremail@example.com</pre><blockquote><strong>Checking out configuration</strong></blockquote><pre>git config --list</pre><h3>Getting a Git Repository</h3><p>Want to initialize the project you do so by typing cd, cd. And after reaching your destination we can initialize by typing <strong><em>git init</em></strong>.</p><p>This will create a new subdirectory called <strong>.git</strong>… which contains all of our project file structure.</p><p>At this point, our git folder is not being tracked.</p><p>If we want to track the untracked files, we should add the following command.</p><p><strong><em>git add *.c </em></strong><em>=&gt; (.== tells add all the files contained in the folder, *.c==it tells what specific files to add)</em></p><pre>git commit -m “your message”</pre><p><em>it is needed for what message we are adding when adding to the git repo. It will be helpful when we are trying to track the error in our project</em></p><p>Before we directly jump on how to push the code into the repo. Let us know about the certain changes in the git.</p><h3><strong>Recording Changes to the Repository</strong></h3><p>In the git, our working files can be only in two stages i.e. either your file is tracked or untracked.</p><p><strong>Tracked</strong> files are those files that are in the staging area or in the snapshot files or we can say the git files can track working folders. <strong>Untracked</strong> files are those files that have not been initialized to the git working environment or we can say that the untracked files are those files that are not in the snapshot phase.</p><p>As we add the file in the staging area and then if we edit the files the git knows about the subtle changes in the folder structure. The git seems to know about the changes if we change the file since the last changes. There are four life cycles of git files Untracked, unmodified, modified, staged.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/0*4c48B9FX4IL0tDpo" /><figcaption>lifecycle of git</figcaption></figure><h4>Checking the status of the file</h4><p>The main command to see the changes in the file is the git command called</p><pre>git status</pre><p>If we run this command after we have cloned the projects or something we can see something like this in our console or a terminal</p><pre>git status<br>On branch master<br>Your branch is up-to-date with &#39;origin/master&#39;.<br>nothing to commit, working tree clean</pre><p>This means we have a clear working directory. None of our tracked files are being modified. Git also does not see any untracked files. The command above shows which branch we are on.</p><p>Let’s take an example for a readme file in this scenario.</p><p>Let’s just say we just need to add a readme file to a project and if we run a <em>git status </em>command we can see this thing in our terminal</p><pre>echo &#39;My Project&#39; &gt; README<br>git status<br>On branch master<br>Your branch is up-to-date with &#39;origin/master&#39;.<br>(use &quot;git add &lt;file&gt;...&quot; to include in what will be committed)<br>    README<br>nothing added to commit but untracked files present (use &quot;git add&quot; to track)</pre><p>We can see that our readme file is untracked in the project directory. As we have talked about the untracked files above, the untracked files are those files that git did not see a file in the previous snapshot (commit).</p><h4><strong>For tracking a file in the git</strong></h4><p>To track files we use the command called</p><pre>git add README</pre><p>Now if we run a git command we can see that file is being tracked we see that the readme file is being tracked and staged to be committed.</p><pre>git status<br>On branch master<br>Your branch is up-to-date with &#39;origin/master&#39;.<br>Changes to be committed:<br>  (use &quot;git restore --staged &lt;file&gt;...&quot; to unstage)<br>    new file:   README</pre><p>And once again if we change the fold name we can see the following in our terminal. Like if we change from readme to readme1.0 and then if we run the git status command we can see the following in the terminal.</p><pre>git status<br>On branch master<br>Your branch is up-to-date with &#39;origin/master&#39;.<br>Changes to be committed:<br>  (use &quot;git reset HEAD &lt;file&gt;...&quot; to unstage)<br><br><br>    new file:   README<br><br><br>Changes not staged for commit:<br>  (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)<br>  (use &quot;git checkout -- &lt;file&gt;...&quot; to discard changes in working directory)<br>  modified:   readme1.0</pre><p>The readme1.0.md file appears under a section named “C<em>hanges not staged for commit</em>” — which means that a tracked file has been modified in the working directory but not yet staged. To stage the file we need to run the ‘git add’ command.</p><pre>git add CONTRIBUTING.md<br>$ git status<br>On branch master<br>Your branch is up-to-date with &#39;origin/master&#39;.<br>Changes to be committed:<br>  (use &quot;git reset HEAD &lt;file&gt;...&quot; to unstage)<br><br><br>    new file:   README<br>    modified:   readme1.0</pre><p>Here <strong>both files </strong>are in <strong>staged</strong> and will go into your next commit and if we run the `git status` we can see that the readme1.0 is both staged and unstaged. From here we can find out that git stages the file exactly as it is when we run the `git add command.</p><p>So on every modification, we must use the `git add` command before staging the file.</p><h4><strong>Ignoring the files</strong></h4><p>Sometimes we do have files that we do not want git to automatically ignore or even show as being untracked. In this case, we can create a file list containing files and name them .gitignore</p><h4><strong>Viewing our staged and unstaged changes</strong></h4><p>If we want to know exactly what you changed, not just which files are changed we can use the `git diff` command. To see what changes we have made before staging we must type git diff.</p><p>To see what we have staged that will go into the next commit, we can use `git diff — -staged`. This will compare staged changes to the last commit.</p><h4><strong>Removing files</strong></h4><p>To remove files from a git we must remove the file from being tracked or we can say remove the file from the staging area. The `git rm` command removes the files from the working directory so we don’t see it as untracked files. If you may want to keep the file on your hard drive but not have Git track it anymore. This is particularly useful if you forgot to add something to your .gitignore file. To do this, use the <em>--cached</em> option:</p><pre>git rm --cached README</pre><h3><strong>Viewing the Commit History</strong></h3><p>After we have cloned the project or have a long list of commits in a git repository and we need to have a look into the commit we can use the `git log` command to view the commit history. the commits made in that repository in reverse chronological order; that is, the most recent commits show up first. we can also limit the number of log entries displayed, such as using -integers to show only the last two entries. e.g</p><pre>git log -p -2</pre><p>Or if we want to user option such as <strong>— -since </strong>and until</p><pre>git log --since=2.weeks</pre><h3><strong>Undoing Things</strong></h3><p>If we want to redo the commit, make additional changes to what we forget and what to stage, or commit again we will be using the `- -amend` option.</p><pre>git commit --amend</pre><p>A more detailed example is</p><pre>git commit -m &#39;Initial commit&#39;<br>git add forgotten_file<br>git commit --amend</pre><h4>Unstaging a Staged File</h4><p>If we have changed two or more files and want to commit them as two separate files but we have just added the `git add .` command how do we unstage the two files?</p><pre> git reset HEAD CONTRIBUTING.md</pre><h4><strong>Unmodifying a Modified File</strong></h4><pre>git checkout -- file_name</pre><h4><strong>Undoing things with git restore</strong></h4><pre>git restore --staged &lt;file&gt;</pre><h4><strong>Unmodifying a Modified File with git restore</strong></h4><pre>git restore CONTRIBUTING.md</pre><h3>Working with Remotes</h3><p>To see which remote servers we have configured, we can run the `git remote` command origin — is the default name Git gives to the server we cloned from To show the <strong>URL of our working directory</strong> we can run the following command</p><pre>git remote -v</pre><p>If we have <strong>more than one remote</strong>, the command lists them all. For example, a repository with multiple remotes.</p><pre>cd grit<br>git remote -v</pre><h4>Adding Remote Repositories</h4><pre>git remote add &lt;nameOfYourChoice&gt; &lt;url&gt;</pre><h4><strong>Fetch from a remote repository</strong></h4><pre> git fetch &lt;remotename&gt;</pre><h4><strong>Pushing to Your Remotes</strong></h4><pre>git push &lt;remote&gt; &lt;branch&gt;</pre><h4>Inspecting a Remote</h4><p>If we want to see the information about a particular remote we can use the `git remote show <strong>&lt;origin&gt;</strong>` the result of this command will show the links of the remote repository.</p><h4><strong>Renaming and Removing Remotes</strong></h4><p>To rename a remote short name we can use `<strong>git remote rename</strong>`. To change the short name from pb to Paul we can use the following command</p><pre>git remote rename pb paul<br>git remote origin paul</pre><p>Here we already have changed to origin to pl and pb to paul when we are accessing the paul why we are writing origin?</p><p>It is before accessing the pb we already changed pb to paul and the system does not know that we have changed to Paul so to let the system know we have written origin to access Paul.</p><p>If we want to remove the remote for some reason we must type the following command.</p><pre>git remote remove or git remote rm:</pre><p>In the real scenario</p><pre>git remote remove paul</pre><p>We go back to the basic</p><pre>git remote origin</pre><h3>Tagging</h3><p>In the git, we can tag specific points in a repository’s history as being important. Typically, we use functionality to mark release points like (v1,v2…).</p><h4>Listing Your Tags</h4><p>To list the tag we have the following command called <em>git tag</em> with the option of -l or — list</p><p>Note: This command lists the tags in alphabetical order, its order has no real importance in which they are displayed.</p><h4>Creating Tags</h4><p>Git supports two types of tags: <em>lightweight </em>and <em>annotated</em></p><p>A lightweight tag is just like a branch it is just a pointer to a specific commit.</p><p>Annotated tags are stored in full objects in the Git database they contain the tagger name, email, and date, they contain the tagging message and can be signed with verified with GNU Privacy Guard (GPG). If we have all of this information then only we can create an annotated tag.</p><p>Creating an annotated tag:</p><p>We just need to add -a in the tag command in the git file.</p><pre>git tag -a v1.4 -m &quot;my version 1.4</pre><p>The -m specifies the tagging message in the git, which will be stored in the tag.</p><h4>Creating a lightweight tag:</h4><p>The lightweight does not support -a -s or -m options, we just need to provide a tag name.</p><pre>git tag v1.4-lw</pre><h4><strong>Deleting Tags</strong></h4><p>To delete a tag we just need to add a command which is</p><pre>git tag -d &lt;tagname&gt;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82f8605c38c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>