<?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 Vaibhav Saxena on Medium]]></title>
        <description><![CDATA[Stories by Vaibhav Saxena on Medium]]></description>
        <link>https://medium.com/@vebsrocks6693?source=rss-71a84cccb2ba------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ar_bXPnxcn9LGSIeehMOHw.png</url>
            <title>Stories by Vaibhav Saxena on Medium</title>
            <link>https://medium.com/@vebsrocks6693?source=rss-71a84cccb2ba------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 12:09:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vebsrocks6693/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 Garbage Collection — Part 1]]></title>
            <link>https://medium.com/@vebsrocks6693/java-garbage-collection-part-1-00a7b78dfacb?source=rss-71a84cccb2ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/00a7b78dfacb</guid>
            <dc:creator><![CDATA[Vaibhav Saxena]]></dc:creator>
            <pubDate>Sat, 13 Jul 2024 07:43:41 GMT</pubDate>
            <atom:updated>2024-07-13T07:43:41.504Z</atom:updated>
            <content:encoded><![CDATA[<h3>Java Garbage Collection — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cpuzgdn7bEjNKpiNmtG7VA.jpeg" /></figure><h3>Understanding Java Garbage Collection</h3><p>Garbage collection is a feature provided by the Java runtime out of the box. This feature enhances Java’s memory management capabilities, making it more efficient compared to languages like C/C++, where memory allocation and deallocation are left to the programmer.</p><h3>What is Java Garbage Collection?</h3><p><strong>Java Garbage Collection (GC)</strong> is an automated memory management process that reclaims memory occupied by objects no longer in use. This process relieves developers from manually managing memory, reducing the likelihood of memory leaks and other memory-related issues.</p><h3>Memory View of Java Heap</h3><p>Java’s heap is divided into several generations: Young Generation and Old Generation. The Young Generation includes the Eden space and Survivor Spaces (S0 and S1). The space previously known as PermGen has been replaced with Metaspace.</p><h4>Memory View Breakdown</h4><p>Understanding the different sections of Java heap memory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*ZSY_4uvu2W9eSsFyiHlAsg.png" /><figcaption>Java Memory View</figcaption></figure><h4>Young Generation</h4><p><strong>Eden</strong>: When objects are created using the new operator, memory is allocated in the Eden space. Research shows that around 98% of newly created objects are short-lived. Garbage collection in the Eden space, called <strong>Minor GC</strong>, occurs frequently.</p><p><strong>Survivor Spaces (S0 and S1)</strong>: These spaces are part of the Young Generation. Objects that survive one or more Minor GC cycles are moved here. S0 and S1 alternate roles during each GC cycle.</p><h4>Old Generation</h4><p><strong>Old Generation (Tenured Space)</strong>: This region manages objects that have survived multiple Minor GC cycles. The memory occupied by objects here is reclaimed during <strong>Major GC</strong> cycles. Additionally, after a Major GC, compaction optimizes memory allocation for long-lived objects.</p><h3>Types of Java Garbage Collection</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*OPSdBADhm0DjTl4n3oBzDA.png" /></figure><p><strong>Minor GC</strong>: This process reclaims memory from the Young Generation, occurring frequently with shorter pause times. The GC identifies live objects and promotes them to the Survivor Spaces while reclaiming memory from unused objects.</p><p><strong>Major GC (Full GC)</strong>: Major GC reclaims memory from both the heap and native memory, including the Young Generation, Old Generation, and Metaspace. Objects that survive multiple Minor GC cycles are promoted to the Old Generation. When these objects go out of scope, they are marked for collection. Metaspace contains metadata such as class information, and when a class loader is unreferenced, it is marked for collection.</p><h3>Conclusion</h3><p>In this article, we explored the different sections of Java heap memory and the processes involved in Java garbage collection. In the next article, we will discuss how the JVM identifies live objects and the steps following the sweeping phase of garbage collection. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=00a7b78dfacb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Execution Flow]]></title>
            <link>https://medium.com/@vebsrocks6693/java-execution-flow-17f9ef6f93f6?source=rss-71a84cccb2ba------2</link>
            <guid isPermaLink="false">https://medium.com/p/17f9ef6f93f6</guid>
            <category><![CDATA[jvm-architecture]]></category>
            <category><![CDATA[java-byte-code]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Vaibhav Saxena]]></dc:creator>
            <pubDate>Fri, 28 Jun 2024 14:54:35 GMT</pubDate>
            <atom:updated>2024-06-28T14:54:35.151Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever wondered how a program written in Java finally executes? Let&#39;s delve into a series that explains how a program written in a simple editor executes.</p><p>If you have a Java background, you must be aware of the fact that Java features Write Once, Run Anywhere (WORA). Let&#39;s find out how Java provides platform independence.</p><p>Unlike C/C++, where the compiler converts source code directly to machine code, Java uses the byte code format, which is then executed by the JVM, which is platform-dependent and generates the instruction set compatible with the host machine architecture. This is how Java stands out from other languages in terms of platform independence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*PEMdTUw5gJ_6zLuFeAryfQ.png" /><figcaption>The figure demonstrates how Java achieves platform independence</figcaption></figure><p>Now that our.<strong>class</strong> file has been generated, we should go ahead in terms of understanding the internals of JVM so as to know the next sequence of steps in our program execution flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*MkLLb38nk389xxdcDKtL5g.png" /><figcaption>Detailed internals of JVM</figcaption></figure><p><strong>ClassLoader</strong> is responsible for the following phases during execution flow:</p><ol><li>Loading .class files</li><li>Linking</li><li>Initialisation</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*HZzi_byEGJVcc6Xjc8w1lA.png" /></figure><p><strong>Loading:</strong> The JVM class loading subsystem consists of 3 types of class loaders.Each class loader has a specific search destination to load class files. The following diagram shows you the hierarchy of class loaders along with their search paths, respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*8O2MbNGm998vzUJrNiD8Gg.png" /><figcaption>Hierarchy of Class Loaders and their search paths</figcaption></figure><p>When the JVM Class subsystem tries to load the Hello.class file, it is first delegated to Application Class Loader, which in turn invokes its parent, Extension Class Loader, which again invokes its parent, which is Bootstrap Class Loader. Bootstrap class loader tries to find Hello.class in its search path, i.e., /jre/lib/rt.jar; if not found, the request is delegated back to Extension Class Loader while it tries to load a file from jre/lib/ext; if not found, the request is delegated to Application Class Loader, which loads it from the classpath variable in Java.In case no loader is able to find the .class file, a <strong>ClassNotFoundException</strong> is thrown</p><p><strong>linking </strong>phase consists of 3 sub-steps, which are as follows:</p><ol><li>Verification</li><li>Preparation</li><li>Resolution</li></ol><p><strong>Verification</strong>: The verification process involves verifying that the.<strong>class</strong> file (byte code) is compatible with the JVM specifications.For example, the bytecode generated for Java 8 wont be compatible with JVM designed for Java11.</p><p><strong>Preparation</strong> : This phase involves memory allocation to class variables (<strong>static</strong>). It also initializes the class variables with appropriate values.The memory to these class fields is allocated within method area, especially.</p><p><strong>Resolution</strong>: This phase involves the transformation of symbolic references in the constant pool into direct references. This includes references to classes, interfaces, fields, and methods. Symbolic references are typically names or strings, while direct references are pointers or indices into the JVM’s runtime data structures.</p><p><strong>Initialization: </strong>This phase involves execution of static initializers in the class and it also initializes the explicitly assigned values to the class variables.It happens after linking, triggered by first use of the class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*jZ_hiKVYMeRBiPPr16zhog.png" /><figcaption>Initialization phase, where static blocks and members are initialized</figcaption></figure><p>After the steps mentioned above, the JVM’s execution engine comes into play. In one of the previous diagrams, it was shown that Java’s execution engine consists of following 3 parts:</p><ol><li>Interpreter</li><li>JIT Compiler</li><li>Garbage Collector</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*pDq62kLnKMi98kV5MvCEqA.png" /></figure><p>We will cover Garbage collection some other day but for now, let’s focus on <strong>Interpreter</strong> and <strong>JIT Compiler.</strong></p><p>Interepreter is responsible for converting bytecode into machine instructions set line by line. Because of this, Java is both a compiled and interpreted language.This interpretation happens at runtime, allowing for dynamic execution of the code.</p><p>The JIT compilation process converts frequently executed bytecode sequences into optimized native code, which reduces the overhead of interpretation. Hence, it offers optimisation in terms of time taken to generate machine-level code generated on interpretation of bytecode.</p><p>Once the instruction set is generated, it is ready for the CPU to execute!!</p><p>Thank you for journeying through the intricate flow of Java execution with us. If you found this exploration insightful and engaging, please give this article a clap to show your appreciation and support! 🌟</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17f9ef6f93f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>