<?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 Kalana Ravishan Uduwarage on Medium]]></title>
        <description><![CDATA[Stories by Kalana Ravishan Uduwarage on Medium]]></description>
        <link>https://medium.com/@ravishan98?source=rss-e1ad1a7025d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*c9Eplv_HKApZm618</url>
            <title>Stories by Kalana Ravishan Uduwarage on Medium</title>
            <link>https://medium.com/@ravishan98?source=rss-e1ad1a7025d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 03:59:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ravishan98/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[Factory Design Pattern]]></title>
            <link>https://medium.com/@ravishan98/factory-design-pattern-ece6a80757df?source=rss-e1ad1a7025d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ece6a80757df</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[factory-pattern]]></category>
            <dc:creator><![CDATA[Kalana Ravishan Uduwarage]]></dc:creator>
            <pubDate>Wed, 29 Dec 2021 22:10:37 GMT</pubDate>
            <atom:updated>2021-12-29T22:10:37.931Z</atom:updated>
            <content:encoded><![CDATA[<p>This pattern falls into the Creational pattern type and this is used when we need to create instances but without disclosing or revealing the creation logic. Simply encapsulating the object creation. This method implements an abstract class or an interface to create an object but the object creation is decided by the subclasses (like which class to instantiate). This pattern is also known as the “ Virtual Constructor”.</p><p>This pattern is completely different from the singleton patterns since this takes arguments to instantiate classes and creates multiple instances.</p><p>let&#39;s take a look at a real-world example; Think there is a system that uses multiple databases such as oracle, mssql and mongo and the system decide to connect with the database based on the client request. If the client wants to connect to the oracle DB client pass an argument as oracle then it creates a driver instance to connect with the DB, and the same happens with the other DBs.</p><p>Code:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*dFXaqAxp42Hh3fkWwZqQGg.jpeg" /><figcaption>DBDriver Interface</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*8ZZtCwu0PtuKty9MzKfJdw.jpeg" /><figcaption>OracleDB class</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*ef4ovx_e42oajnbquCBs2w.jpeg" /><figcaption>MSSQLDB Class</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*XxEN6m9Xp65itTrf9Xnhuw.jpeg" /><figcaption>MongoDB Class</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*BvuLIV_aNgxsVHEkbT0sQA.jpeg" /><figcaption>DBFactory class</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*nBPAeNuhLkfwao296F2DWQ.jpeg" /><figcaption>DriverApp class</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*MqNBf4ZCS8utCjnWT9_fpg.jpeg" /><figcaption>Output</figcaption></figure><p>In here what happens is we take object creation to the DBFactory and create instances according to the passed parameters then it decides what class should be instantiated and deploys the required instance.</p><p>Think if we need to update the driver or make changes, we can perform that simply by changing the relevant parts of the DBfactory method despite changing all the codes from the client-side. Through this design pattern, we can achieve the decouplinge of the client&#39;s object creation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ece6a80757df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Singleton Design Pattern]]></title>
            <link>https://medium.com/@ravishan98/singleton-design-pattern-a81d67c0e7fa?source=rss-e1ad1a7025d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a81d67c0e7fa</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[singleton-pattern]]></category>
            <dc:creator><![CDATA[Kalana Ravishan Uduwarage]]></dc:creator>
            <pubDate>Wed, 29 Dec 2021 13:44:38 GMT</pubDate>
            <atom:updated>2021-12-29T13:44:38.654Z</atom:updated>
            <content:encoded><![CDATA[<p>This design pattern is one instance oriented design pattern and the easiest and the simplest form other 23 design patterns. This pattern allows only one instance and we can&#39;t use this pattern unless we need to create only one instance. This design pattern falls into the Creational design patterns category.</p><p>This pattern actually allows one instance per container and as an example single instance of a class per a JVM which provides access globally. As another example, let’s think of a Database connection or a socket, when we create a single instance we don&#39;t need to recreate instances again and again so using this design pattern we can achieve that simply. But the dark side of this design pattern is if we use this without a good understanding we might get into trouble when performing unit testing since there are no instance variables or any other references to create. and another important thing is we should not take any arguments when creating an instance or else if in need we have to stick with another design pattern (Factory Design Patterns)to keep its form clean.</p><p>To keep the pattern clean programmers use some techniques like 1. Creating a constructor private in order to make sure that the singleton class doesn&#39;t get instantiated by other classes, 2. Creating static variables for instance which don&#39;t take any arguments and 3. Creating only static methods to allow point access globally to the singleton object.</p><p>there are two other approaches named “Early initialization” and “Lazy initialization”. In the Early initialization method, it creates instances at the load time and in the Lazy initialization method, it creates instances based on the requirement. The “Synchronized ” keyword is used to make a thread-safe singleton approach called “Double checking Singleton”.</p><p>Let&#39;s take a look at the code example :</p><p>there is a company that performs vehicle inspections and customers have to plug their scanner port into the car and a mechanic scans and print a report to the customers. there should only be one inspection handler to handle inspection sessions and two customers can’t get the inspection done at the same time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*F47HI_fFLZlaaQ2j2GD-mw.jpeg" /><figcaption>InspectionManager class</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*R6w0JrzSJ3n5Pb31OKJ9OA.jpeg" /><figcaption>InspectionApp class</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*gM_4kaPE3yQ5hhmbUScpZA.jpeg" /><figcaption>Output</figcaption></figure><p>Did you notice that even though we created two instances it returned us the same instance despite creating and returning a new instance. And also to keep the thread-safe and clean getInspectionManager method in InspectionManager class and the “double-checking singleton” method is created and they prevent multiple instances and multiple thread instances.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a81d67c0e7fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design Patterns Explained]]></title>
            <link>https://medium.com/@ravishan98/design-patterns-explained-13c359795bf5?source=rss-e1ad1a7025d------2</link>
            <guid isPermaLink="false">https://medium.com/p/13c359795bf5</guid>
            <category><![CDATA[software-design-patterns]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Kalana Ravishan Uduwarage]]></dc:creator>
            <pubDate>Wed, 29 Dec 2021 07:49:04 GMT</pubDate>
            <atom:updated>2021-12-29T08:00:01.837Z</atom:updated>
            <content:encoded><![CDATA[<p>Design patterns are a way to provide solutions to general problems within the given context which are reusable and common, invented by the “Gang of four”( <em>Erich Gamma</em>, <em>Richard Helm</em>, <em>Ralph Johnson</em>, and <em>John Vlissides </em>) in 1994 with the book “<em>Design Pattern-Elements of Reusable Object-Oriented Software</em>”.</p><p>There are three types of Design Patterns available to fit in with how it works and what are problems it works well. Those are,</p><ol><li>Creational Design Patterns. (Singleton, Factory, Prototype, Abstract…etc)</li><li>Structural Design Patterns. (Composite, Proxy, Fly-Weight, Adapter…etc)</li><li>Behavioral Design Patterns.(Strategy,Template,Observe,Command…etc)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*8CAwMhyQ-DCkMDWV-vUycQ.jpeg" /></figure><p><strong>Creational Design Patterns</strong> as the name sounds this design pattern involves the creation of objects and the way of creating. It allows you to create objects without revealing the logic behind them. So it means we can openly give the type of the required object and then it will provide the needed object but it avoids utilizing the “new” keyword to directly instantiate objects. These creational design patterns boost the reusability of programming and allow additional flexibility.</p><p><strong>Structural Design Pattern</strong> as the name says it specifies the structure and the composition between classes and objects. The technique for composing interfaces is based on the concept of inheritance. This pattern provides extra flexibility to the classes and objects.</p><p><strong>Behavioural Design Patterns</strong> describe the behaviour of communication, interaction and responsibilities spread between objects. It tells us how communication happens, what kind of interactions happen between objects and what are the assigned responsibilities of the objects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13c359795bf5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JVM Architecture explained…]]></title>
            <link>https://medium.com/@ravishan98/jvm-architecture-explained-77d001b4a364?source=rss-e1ad1a7025d------2</link>
            <guid isPermaLink="false">https://medium.com/p/77d001b4a364</guid>
            <category><![CDATA[jvm-memory]]></category>
            <category><![CDATA[jvm]]></category>
            <category><![CDATA[jvm-architecture]]></category>
            <dc:creator><![CDATA[Kalana Ravishan Uduwarage]]></dc:creator>
            <pubDate>Tue, 28 Dec 2021 21:42:17 GMT</pubDate>
            <atom:updated>2021-12-28T21:42:17.354Z</atom:updated>
            <content:encoded><![CDATA[<p>In the previous article, we discussed the JVM briefly and now it&#39;s time to dig deep into JVM architecture and how it really works.</p><p>The JVM consist of three main components which are,</p><ol><li>Class-Loader.</li><li>Memory Area.</li><li>Execution Engine.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*OP_EmFN-G8ds1dHuiduiIg.jpeg" /></figure><p><strong><em>Class-Loader</em></strong></p><p>Class-loader is the part where the classes are loaded into the JVM and stored in the memory area. There are two types of class loaders present in java one is “Bootstrap Class-loader” and the other is “Custom Class-Loaders”. Class- loader performs three main works,</p><ol><li>Loading.</li><li>Linking.</li><li>Initialization.</li></ol><p><strong>In the loading phase</strong>, it reads the fully qualified class name, variable information, immediate parent details, and finally, it checks whether it is a class, interfaces or enum in order to load it into the memory. There is a built-in class type called Class in JVM (not the class that we make but a type as a data type) which gets created an object whenever a class is loaded into the memory and it happens for each class loaded into the memory. Then that object gets assigned to the class which is loaded (the class that we created) and pushed into the heap area.</p><p><strong>The linking phase</strong> comes with 3 sub-steps which are known as, 1. Verification 2. Preparation and 3. Resolution.</p><p>What verification does is check whether the class comes from a valid compiler, comply with the valid format or structure and verify that whether this class is safe to execute or not with the help of “Byte Code Verifier” in java. If a class fails to fulfil the above requirement “Verifier Exception” is thrown by the JVM which is a “Run-time Exception” or If all are fulfilled then it is pushed forward to the preparation step.</p><p>In the preparation step, a default value is assigned to the variables if we use any Static or Instance level variables in the class which are not the values that we assigned in the code.</p><p>In the resolution, JVM assigns memory location for domain-specific objects by replacing their symbolic links with direct links.</p><p><strong>The initialization phase</strong> is where the originally assigned values from the code get assigned back to the variables and execution of static methods or blocks. This step is a must to happen before a class becomes an active use.</p><p>Active use: “new” keyword in the class, static methods in the class, has a main method, a value assigned for a static field, use reflection specific methods (getInstance()) or has an instantiation of the subclass.</p><p>java methods to create objects or initialize the class : “new” keyword, getInstance(), clone() or IO.ObjectInputStream.</p><p><strong><em>Memory Area</em></strong></p><p>This consist of five parts and those are,</p><ol><li>Method Area.</li><li>Heap.</li><li>Stack.</li><li>PC Registers.</li><li>Native Method Area.</li></ol><p>In <strong>Method Area</strong>, class data is loaded with details such as static variables, blocks, method and immediate parent class information..etc.</p><p><strong>Heap Area</strong> facilitates storage to all the objects when loading classes.</p><p>Both Method Area and Heap are is created per a JVM</p><p><strong>Stack </strong>stores information about methods and local variables. Stack pushes variable info into the stack when a certain method calls, and pop when they are done execution. Stack uses the last in first out method to operate. This is created per a thread.</p><p><strong>PC Registers </strong>hold information about the next execution if there are any and not the native method details are allowed. PC register is created per a thread.</p><p><strong>Native Method Area</strong> provides storage for the native method data for the program. This was also created per a thread.</p><p><strong><em>Execution Engine</em></strong></p><p>The execution engine consists of 3 components which are, 1. Interpreter, 2. JIT Compiler, 3. Garbage Collector. The main role of the Execution engine is to execute the byte code line by line.</p><p>what <strong>Interpreter does</strong> is read interpret and execute the code. But unfortunately, this process reduces the performance of the program since the execution happens line by line and when a method which already invoked invokes multiple times a new interpretation is needed to perform. So that is where the JIT Compiler comes in handy.</p><p><strong>JIT Compiler</strong> comes to the rescue of the performance reduction caused by the Interpreter and it runs parallel to the interpreter. It is used to recognize repeated code in a program while the interpreter does its job as usual. This compiler stores the machine code of the compiled byte code in the cache to use later whenever those are required. It boosts the performance of a JAVA program furthermore.</p><p>Garbage Collector collects garbage or unused objects from a program. This inspects the heap area and figures out what are the unused or unreferenced objects (Mark) and if there are such objects they are destroyed and cleaned from the heap memory (Sweep). This uses a technique called “Mark and Sweep” to perform its job.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77d001b4a364" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is this JVM ??]]></title>
            <link>https://medium.com/@ravishan98/jvm-7337bff604d0?source=rss-e1ad1a7025d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7337bff604d0</guid>
            <category><![CDATA[jvm]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Kalana Ravishan Uduwarage]]></dc:creator>
            <pubDate>Mon, 27 Dec 2021 17:30:47 GMT</pubDate>
            <atom:updated>2021-12-28T18:49:41.629Z</atom:updated>
            <content:encoded><![CDATA[<p>Java Virtual Machine, it’s a common set of words for you if you&#39;re following the field of software engineering or development etc. But do you know what it really is?</p><p>Okay first of all let&#39;s dig into the meaning of these couple of words. You probably know what is java and the grey area is the virtual machine, right?</p><p>A Virtual Machine is a mechanism that does the work virtually but is not physically accessible or exists. When every time we run a .java file it creates a JVM and it dies with the program when it ends. A java code must need a running non-daemon thread to exist, if that condition doesn&#39;t meet, the java program dies. A JVM is created per a program, if we run 4 .java programs at once there will be 4 JVMs running at that moment. JVM is a complete specification that tells “ how this should be done”. Think about a real-world scenario; driving a car, we have a car and we have all the equipment and requirements to drive the car but we need to know how should we do it, how to start it, how to get it into gear, how to stop it, how to drive under the law …etc. That&#39;s exactly what JVM performs for us. JVM interpret the byte code into machine understandable code and tells the machine how this should be done, JVM passes the instruction set to perform the task. JVM is inside the JRE and JVM is deployed according to the specific OS, as an example, if we install the JRE on an apple machine it will install the JVM suitable for the apple machine, but for the windows, it is not the same and a specific JVM designed to windows will be deployed for the windows machines. Even though the JVM is platform-independent, the JRE is tightly platform dependant. The capability of being platform-independent for java come with the JVM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*tZoWydo2eA3lIwVdxtdjEg.jpeg" /></figure><p>There are two types of virtual machines present,</p><ol><li>SVM -System Based Virtual Machine</li><li>AVM -Application based virtual machine</li></ol><p>SVM</p><p>This type of VMs creates a totally independent environment to work where multiple instances or users can work on and could have one or more hardware.</p><p>Ex:- Xen, Hyper vision</p><p>AVM</p><p>This type doesn&#39;t depend on any hardware but software. These create a platform to run other programs using its own programme or software. JVM falls into this category.</p><p>ex:- JVM, YVM, CLR, PVM.</p><p>Hope you got an idea about what the JVM is, keep your eyes peeled for another article on JVM architecture.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7337bff604d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>