<?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 Sachith Rangana on Medium]]></title>
        <description><![CDATA[Stories by Sachith Rangana on Medium]]></description>
        <link>https://medium.com/@sachithrangana6?source=rss-d6f4d539559a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*fLlMgjzVwOcvbmJH</url>
            <title>Stories by Sachith Rangana on Medium</title>
            <link>https://medium.com/@sachithrangana6?source=rss-d6f4d539559a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 08:50:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sachithrangana6/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[JVM Architecture]]></title>
            <link>https://medium.com/@sachithrangana6/jvm-architecture-4e88c500962a?source=rss-d6f4d539559a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e88c500962a</guid>
            <category><![CDATA[jvm-architecture]]></category>
            <category><![CDATA[jvm]]></category>
            <dc:creator><![CDATA[Sachith Rangana]]></dc:creator>
            <pubDate>Sat, 24 Oct 2026 12:51:57 GMT</pubDate>
            <atom:updated>2026-10-24T12:51:57.053Z</atom:updated>
            <content:encoded><![CDATA[<p>The Java Virtual Machine (JVM) is the core runtime environment responsible for executing compiled Java bytecode</p><p>Compilation &amp; Execution Flow :</p><p>Source code written in a .java file is first compiled by the Java compiler (javac) into platform-independent bytecode saved as a .class file. The JVM then loads this bytecode, translates it into native machine code, and executes it on the host platform</p><p>Write Once, Run Anywhere :</p><p>Because bytecode is platform-agnostic, the same compiled .class file can run seamlessly across any operating system—such as Windows, Linux, or macOS—provided a platform-specific JVM is installed</p><h3><strong>Overview of the JVM</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NJ40fgeQlrj-dXVB5YmYpg.jpeg" /></figure><p>Then Understand each of the Area Step by Step.</p><h3><strong>ClassLoader Subsystem</strong></h3><p>There are three phases.</p><p>Phase 1: <strong>Loading</strong></p><p>The JVM locates the binary representation of a class and loads it using three standard built-in class loaders following the <strong>Delegation Hierarchy Principle</strong></p><ol><li>Bootstrap ClassLoader<br> Loads core Java platform classes from java.base (java.lang.*, java.util.*, etc.). Written in native C/C++.</li><li>Platform ClassLoader (formerly Extension ClassLoader)<br> Loads standard Java platform extensions and modules (SQL/Database Connectivity (JDBC extensions) ,XML Parsing).</li><li>Application (System) ClassLoader<br>Loads custom application classes found on the application classpath<br>(User-defined Classes Load , Check class path)</li></ol><blockquote><em>Parent Delegation Model<br>When the JVM needs to load a class (e.g., </em><em>myApp.class), it follows the Parent Delegation Mode<br> — </em>The loading request is initially received by the Application ClassLoader, which delegates it up to the Extension ClassLoader<br> — The Extension ClassLoader further delegates the request up to the Bootstrap ClassLoader<br> — If a parent loader cannot locate the class in its designated directory, the delegation bubbles back down the hierarchy to allow child loaders to search their respective class paths</blockquote><h4>Phase 2: Linking</h4><p><strong>Verification </strong>— Ensures bytecode strictly complies with JVM specification rules and does not violate memory access boundaries or structural constraints.<br><strong>Preparation — </strong>Allocates memory for static variables and sets default initial values (e.g., 0, null, false). <em>Actual custom values are not assigned yet<br></em><strong>Resolution — </strong>Replaces symbolic memory references in the runtime constant pool with direct memory addresses.</p><h4>Phase 3: Initialization</h4><p>Executes static initializers and assigns actual values to static fields defined in the code.</p><h3>JVM Memory Areas (Runtime Data Areas)</h3><p><strong>Heap Memory(Thread-Shared Memory Areas):</strong> The shared pool where all <strong>Objects and Instance Variables</strong> (new instances) live. It is shared across all threads and managed by the Garbage Collector.</p><p><strong>Metaspace(Thread-Shared Memory Areas):</strong> Stores the structural blueprints of your application — including <strong>Class Definitions, Bytecode, Methods, and Static Variables</strong>. (In older Java versions, this was called PermGen).</p><p><strong>JVM Stack(Thread-Private Memory Areas):</strong> A thread-specific memory area where <strong>Local Variables</strong> and method call frames are stored. When a method finishes execution, its stack frame is instantly removed.</p><p><strong>PC Registers(Thread-Private Memory Areas):</strong> Tracks the instruction address for each active thread.</p><p><strong>Native Method Stack(Thread-Private Memory Areas):</strong> Handles method calls written in languages other than Java (like C/C++).</p><h3><strong>Object Memory Allocation Flow</strong></h3><p>Consider the statement: Student s = new Student(); s.id = 10;</p><p>— Stack Memory: Holds the object reference variable s.</p><p>— Heap Memory: Allocates the actual Student instance along with its instance field values (id = 10).</p><p>— Metaspace: Stores structural metadata regarding the Student class definition</p><h3><strong>Execution Engine</strong></h3><p>It consists of three main components working together:</p><ol><li><strong>Interpreter:</strong></li></ol><p>— Reads and executes the bytecode instructions line by line, translating them into machine-understandable code.</p><p><strong>— -Drawback:</strong> It can be relatively slow because it translates every instruction every time it is encountered.</p><p><strong>2.JIT (Just-In-Time) Compiler<br> — </strong>Designed to boost execution speed by solving the interpreter’s performance bottleneck.</p><p>— It identifies frequently executed code sections (called “hot spots”), compiles them directly into native machine code all at once, and caches them for lightning-fast execution on subsequent runs.</p><p><strong>3.Garbage Collector (GC):<br> — </strong>Manages memory in the background by automatically scanning the Heap memory, identifying objects that are no longer in use, and clearing them out to free up space.</p><h3><strong>Java Native Interface (JNI) &amp; Native Libraries</strong></h3><p>— Java Native Interface (JNI): Acts as a bridge enabling Java bytecode to interact with native code and shared libraries written in C or C++.</p><p>— Native Method Libraries: Header and binary libraries loaded by the JVM to execute system-level or platform-specific operations</p><h3><strong>Common JVM Memory Errors</strong></h3><p>— java.lang.OutOfMemoryError: Java heap space: Occurs when the Heap space becomes completely full due to excessive object creation or unhandled memory leaks.</p><p>— java.lang.StackOverflowError: Occurs when the Stack memory limit is exceeded, typically caused by infinite recursion or uncontrolled method calls.</p><p>— java.lang.OutOfMemoryError: Metaspace: Occurs when an application loads an excessively large number of class definitions and metadata into Metaspace</p><p>Thank you for reading. Stay with us to read more artcles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e88c500962a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to improve the quality of your Node application’s code]]></title>
            <link>https://medium.com/@sachithrangana6/how-to-improve-the-quality-of-your-node-applications-code-cc6201839f8a?source=rss-d6f4d539559a------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc6201839f8a</guid>
            <dc:creator><![CDATA[Sachith Rangana]]></dc:creator>
            <pubDate>Mon, 17 Jul 2023 20:27:39 GMT</pubDate>
            <atom:updated>2023-07-17T20:27:39.387Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we will discuss two powerful techniques that can greatly improve quality of your application’s code.</p><p>1.middleware<br>2. Global Error Handling</p><ol><li><strong>middleware</strong></li></ol><p>A request handler with access to the application’s request-response cycle is known as middleware. It’s a function that holds the request object, the response object, and the middleware function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*gp_uq9wbpL90wEq-oh5oBw.png" /><figcaption>flow of middlware</figcaption></figure><p>When adding middleware,it is better to use the top of the required route rather than adding it to every route. it is sutable to avoid routes that does not need middleware and add middleware only to routes that needs it.</p><pre>const route = express.Router();<br>const {login} = require(&quot;../controllers/auth&quot;);<br>const { addProducts,updateProduct } = require(&quot;../controllers/product&quot;);<br>const { isAuthenticated } = require(&#39;../helper/global&#39;);<br><br>route.get(&#39;/login&#39;, login)<br><br>// It is unnecessary to use middleware on each route<br>route.post(&#39;/products&#39;, isAuthenticated, addProducts);<br>route.put(&#39;/product/:id&#39;, isAuthenticated, updateProduct)<br><br><br>//It is necessary to use middleware this way<br>//This approach is better way<br>route.use(isAuthenticated);<br>route.post(&#39;/products&#39;, isAuthenticated, addProducts);<br>route.put(&#39;/product/:id&#39;, isAuthenticated, updateProduct)</pre><p><strong>2. Global Error Handling</strong></p><p>It is best to use the Node.js feature for global error handling. You can create custom class derived from the built in Error class.it is possible to customize the error object with traditional instances such as status code and status.</p><pre><br>// Custom Error class<br>module.exports = class ErrorHandler extends Error {<br>  constructor(message, statusCode) {<br>    super(message);<br>    this.statusCode = statusCode;<br>    this.status = statusCode;<br><br>    Error.captureStackTrace(this, this.constructor);<br>  }<br>};</pre><pre><br>//app.js file<br>app.use((err, req, res, next) =&gt; {<br>  err.status = err.status || &quot;fail&quot;;<br>  err.statusCode = err.statusCode || 500;<br><br>  res.status(err.statusCode).json({<br>    status: err.status,<br>    message: err.message,<br>  });<br>});</pre><pre>//product controller file<br>exports.addProducts = async (req, res, next) =&gt; {<br>  try {<br>    const product = await Product.create(req.body);<br>    if (!product) {<br>      return next(new ErrorHandler(&quot;Invalid data&quot;, 400));<br>    }<br>  <br>    res.status(200).json({ message:&quot;added Product!&quot; });<br>  } catch(error) {<br>      next(error);<br>  }<br>});</pre><p>In this article, we have discussed middleware and custom error handler class with examples. These are used to organize code and avoid repeating code.</p><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc6201839f8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Redux from the Begining  —  Study with Code Examples]]></title>
            <link>https://medium.com/@sachithrangana6/react-redux-from-the-begining-study-with-code-examples-c9b641f10e2c?source=rss-d6f4d539559a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9b641f10e2c</guid>
            <dc:creator><![CDATA[Sachith Rangana]]></dc:creator>
            <pubDate>Sun, 15 Jan 2023 08:34:43 GMT</pubDate>
            <atom:updated>2023-01-15T08:34:43.079Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Redux from the Begining — Study with Code Examples</h3><p>Redux can not be easily understand because it is little bit difficult for beginners. There are some concepts to know like action, reducer, store etc.</p><p>Specially, React developers must have a fundermental knowledge of redux because, it is essential for large projects in the industry.</p><p>You can get a basic understanding about the redux through this article.</p><h3>What is Redux ?</h3><p>Redux can be consider as a state container for javascript apps. Redux is commenly paired with react. But we can use it with Angular and vanila javascript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*6Us-DEYee6E2s6tUuIBs7w.png" /><figcaption>Redux Concept</figcaption></figure><p><strong>Importance of Redux</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*FlubWxliedWIIgEsHAPbag.png" /><figcaption>Importance of redux</figcaption></figure><h3><strong>Components of Redux</strong></h3><p>There are few components.</p><p><strong>Actions</strong> - actions are plain javascript object. It used to send data from application to redux store. There are two properties like type and optional payload.</p><p><strong>Reducers -</strong> This is a function. Reducers will access and update store accoding to actions.</p><p><strong>Store -</strong>This is the center of redux . The state is kept in plain javascript object.</p><p><strong>Middleware -</strong>Middleware can be used to manage logging and Api Calls.</p><h3><strong>Projects Example</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oFvP5hRxQCVkJdW3dloaUA.png" /><figcaption>Posts Display</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nrqcQIYZKgyOpK9NSmdSVQ.png" /><figcaption>redux store</figcaption></figure><p>Thank you for reading. Stay with us to read more artcles. You can Practice and develop your skills through my projects. <a href="https://github.com/sachithrangana96/react-redux-tutorial">click here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9b641f10e2c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>