<?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 Oshan Vikasith on Medium]]></title>
        <description><![CDATA[Stories by Oshan Vikasith on Medium]]></description>
        <link>https://medium.com/@oshanvikasith1998?source=rss-f641e7e89be------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Ngb1KcFGyDB2bmMpvnhXjA.jpeg</url>
            <title>Stories by Oshan Vikasith on Medium</title>
            <link>https://medium.com/@oshanvikasith1998?source=rss-f641e7e89be------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 21:44:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@oshanvikasith1998/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[Linux Commands That Look Simple but Are Essential for Everyday DevOps Tasks]]></title>
            <link>https://oshanvikasith1998.medium.com/linux-commands-that-look-simple-but-are-essential-for-everyday-devops-tasks-239257ea9fb7?source=rss-f641e7e89be------2</link>
            <guid isPermaLink="false">https://medium.com/p/239257ea9fb7</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[beginner-programming-tips]]></category>
            <category><![CDATA[linux-commands]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Oshan Vikasith]]></dc:creator>
            <pubDate>Sun, 19 Jul 2026 19:35:30 GMT</pubDate>
            <atom:updated>2026-07-19T19:35:30.730Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DK8ytwa5aBbJpduz" /><figcaption>Photo by <a href="https://unsplash.com/@6heinz3r?utm_source=medium&amp;utm_medium=referral">Gabriel Heinzer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Usually <strong>when you start working with Linux</strong> and begin learning DevOps, you need to become <strong>familiar with Linux</strong> commands. To <strong>fully understand</strong> what you are doing, it is very <strong>important to have a strong foundation</strong>. This <strong>article will help you gain that stronger understanding</strong> of the <strong>fundamentals</strong> that you need to <strong>master the technical aspects of DevOps.</strong></p><p>In this article, we are going to take a deep dive into some<strong> commonly used Linux commands</strong> that can have<strong> significant impact</strong> on strengthening your <strong>fundamentals knowledge.</strong> I will <strong>break down the content </strong>into following <strong>topics</strong> and will also <strong>explain practical scenarios</strong> that you can try yourself to get hands on experience.</p><h4>1. Introduction and Usage</h4><h4>2. The “<strong>pwd” </strong>Command and Its Behavior</h4><h4>3. The “ls” Command and Its Behavior</h4><h4>4. The “cd” Command and Its Behavior</h4><h4>5. The “mkdir” Command and Its Behavior</h4><h4>6. The “cp” Command and Its Behavior</h4><h4>7. The “chmod” Command and Its Behavior</h4><h3>Introduction and Usage</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nk2CoPPC2-mH2nOC" /><figcaption>Photo by <a href="https://unsplash.com/@afgprogrammer?utm_source=medium&amp;utm_medium=referral">Mohammad Rahmani</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When you <strong>initially</strong> take dive into <strong>DevOps</strong> as a <strong>beginner </strong>or start using <strong>Linux components</strong> these commands would <strong>appear everywhere.</strong></p><p>These commands <strong>would appear</strong> in <strong>docker tutorials</strong>, <strong>CI/CD</strong> pipelines, <strong>cloud</strong> <strong>servers</strong>, <strong>deployment scripts</strong>, <strong>Kubernetes </strong>containers and <strong>troubleshooting guides </strong>as a software engineer these are <strong>like must know facts</strong>.</p><p>As a DevOps Engineer or as a Software Engineer you may need to</p><ol><li>Navigate through server directories</li><li>Inspect application files</li><li>Create deployment folders</li><li>Copy configuration files</li><li>Run shell scripts</li><li>Change file permissions</li><li>Investigate file permissions</li><li>Investigate application logs</li><li>Troubleshoot failed deployments</li></ol><p>Basic Linux commands help us perform all these tasks.</p><h3>The “pwd” Command and Its Behavior</h3><pre>pwd - Find your current location</pre><p>The <strong>pwd </strong>command means basically <strong>print the working directory</strong>.</p><pre>pwd --&gt; execute command<br>/mnt/c/Users/User1/linux-practise  --&gt; example output</pre><p>This command is mostly helpful to identify whether you are in the correct application directory.</p><h3>The “ls” Command and Its Behavior</h3><pre>ls - list</pre><p>The <strong>ls</strong> command <strong>displays the files and directories inside your current location</strong>.</p><p>Say for an example your directory contains below files, then the ls command would print out all the files in the terminal.<br> 1. index.js<br> 2. readme.txt<br> 3. services.js</p><h4><strong>Useful ls options</strong></h4><p><strong>ls-l : Long format</strong></p><pre>ls-l</pre><p>This displays</p><ol><li>File permissions</li><li>File owner</li><li>Group</li><li>File size</li><li>Last modified date</li><li>File or directory name</li></ol><p>When you run the command ls-l you will get an output like below. Through the below diagrams you can learn exactly what this result expresses.</p><pre>-rwxrwxrwx 1 user1 user1 0 Jul 18 21:09 sample.txt </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*81e5MazsM1f8iVCldWjt_w.png" /><figcaption>ls-l command explanation</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S73ydc1SrWEHJGHShygKdw.png" /><figcaption>File permissions</figcaption></figure><p>Hope you now has a better understanding of what interprets from the longer format of ls command.</p><h4>ls -a : Display hidden files</h4><p>This command usually brings out the files which are hidden.</p><p><strong>Display hidden files with Details : ls — la</strong></p><p>The ls command variations discussed above are widely used in day-to-day DevOps work and Linux environments. I hope you now have a better understanding of how they work.</p><h3>The “cd” Command and Its Behavior</h3><p>The cd command means <strong>change directory</strong>.</p><p>This command allow us to move from directory to another.</p><p>You can use to enter a directory : <strong>cd frontend</strong><br>To move back one level : <strong>cd ..</strong><br>To returns home directory: <strong>cd ~</strong><br>To move to root directory: <strong>cd /</strong><br>To return to previous directory : <strong>cd -</strong></p><p>You can also you relative path and absolute path with the cd command as well.</p><p><strong>Relative path starts from your current location.</strong><br>cd project/src/components</p><p><strong>Absolute path start from your Linux root directory</strong><br>cd /home/username/project/src/components</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SiGCm5sWPS3HLMrmRgAfJA.png" /><figcaption>Common Linux Path Symbols</figcaption></figure><h3>The “mkdir” Command and Its Behavior</h3><p>The mkdir command means <strong>make directory</strong>.</p><p><strong>It creates a new folder</strong></p><p><strong>mkdir deployment</strong></p><p>you can create several directories at once: <strong>mkdir dev test production</strong></p><h4>Creating Nested directories</h4><p>use<strong> -p</strong> option to create <strong>parent and child directories</strong> together.</p><p><strong>mkdir -p application/config/nginx</strong></p><p>This command create the complete directory structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NY_0i9eHzxnMxrSMHJ3Pcg.png" /><figcaption>Folder structure created by the mkdir -p command</figcaption></figure><p>Without -p, the command may fail if the parent directories do not already exist</p><pre>mkdir: cannot create directory ‘application/config/nginx’: No such file or directory</pre><h3>The “cp” Command and Its Behavior</h3><p>The cp command means <strong>copy</strong>.</p><p>Its basic structure is<br>cp <strong>SOURCE DESTINATION</strong></p><p><strong>Copy a File</strong></p><p>cp config.json config-backup.json<br>This creates a copy of <strong>config.json</strong> named <strong>config-backup.json</strong></p><p><strong>Copy a file into another directory</strong></p><p>cp config.json backup/</p><p><strong>Copy and rename a file</strong></p><p>cp config.json backup/old-config.json</p><p><strong>Copy a directory</strong></p><p>To copy a directory and everything inside it, use the <strong>-r </strong>option:</p><p>cp -r frontend frontend-backup</p><p>The <strong>-r</strong> means <strong>recursive</strong>.</p><p>Without <strong>-r</strong>, Linux will not normally copy a directory.</p><h3>The “chmod” Command and Its Behavior</h3><p>The <strong>chmod </strong>command stands for<strong> change mode</strong>. It is used to <strong>change the</strong> <strong>permissions of files and directories in Linux</strong>.</p><p>Permissions determine who can <strong>read</strong>, <strong>modify </strong>or <strong>execute a file</strong>.</p><p>Basic Syntax is:<br>chmod<strong> PERMISSONS</strong> <strong>FILE_NAME</strong></p><p>Example : chmod 755 deploy.sh<br>This changes the permissions of the deploy.sh file</p><h4><strong>The three main permissions are</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F0YIivx-MAhvFcFByzCkRg.png" /><figcaption>Permission types</figcaption></figure><h4>Linux permissions are normally assigned to three categories</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eTEzzqLRcmVfkLXH0XaiVw.png" /><figcaption>Permission groups</figcaption></figure><p><strong>The permission order is always</strong></p><p>Read → Write → Execute</p><p><strong>The category order is always</strong></p><p>User/Owner → Group → Others</p><p>For example:</p><pre>rwx</pre><p>means that read, write, and execute permissions are granted.</p><pre>r-x</pre><p>means:</p><pre>r = Read permission is granted<br>- = Write permission is not granted<br>x = Execute permission is granted</pre><p>The dash does not represent another permission. It shows that the permission in that position is missing.</p><pre>Permission set Meaning<br><br>rwx   Read, write, and execute<br>rw-   Read and write<br>r-x   Read and execute<br>r--   Read only<br>-w-   Write only<br>--x   Execute only<br>---   No permissions</pre><p>In an ls -l result such as: -rwxr-xr-x</p><p><strong>the permissions are divided like this</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R2xhaM7iuzrGvCbYKwBLQA.png" /><figcaption>Permission flow</figcaption></figure><h4>Numeric Permission Method</h4><p>Linux permissions can be represented using numbers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5WVt-fmTJwI0YrfwB3nu5Q.png" /><figcaption>Numeric permission</figcaption></figure><pre>Number Permission result<br><br>7 : Read, write, and execute<br>6 : Read and write<br>5 : Read and execute<br>4 : Read only<br>3 : Write and execute<br>2 : Write only<br>1 : Execute only<br>0 : No permissions</pre><p><strong>Understanding </strong><strong>chmod 755</strong></p><p>Consider this command:</p><pre>chmod 755 deploy.sh</pre><p>The three digits follow this order:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hI5DHMnThKQDYFmZf9c3bQ.png" /><figcaption>755 command explanation</figcaption></figure><p>The meaning is:</p><pre>User/owner: 7 = read + write + execute<br>Group:      5 = read + execute<br>Others:     5 = read + execute</pre><p>In permission symbols, this becomes:</p><pre>rwxr-xr-x</pre><p>After running the command, ls -l may display:</p><pre>-rwxr-xr-x 1 user1 user1 120 Jul 18 21:09 deploy.sh</pre><p>The owner can read, modify, and execute the script. The group and other users can read and execute it, but they cannot modify it.</p><h4>Symbolic Permission Method</h4><p>Linux also allows permissions to be changed using letters.</p><p>The general format is:</p><pre>who + action + permission</pre><p>For example:</p><pre>u + x</pre><p>means:</p><pre>u = User/owner<br>+ = Add permission<br>x = Execute permission</pre><p>Therefore:</p><pre>chmod u+x deploy.sh</pre><p>means:</p><blockquote><em>Add execute permission for the file owner.</em></blockquote><h3>Permission Operators</h3><p>Symbolic mode uses three main operators:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Tj2OhR506B0Qe5khAmweQ.png" /><figcaption>Permission Operators</figcaption></figure><p><strong>Add a permission</strong></p><pre>chmod u+x deploy.sh</pre><p>Adds <strong>execute </strong>permission for the <strong>owner</strong>.</p><p>Suppose the owner previously had: rw-<br>After adding execute permission, it becomes: rwx</p><p><strong>Remove a permission</strong></p><pre>chmod g-w deploy.sh</pre><p><strong>Removes </strong>write <strong>permission </strong>from the group.</p><p><strong>Set exact permissions</strong></p><pre>chmod u=rx deploy.sh</pre><p>Sets the owner permissions to read and execute only.</p><p>If the <strong>owner </strong>previously had <strong>write </strong>permission, it will be <strong>removed </strong>because = replaces the existing <strong>permission set</strong>.</p><p><strong>Below </strong>are few <strong>examples </strong>I came up with so you could<strong> have a better</strong> understanding.</p><p><strong>Add read permission for the group:</strong></p><pre>chmod g+r file.txt</pre><p><strong>Remove write permission from others:</strong></p><pre>chmod o-w file.txt</pre><p><strong>Add execute permission for everyone:</strong></p><pre>chmod a+x deploy.sh</pre><p>Here, a means all categories:<br>a = user + group + others</p><p><strong>Set different permissions for all three categories:</strong></p><pre>chmod u=rwx,g=rx,o=rx deploy.sh</pre><pre>u=rwx User/owner receives read, write, and execute <br>g=rx  Group receives read and execute <br>o=rx  Others receive read and execute</pre><p><strong>This command is equivalent to:</strong></p><pre>chmod 755 deploy.sh</pre><p><strong>However, the following command is not valid:</strong></p><pre>chmod rwxr-xr-x deploy.sh</pre><p>When using <strong>symbolic mode</strong>, the <strong>categories </strong>such as <strong>u</strong>, <strong>g, </strong>and <strong>o </strong>must be included.</p><p>The correct symbolic form is:</p><pre>chmod u=rwx,g=rx,o=rx deploy.sh</pre><h4>Numeric Mode vs Symbolic Mode</h4><p>Both change the permissions but they are used in different scenarios.</p><p><strong>Numeric mode</strong></p><pre>chmod 755 deploy.sh</pre><p>Numeric mode sets the complete permission structure.<br>It is useful when you already know the exact permissions required.</p><p><strong>Symbolic mode</strong></p><pre>chmod u+x deploy.sh</pre><p>Symbolic mode changes only a specific permission.<br>It is useful when you want to add or remove one permission without changing the others.</p><p>For example:</p><pre>chmod u+x deploy.sh</pre><p>only adds execute permission for the owner.</p><p>However:</p><pre>chmod 755 deploy.sh</pre><p>replaces the complete owner, group, and others permission structure.</p><p>I hope you now have a better understanding of these Linux commands and have strengthened your fundamental knowledge. The best way to become confident with Linux is to practise these commands and try them yourself in different scenarios. You can also return to this article whenever you need to refresh your knowledge and reinforce what you have learned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=239257ea9fb7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Factory Method Design Pattern Explained.]]></title>
            <link>https://oshanvikasith1998.medium.com/factory-method-design-pattern-explained-67d183ea4b28?source=rss-f641e7e89be------2</link>
            <guid isPermaLink="false">https://medium.com/p/67d183ea4b28</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[codingbootcamp]]></category>
            <dc:creator><![CDATA[Oshan Vikasith]]></dc:creator>
            <pubDate>Mon, 14 Mar 2022 14:13:23 GMT</pubDate>
            <atom:updated>2022-03-14T14:22:26.159Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3b1lYxYZtUn-yFkg" /><figcaption>Photo by <a href="https://unsplash.com/@carlosaranda?utm_source=medium&amp;utm_medium=referral">carlos aranda</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>We’re back with another design pattern after learning about the singleton coding pattern. The factory design pattern is a frequently used coding design pattern among software engineers. We’ll talk about the fundamentals of it as well as how to put it into practice. The procedure will be thoroughly covered in the article.</blockquote><h3>What is Factory method design pattern?</h3><p>Define an interface (a java interface or an abstract class) and<strong> allow the subclasses to determine which object to instantiate</strong>, according to the factory design pattern.</p><blockquote><strong><em>The factory method pattern proceeds the object creation by letting subclasses to decide what objects to create.</em></strong></blockquote><p>This design pattern comes under the creational design pattern.</p><p>Generally, factories are involved in the creation of products, and this is one of them which will be dedicated to creation of objects . It’s one of the most effective methods for hiding object creation logic from the client.</p><h3><strong>Implementation of Factory method design pattern</strong></h3><p>The factory method pattern encapsulates object creation by allowing subclasses to choose the objects they want to create.</p><ol><li><strong>Inside a abstract class or interface define the factory method</strong></li><li><strong>Create subclasses that extend the abstract method or implementing the interface. (The subclasses will decide the creation of objects)</strong></li></ol><h4><strong>Implementation Code</strong></h4><p>Here is a practical demonstration of how the Factory method design pattern is used.</p><p>Creating the interface which holds the method that needs to be implemented This method can also be an abstract method. In here I used an interface to determine the solution. In this design pattern we use OOP concepts such as abstraction.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba884de1a96715b7c2d8753748f73f22/href">https://medium.com/media/ba884de1a96715b7c2d8753748f73f22/href</a></iframe><p>In below you will find the sub class implementations. The sub classes which I created was Normal, Silver, Gold and Platinum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*ATuBth8VpUCojG05Xrqg4g.png" /><figcaption>Figure 1: Interface implementing of classes.</figcaption></figure><p>All these sub classes are implemented by the Travel interface.</p><p><strong>Basic package class implementation</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/905cadcd5a7fb056e70aa5be2a2e6d9d/href">https://medium.com/media/905cadcd5a7fb056e70aa5be2a2e6d9d/href</a></iframe><p><strong>Silver package class implementation</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76875ba30aad4d70110377192d8900a2/href">https://medium.com/media/76875ba30aad4d70110377192d8900a2/href</a></iframe><p><strong>Gold package class implementation</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06e59ed341c3f121a266949b9fb9d558/href">https://medium.com/media/06e59ed341c3f121a266949b9fb9d558/href</a></iframe><p><strong>Platinum package class implementation</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c8b36b487d421daa4bb0d16803f5fc0/href">https://medium.com/media/1c8b36b487d421daa4bb0d16803f5fc0/href</a></iframe><p>As you can see the classes are implemented by the travel interface, which also can be obtained by extending a travel abstract class.</p><p>According to the given parameter in the main method, these objects will be created. In order to create these objects the following classes are used. This class will verify the input and it will deliver the particular object.</p><p><strong>I have created an enum to store the types.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37f84e8c508e939d63041874ffad54c9/href">https://medium.com/media/37f84e8c508e939d63041874ffad54c9/href</a></iframe><p><strong>Using the following class the input will be identified and subsequently relevant objects will be created.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/096cda81437ebf1c2a49673b2f5dc01e/href">https://medium.com/media/096cda81437ebf1c2a49673b2f5dc01e/href</a></iframe><p>Here the <strong>createPackage()</strong> method is static so we can call the method without instantiating an object. This method will be called inside the main method.</p><p>Now the remaining implementation is on the main class inside the main method. Now the hard part is done, here what we have to do is call the static method which is defined in the <strong>TravelFactory</strong> class by including the correct parameter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2fafee04aa8f240576fcf8439f0397ec/href">https://medium.com/media/2fafee04aa8f240576fcf8439f0397ec/href</a></iframe><p><strong>output</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*P5U9fXOg9Z4LWNy4tUGXIw.png" /><figcaption>Figure 2 : Output</figcaption></figure><p>This is a sample implementation of the Factory method design pattern. Hope you understood the implementation process. In the Main class you can identify that according to the particular subclass, the object is created. We have to specify the certain sub class as a parameter.</p><p>Factory pattern is one of the most used design patterns in Java. This pattern provides one of the best ways to create an object.</p><h4><strong>Now we are going to discuss some of the differences between singleton design pattern and factory method design pattern.</strong></h4><ol><li>We don’t use parameters to create instances in a singleton design pattern. When it comes to the Factory method pattern, however, the parameters are always used to determine which instance is required.</li><li>Interfaces and abstract methods are used when implementing.</li><li>Factory method design method is used widely than the singleton pattern.</li><li>Unlike the Singleton design pattern, the Factory method design pattern does not show the instantiated logic, and you will always see only what you get.</li></ol><h4>Advantages of using factory method design pattern</h4><ul><li>Factory Method Pattern allows the sub-classes to choose the type of objects to create.</li><li>It promotes the <strong>loose-coupling.</strong></li><li>Good testability</li></ul><p><strong>Hope you had a better understanding regarding the Factory method design pattern, Hope to see you again in the future with another interesting article.</strong></p><p><strong>Here I have included the sources which I have referred.</strong></p><p><a href="https://www.youtube.com/watch?v=8W-BeJH1aO0&amp;list=PLD-mYtebG3X86i3uyAXwZKfVtUy2gMDdo&amp;index=5">(4271) Use of factory method design pattern | Design patterns you MUST know — YouTube</a></p><p><a href="https://www.tutorialspoint.com/design_pattern/factory_pattern.htm">Design Pattern — Factory Pattern (tutorialspoint.com)</a></p><p><a href="https://www.geeksforgeeks.org/factory-method-design-pattern-in-java/">Factory method design pattern in Java — GeeksforGeeks</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67d183ea4b28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why do Software Engineers need to consider more about time zones?]]></title>
            <link>https://oshanvikasith1998.medium.com/why-do-software-engineers-need-to-consider-more-about-time-zones-f897111d9d0d?source=rss-f641e7e89be------2</link>
            <guid isPermaLink="false">https://medium.com/p/f897111d9d0d</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Oshan Vikasith]]></dc:creator>
            <pubDate>Sat, 12 Mar 2022 08:28:47 GMT</pubDate>
            <atom:updated>2022-03-12T10:03:02.868Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Oa0NnYHqgnmzmcln" /><figcaption>Photo by <a href="https://unsplash.com/@sigmund?utm_source=medium&amp;utm_medium=referral">Sigmund</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>In this article we are going to discuss how time zones affect software engineers. How to manage application development when time zones come into play. Hope you will be able to get an understanding of details with regards to time zones.</blockquote><h3><strong>Time Zones</strong></h3><p>When the sun rises for one part of the planet, it sets in another part of the planet. This is due to the rotation of the Earth. Every country is placed in a specific time zone which was created by humans. Time zones were created to ensure that all countries had the same amount of time in relation to a day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*g-44LPS2luAF4h34" /><figcaption>Figure 1: Display of way how sun rays falls on to earth (<a href="https://c.tadst.com/gfx/1200x630/september-equinox-dark.png?1">https://c.tadst.com/gfx/1200x630/september-equinox-dark.png?1</a>)</figcaption></figure><ul><li>Time differs from country to country and also location to location due to the implementation of time zones. On some occasions dates are also going to change, as software engineers we need to concern these core factors when developing a software solution.</li><li>The world is divided into time zones by longitude. Each longitude line is divided into fifteen degrees. Depending on which direction you travel, time travels forward or backwards one hour for every fifteen degrees of longitude.</li><li>All time zones are derived from the Greenwich Observatory in England as a starting point.</li><li>If we develop an application for a country which is in a different time zone and if we develop the application according to the local time zone then it would create chaos. So it is essential that we understand time zones as software engineers.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*O-wN8StmVo6XIiON" /><figcaption>Figure 2: Time zones of the world (<a href="https://en.wikipedia.org/wiki/Time_zone">Time zone — Wikipedia</a>)</figcaption></figure><h4><strong>UTC — Universal Time Coordinated</strong></h4><blockquote>The major time standard by which the world governs clocks and time is Coordinated Universal Time, or UTC. This is a British time zone standard that is used to set all time zones around the world. Greenwich Mean Time (GMT) does not have a UTC offset value. The time in Sri Lanka can be obtained by adding 5 hours and 30 minutes to the UTC (UTC + 05:30).</blockquote><h4><strong>Note</strong></h4><ul><li>From UTC+12:00 to UTC+14:00, all time zones are defined as offsets from Coordinated Universal Time (UTC). In most cases, the offsets are a whole number of hours.</li><li>During the spring and summer, several places of higher latitude adopt daylight saving time for portions of the year, often by adding one hour to local time.</li><li>In the same country, different time zones can be present.</li><li>In two distinct countries, the time zone can be similar.</li></ul><h4><strong>What is daylight Saving?</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*jnRRpqOw6qPekUbnbl8tdA.jpeg" /></figure><p><strong>During the warmer months, daylight saving is the practice of advancing clocks (usually by one hour) so that darkness falls at a later clock time. Clocks are often set forward by one hour in the spring (“spring forward”) and to revert to standard time, turn backward by one hour in the autumn (“fall back”).</strong></p><p>As a result, in late winter or early spring, there is one 23-hour day and, while in autumn, there is one 25-hour day.</p><p>The main purpose of daylight saving is to make better use of daylight.</p><p>Countries near the equator, on the other hand, do not follow this approach because dawn and sunset hours do not vary significantly near the equator over the seasonal changes.</p><h4><strong>How do software engineers deal with time zones when developing applications?</strong></h4><p>All programming languages have come up with solutions for these problems, in the early days of programming these were a bit confusing but nowadays libraries and packages are there to help when developing.</p><p>In order to overcome confusions, what we should do is when programming, if we have to save dates and time, we should convert the date and time to UTC time or we have to store the time zone information (offset value)other than saving it as local time. After converting the time we should store the date in the central server. If we save time according to the UTC format is very easy to trace back time according to the specific time zone. Then we can retrieve the data and convert according to the time zone. This should be followed as a practice when developing software&#39;s.</p><p><strong>Eg -:</strong></p><p>Assume my server is in Sri Lanka and the user is in London. As a result, when a user uses the app, he expects to see the clock in his own time zone. For sites where the client and server are in the same time zone, this may not be an issue. When the program displays the server time in Sri Lanka for a client in London, the problem will occur. So, what’s the best way to deal with such a problem?</p><p><strong>Solution:</strong></p><p>We can find the offset value associated with a specific location using a JavaScript API (getTimezoneOffset()). We can determine the time zone based on the location using the offset value, and then record it using a cookie. Finally, submit the information about the time zone to the central server. Now the central server must send the information for that specific time zone. The values must now be sent to the client after converting the time according to the offset (Time zone). When saving date and time information in the central server, we must be vigilant enough to set according to the UTC format.</p><p><strong>You will be able to understand how date and time are managed in Java by reading the article below.</strong></p><p><a href="https://oshanvikasith1998.medium.com/introduction-to-java-date-time-63b02ddab117">Introduction to Java Date &amp; Time. In this article we are going to discuss… | by Oshan Vikasith | Mar, 2022 | Medium</a></p><blockquote><strong><em>Hope you had a better understanding regarding time zones, Hope to see you again in the future with another interesting article.</em></strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f897111d9d0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding The Core Aspects Of Singleton Design Pattern]]></title>
            <link>https://oshanvikasith1998.medium.com/understanding-the-core-aspects-of-singleton-design-pattern-4f7de10a6065?source=rss-f641e7e89be------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f7de10a6065</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-programming]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Oshan Vikasith]]></dc:creator>
            <pubDate>Wed, 09 Mar 2022 12:06:00 GMT</pubDate>
            <atom:updated>2022-03-13T09:00:46.656Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QOp6gadMts6jNzEE" /><figcaption>Photo by <a href="https://unsplash.com/@hishahadat?utm_source=medium&amp;utm_medium=referral">Shahadat Rahman</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>In this article we are going to discuss the Singleton design pattern. In order to start the explanation, I will explain why these patterns do help for software engineers.</blockquote><p><strong><em>Think of an occasion the way you have been treated for a certain disease. For starters the doctor will come and ask some common questions and do some common tests before jumping into any predictions. Which means by their experience they have a certain pattern which they are used to in order to identify the disease.</em></strong></p><p>Similarly in programming languages, developers have tested certain coding styles for several conditions and they have come up with practical solutions. These solutions have been tried and tested numerous times. So as the final output, they were able to come up with the design patterns. Which are much more efficient to use. Singleton design pattern is also one of them.</p><p>As a result, we may argue that these design patterns will provide a general answer to frequent challenges.</p><p><strong>Design patterns are not considered as libraries which means these patterns can not be downloaded. We have to implement them in order to use.</strong></p><p><strong>These design patterns aren’t limited to a specific domain, and if you’re familiar with them, You’ll be able to effortlessly adapt to them.</strong></p><p>According to the Book <strong>Design Patterns — Elements of Reusable object oriented software</strong>, the design patterns have been divided into three type as</p><ol><li>Creational Patterns</li><li>Structural Patterns</li><li>Behavioral Patterns</li></ol><h4><strong>Creational Patterns</strong></h4><p>Creational design patterns are concerned with the way of creating objects. When a decision must be made during the instantiation of a class, these design patterns are used (i.e. creating an object of a class). Trying to create objects in a manner suitable for a situation.</p><h4><strong>Structural Patterns</strong></h4><p>Structural design patterns are concerned with how classes and objects can be composed, to form larger structures. It Simplifies Structure by identifying relationships.</p><h4><strong>Behavioral Patterns</strong></h4><p>Design patterns which identify common communication patterns between objects and realize these patterns.</p><h3>Types of Design patterns and examples</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ztfbsmHlKDaNJRl0" /><figcaption>Figure 1: Types of Design Patterns</figcaption></figure><h3><strong>Singleton Design Pattern Explained</strong></h3><blockquote>Singleton pattern comes under creational design patterns. In singleton pattern what happens is, it makes sure only <strong>one instance of the class per container</strong> is created. <strong>This instance has global point access to it</strong>.</blockquote><p><strong><em>So in the singleton design pattern we can not create numerous instances from a class.</em></strong></p><h4><strong>Occasions where singleton design pattern being used.</strong></h4><ul><li>Used in logging, caching, thread pools, configurations settings etc.</li><li>Used in multi threaded and database applications.</li></ul><h4><strong>Advantages of using Singleton design patterns</strong></h4><ul><li>Save memory because a single instance is used regarding to a specific class</li><li>Efficiency is improved, because after creating the instance the same instance can be used so no need to wait for re creation.</li></ul><h4><strong>UML Representation of Singleton Design Pattern</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bsZBQM-iznkeP2Lp" /><figcaption>Figure 2: UML Representation of Singleton Pattern (<a href="https://en.wikipedia.org/wiki/Singleton_pattern#/media/File:Singleton_UML_class_diagram.svg">Singleton pattern — Wikipedia</a>)</figcaption></figure><h4><strong>Important facts that should be considered when implementing a singleton pattern.</strong></h4><ol><li>If you are implementing a singleton pattern then you should not take any arguments when creating the instance. (Taking arguments in not a preferred way of executing singleton)</li><li>Very hard to do unit tests since there are no instance variables and no references to create. So should not overkill the singleton pattern and use the pattern if only necessary.</li></ol><h4><strong>Design approaches of Singleton design pattern</strong></h4><p>In this article we are going to discuss the following design approaches of singleton pattern.</p><ol><li><strong>Eager initialization</strong></li><li><strong>Lazy initialization</strong></li><li><strong>Double checking initialization</strong></li></ol><h3><strong>Eager Initialization</strong></h3><p>Simplest way of creating the singleton design pattern. Instance of the singleton class is created when the class is loaded to the memory because of the static initializer.</p><p><strong>Note: The instance of the class will be created even though it is not in use.</strong></p><p><strong>Below I have included the implementation code.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fea1f58f2dc2677a105970f520b183db/href">https://medium.com/media/fea1f58f2dc2677a105970f520b183db/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8282624ea661c8e34686151d2a04b0d/href">https://medium.com/media/d8282624ea661c8e34686151d2a04b0d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*a5V0C7pE0ur-dJMGChxWTg.png" /><figcaption>Figure 5: Output</figcaption></figure><p><em>In this above example you can identify that in both print statements the same object is displayed.</em></p><p><strong>In this approach you can see that the instance is being created as a static initializer, which means at the start of the program the instance will be created.</strong></p><p><strong>This technique is thread-safe, however there is a risk of resource leakage if this pattern is used. Because the object is created even when it is not in use.</strong></p><h3><strong>Lazy Initialization</strong></h3><blockquote>An object is created <strong>only when it is required</strong> in this implementation (So the resource wastage is prevented).</blockquote><p>The object will not be created at the point of start, here <strong>according to the</strong> <strong>situation</strong> getInstance() method will be called and it will first check whether the object is null if the object is null then it will create the instance if not return the created instance.</p><p>The Object will not be created unless it is absolutely necessary from this approach.</p><p><strong>Note : This approach is not thread safe because multiple threads can access the method at the same time and it will lead to creation of multiple objects. Therefore this approach can only be used in a Single threaded environment.</strong></p><h4><strong>Below I have included the implementation code.</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8dd09a6ec7c71e93625d4d61002b13c5/href">https://medium.com/media/8dd09a6ec7c71e93625d4d61002b13c5/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27de358ad4e1c835e877777d4a76b25b/href">https://medium.com/media/27de358ad4e1c835e877777d4a76b25b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*lK6crE2YDCkyWMggLeaPnQ.png" /><figcaption>Figure 8: output</figcaption></figure><p>In this approach also you can identify that in both print statements the same object is displayed.</p><h3><strong>Double checking Singleton Approach</strong></h3><blockquote>This method is known as double checking since the issue of resource leakage is minimized when using lazy initialization. However, the fundamental problem with lazy initialization is that it is not thread safe. As a result, a double check is performed in double checking pattern in order to keep the design pattern thread secure.</blockquote><p><strong>Here is the implementation of double checking singleton pattern.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afe876f7ded7fefbbab973b2d6cfc94a/href">https://medium.com/media/afe876f7ded7fefbbab973b2d6cfc94a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3d4b3db40eb7559acf46cc4b335cd4c/href">https://medium.com/media/d3d4b3db40eb7559acf46cc4b335cd4c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*P40mkS31qjON80Kd7B3QGw.png" /><figcaption>Figure 11: Final Output</figcaption></figure><p><em>So, in this double-checking singleton approach, you can see an if condition in Figure 9 where the constructor is being built. This if condition is used because reflection API constructs can be used to build objects of classes. So, in order to prevent instances from being created using the reflection API. In the constructor, we verify and throw an exception if someone tries to do so.</em></p><p>You can see that a <strong>synchronized block</strong> is used in the get instance method, and that the method also has two if conditions. <strong>The</strong> <strong>main advantage of synchronized is that once a thread enters a block, no other thread can access it.</strong></p><p>So, in the first if condition, it will see if an object has been created, and if not, it will proceed to the synchronized block (thread 1). Other threads cannot access the synchronized block while thread1 is performing operations inside it. The instance will be returned once the object has been created. The waiting thread (thread 2) will then be able to access the block, but there is yet another if statement, this time checking whether an object has been created. Since an object has been created, the authorization to create another object will be denied, and the same instance will be returned.</p><p><strong>Note: At the method level, some developers use the synchronized keyword. This is something that should be avoided at all costs. Because using the synchronized keyword at the block level disables the entire procedure and reduces performance.</strong></p><p>Mostly this Singleton pattern is used when creating a database connection.</p><h4>Efficiency of the Singleton pattern.</h4><p>By using the below code segment you will be able to understand the efficiency of the singleton pattern.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d6c37f259516ee66fd1ff696bd0e09e/href">https://medium.com/media/2d6c37f259516ee66fd1ff696bd0e09e/href</a></iframe><p>In this code segment what I have done is creating two “<strong>DobleCheckingPattern</strong>” class type variables and assigning the instance for them. I record the time it takes to create and assign the instance using start and end long type variables.</p><p><strong>What do you think the output would be?</strong></p><p>Here I have included the screenshot of the resulting output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*gKiHyW5ut2qaG1zPI1_OmA.png" /><figcaption>Figure 13 : Final Output</figcaption></figure><blockquote>This design pattern will cut down on the time it takes to create objects. As you can see, it took a bit of time initially, but there was no time used after that. With the help of this design pattern, efficiency is increased. However, we should be more cautious when using the singleton design because there are specific situations where it might bring complications. I discussed them during the initial part of this article.</blockquote><p><strong>Hope you had a clear idea about singleton design pattern.</strong></p><p><em>Hope you got a clear and better understanding regarding the design pattern related to java. Hope to see you again in a future article, Thank you for reading !</em></p><p><strong>Here I have included the sources which I have referred.</strong></p><p><a href="https://www.youtube.com/watch?v=g7RfBhO-rhU&amp;list=PLD-mYtebG3X86i3uyAXwZKfVtUy2gMDdo">(4231) Power of Singleton Design Pattern | Design pattern you MUST know — YouTube</a></p><p><a href="https://www.geeksforgeeks.org/singleton-design-pattern-introduction/">Singleton Design Pattern | Introduction — GeeksforGeeks</a></p><p><a href="https://www.tutorialspoint.com/design_pattern/singleton_pattern.htm">Design Pattern — Singleton Pattern (tutorialspoint.com)</a></p><p><a href="https://en.wikipedia.org/wiki/Singleton_pattern">Singleton pattern — Wikipedia</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f7de10a6065" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Edge Cases Of Numbering System in Java]]></title>
            <link>https://oshanvikasith1998.medium.com/edge-cases-of-numbering-system-in-java-a08901033297?source=rss-f641e7e89be------2</link>
            <guid isPermaLink="false">https://medium.com/p/a08901033297</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Oshan Vikasith]]></dc:creator>
            <pubDate>Mon, 07 Mar 2022 05:50:11 GMT</pubDate>
            <atom:updated>2022-03-07T05:50:11.118Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J1aqkw-xnhaTJQLB" /><figcaption>Photo by <a href="https://unsplash.com/@mbaumi?utm_source=medium&amp;utm_medium=referral">Mika Baumeister</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Java consists of quite a bit of Integral data types for performing calculations. The integral data types are Byte, Short, integer, long. These data types are very essential when doing arithmetic operations. Size of the value that can hold in a specific data type varies from one another. Given below are the integral data types.</blockquote><ul><li><strong>Byte — From -128 to maximum of 127 (-2⁷ to 2⁷ -1)</strong></li><li><strong>Short — From -32,768 to maximum of 32,767 (-2¹⁵ to 2¹⁵ -1)</strong></li><li><strong>Integer — From -2147483648 to 2147483648 (-2³¹ to 2³¹-1)</strong></li><li><strong>Long — From -9223372036854775807 to 92233720368547755807 (-2⁶³ and a maximum of 2⁶³-1)</strong></li></ul><p><strong><em>When using integral data types for mathematical operations have you ever encountered a situation where you end up with an unusual result. Have you ever wondered what happens when we try to add a value which is greater than the value that can be held by a certain data type?</em></strong></p><h4><strong>Example of Such an instance</strong></h4><p>In this example we are going to use the Byte variable type to demonstrate such a situation.</p><p>Imagine you have two byte variables named x and y. The variables are assigned with values as below. x=124 &amp; y = 7</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f68f4c839c6a2da56e11da99d313c02/href">https://medium.com/media/2f68f4c839c6a2da56e11da99d313c02/href</a></iframe><p><strong>What would you think the output would be?</strong></p><p>Is it 130? No, the answer is not 130. Here we are going to explain how we can calculate the resulting value in this kind of a situation.</p><p><strong>An interesting fact is that in Java these numbers are arranged in a circular pattern.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hq9IN85pFbaRMD-ZDsWj8g.jpeg" /><figcaption>Figure 1: Number distribution in Java</figcaption></figure><p><strong>Number systems in java do not follow the principles which are normally used in arithmetic operations.</strong></p><p>Here numbers are not arranged in a linear pattern as in general mathematics. In programming these distribution of positive and negative numbers are arranged in a circular pattern as above. So once the number reaches its peak in minimum level or maximum level, from there the value moves for either positive side or negative side with respect to the added or subtracted value.</p><p><strong>So in the above example we add 7 to 124 which means it will go past positive 127. Because of the circular distribution of the number system after passing 127 it will go for the values which are placed in the negative boundary. So the output would be -125.</strong></p><p><em>This is one of the edge cases you will find in java. So we should carefully select the variable when doing arithmetic operations otherwise we will end up with unusual values such as having a negative value or a 0 for an answer, which should obtain a positive value.</em></p><blockquote><em>Hope you got a clear and better understanding regarding the number systems used in java. Hope to see you again in a future article, Thank you for reading !</em></blockquote><p><strong>Here I have included the articles which I have referred</strong></p><p><a href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#:~:text=The%20integral%20types%20are%20byte,code%20units%20(%C2%A73.1).">Chapter 4. Types, Values, and Variables (oracle.com)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a08901033297" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JVM Data Types Explained]]></title>
            <link>https://oshanvikasith1998.medium.com/jvm-data-types-explained-8652c691ad5f?source=rss-f641e7e89be------2</link>
            <guid isPermaLink="false">https://medium.com/p/8652c691ad5f</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Oshan Vikasith]]></dc:creator>
            <pubDate>Sun, 06 Mar 2022 19:07:08 GMT</pubDate>
            <atom:updated>2022-03-06T19:07:08.410Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SRDpDgQOt-WV2iU1" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=medium&amp;utm_medium=referral">Markus Spiske</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>In this article we are going to discuss the data types which are associated with the JVM. These data types are more or less similar to the data types which are used in java programming aspects.</blockquote><h4>There are two types of data types in JVM, they are as follows</h4><ol><li>Primitive Data Type</li><li>Referenced Data Type</li></ol><h4><strong>What is the primitive data type ?</strong></h4><p><em>In the primitive data type it will hold the value in the variable itself.</em></p><h4><strong>What is the Referenced data type?</strong></h4><p><em>In the referenced type it will hold the reference to the value.</em></p><h3><strong>Primitive Data Type</strong></h3><p>In the primitive type all the data types except Boolean act the same as the data types which involve when programming java. The difference with the Boolean data type is that it gets slightly less support from the instruction set. Because of that Boolean is always referred to in the JVM by either integer or byte.</p><ul><li><strong>Boolean False is represented as — 0</strong></li><li><strong>Boolean True is represented as — 1</strong></li></ul><p>The Sizes of these data types are similar in every environment. The long data type takes size as 64 bit in every implementation that does not change with respect to platform. That’s the only difference in the data types.</p><p>There is a unique data type which consists in the primitive data types, that is the <strong>Return Address</strong> type. The Return address data type is used to implement the final block. This data type is not accessible for the developers, it is used only in JVM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GSTAV9b4b_o9Gh0POgNPOg.jpeg" /><figcaption>Figure 1: Primitive Data Type Distribution</figcaption></figure><h3><strong>Referenced Data Type</strong></h3><p>In the referenced data type it will store the reference to the variable.</p><h4><strong>Under referenced type these variables types exist.</strong></h4><ol><li>Class Type</li><li>Interface Type</li><li>Array Type</li></ol><h4><strong>Class Type</strong></h4><p>Referenced to instance of class type.</p><h4><strong>Interface Type</strong></h4><p>Interface type is referenced to class implementation.</p><h4><strong>Array Type</strong></h4><p>Referenced to array.</p><h3><strong>Word Size In JVM</strong></h3><p>Word size is used as a unit in obtaining data values in JVM. The length of the word size is decided by the particular JVM implementation.</p><p><strong>There are two rules that need to be obeyed when defining word size</strong></p><ol><li><strong>Particular word size should be able to hold any primitive data type.</strong></li></ol><p><em>Eg-: if we have any word and if there is a variable in integer type named as “value” then word should be able to hold the variable “value”</em></p><p>2.<strong> Two word sizes need to be used for long or double values.</strong></p><p>So at least this word size should be at 32 bits.</p><p>In internal implementation of JVM, word size is widely used..</p><p><em>Eg -: In the java stack, there is a special location where it will store local variables. If you insert an integer type primitive variable then this variable should be held by one word. If it is double or long then it should be held by two word sizes</em></p><h3><strong>JVM Data type Analyzed Diagram.</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H1GWYi8JmSVHwn3McKPp8Q.jpeg" /><figcaption>Figure 2: JVM Data Types</figcaption></figure><blockquote>Hope you got a clear and better understanding regarding the core fundamental aspects of java. Hope to see you again in a future article, Thank you for reading !</blockquote><p>Here I have included the sources which I have referred.</p><p><a href="https://www.youtube.com/watch?v=6AWckdRYWTI">(4211) JVM part 03 — Data Types in JVM — YouTube</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8652c691ad5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JDK vs JRE vs JVM]]></title>
            <link>https://oshanvikasith1998.medium.com/jdk-vs-jre-vs-jvm-3fbf91ad9beb?source=rss-f641e7e89be------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fbf91ad9beb</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java-development]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Oshan Vikasith]]></dc:creator>
            <pubDate>Fri, 04 Mar 2022 03:41:10 GMT</pubDate>
            <atom:updated>2022-03-04T10:59:32.597Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IYffUjCBPvmsuGgE" /><figcaption>Photo by <a href="https://unsplash.com/@ffstop?utm_source=medium&amp;utm_medium=referral">Fotis Fotopoulos</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>By looking at the terms you should know these components are associated with java. Each of these components performs a unique task relevant to java development. So in this article we are going to understand the functionalities and the differences of each of these components.</blockquote><h3><strong>JDK (Java Development Kit)</strong></h3><p><strong>Java development Kit is the software development environment used to develop java programs.</strong> It consists of JRE(Java Runtime Environment), libraries, compiler, a documentation generator (Javadoc), Interpreter and other tools needed in java application development.</p><p><strong>Java development Kit exists physically</strong>. (Consisted with JRE + development tools)</p><p><strong>JDK is an implementation of any of Oracle Corporation’s Java Platforms, as listed below:</strong></p><ol><li>Standard Edition Java Platform</li><li>Enterprise Edition Java Platform</li><li>Micro Edition Java Platform</li></ol><ul><li><strong>JDK is highly platform dependent</strong>, It means the JDK for windows operating system will not work for a Linux environment. We have to select the JDK relevant to our specific platform. If not, Java language will not work.</li><li>JDK is in charge of primary development, it includes tools for creating, debugging, and monitoring Java applications.</li><li>For your reference here I have included some of the components that lie within JDK, These components will not be discussed through this article. Which will be discussed in the future. Here I have mentioned a few of them.</li></ul><h4><strong>Appletviewer</strong></h4><p><em>Used to run and debug Java applets without a web browser.</em></p><h4><strong>Apt</strong></h4><p><em>Annotation-processing tool.</em></p><h4>Extcheck</h4><p><em>A utility that detects JAR file conflicts.</em></p><h4>Javac</h4><p><em>Specifies the Java compiler, converts source code into Java bytecode.</em></p><h4><strong>Javadoc</strong></h4><p><em>The documentation generator.</em></p><h4><strong>Jar</strong></h4><p><em>Specifies the archiver, helps to manage JAR files.</em></p><h4><strong>Javafxpackager</strong></h4><p><em>It is a tool to package and sign JavaFX applications.</em></p><h4><strong>Architectural View</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/0*oRQrZBoKA8x4TpKv" /><figcaption>Figure 1: Architectural View of JDK (https://www.javatpoint.com/difference-between-jdk-jre-and-jvm)</figcaption></figure><h3><strong>JRE (Java Runtime Environment)</strong></h3><ul><li><strong>JRE stands for Java Runtime Environment</strong>, Java runtime environment is the implementation of JVM. JRE provides an environment to run java programs.</li><li>JRE consists of Java Virtual Machine, core classes and supporting files in order to provide implementations.</li><li>Exists physically, It comprises a collection of libraries as well as other files that JVM uses during execution.</li><li>Major responsibility of the JRE is to provide the environment for code execution.</li><li>Similarly as to JDK, JRE is also platform dependent which means we have to have JRE compatible for relevant platforms. Otherwise the language will not function.</li><li>Does not contain any tools such as compilers or debuggers etc. Rather, it contains the class libraries and other supporting files required by JVM to run the program.</li></ul><p><strong>JRE consist of following components</strong></p><ol><li>Deployment Technologies</li><li>User Interface Tool kits</li><li>Integration Libraries</li><li>Other base Libraries</li><li>Lang and Util base Libraries</li><li>Java Virtual Machine</li></ol><p><strong>Following actions occur at run time</strong></p><ul><li>Class Loader</li><li>ByteCode Verifier</li><li>Interpreter</li><li>Execute the Byte Code</li><li>Make appropriate calls to the underlying hardware</li></ul><h3><strong>JVM (Java Virtual Machine)</strong></h3><ul><li><strong>JVM</strong> is a process or a program which is not a physical entity; that holds specifications which are relevant to java.</li><li>JVM, on the other hand, specifies all implementations and is responsible for providing them to JRE.</li><li>Can not install or download JVM, because it does not exist as a physical entity.</li><li>When a Java program runs, JVM becomes an instance of JRE.</li></ul><blockquote><strong>JVM is platform dependent, JVM comes with JRE so if we download a JRE for a windows platform then JRE will implement the code segment to create a JVM for windows environment. Similarly this happens for all the other platforms as well.</strong></blockquote><h4><strong>JVM Consist of 3 Main Components, they as follows</strong></h4><ol><li>Class Loader</li><li>Memory Area</li><li>Execution Engine</li></ol><ul><li>JVM will perform many core functionalities such as it will be responsible to load the class and store relevant details and finally execute the java code.</li><li>These aspects are discussed thoroughly in the below given article. Here I have attached the link for your reference.</li></ul><h4>Article Link: <a href="https://oshanvikasith1998.medium.com/understanding-the-core-concepts-behind-jvm-jre-and-jdk-in-java-ce67c1be81f5">Understanding The Core Concepts Behind JVM, JRE and JDK in Java. | by Oshan Vikasith | Feb, 2022 | Medium | Medium</a></h4><ul><li>Functionality of the major components are discussed in the above mentioned article.</li><li>You can get a much more clear idea about JVM through the above article.</li></ul><h4>JVM Architecture</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/0*gwEN8lmcL29ic65J" /><figcaption>Figure 2: Architecture of JVM (<a href="https://www.freecodecamp.org/news/content/images/size/w1000/2021/01/image-39.png">image-39.png (1000×578) (freecodecamp.org)</a>)</figcaption></figure><blockquote><em>Hope you got a clear and better understanding regarding the core fundamental aspects of java. Hope to see you again in a future article, Thank you for reading !</em></blockquote><p><strong>Here I have included the sources which I have referred.</strong></p><p><a href="https://www.javatpoint.com/jdk">JDK | Java Development Kit — Javatpoint</a></p><p><a href="https://www.javatpoint.com/difference-between-jdk-jre-and-jvm">Difference between JDK, JRE and JVM — javatpoint</a></p><p><a href="https://www.tutorialspoint.com/What-is-the-difference-between-JDK-JRE-and-JVM">What is the difference between JDK, JRE, and JVM? (tutorialspoint.com)</a></p><p><a href="https://www.youtube.com/watch?v=bUtIIWbaFKc">What is JVM — Java Virtual Machine — YouTube</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fbf91ad9beb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction To Java Date & Time]]></title>
            <link>https://oshanvikasith1998.medium.com/introduction-to-java-date-time-63b02ddab117?source=rss-f641e7e89be------2</link>
            <guid isPermaLink="false">https://medium.com/p/63b02ddab117</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-programming]]></category>
            <category><![CDATA[java-developer]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Oshan Vikasith]]></dc:creator>
            <pubDate>Tue, 01 Mar 2022 13:18:12 GMT</pubDate>
            <atom:updated>2022-03-01T13:18:12.530Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction to Java Date &amp; Time</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Pp72tBa5MIuebCox" /><figcaption>Photo by <a href="https://unsplash.com/@aronvisuals?utm_source=medium&amp;utm_medium=referral">Aron Visuals</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>In this article we are going to discuss mainly about handling date &amp; time through java.util.date package, java.sql.date package and the newly constructed java 8 data and time API.</strong></p><p>Before discussing each of these topics it’s better to know about the epoch time.</p><blockquote>It is essential to know the theoretical aspects behind the concept epoch, because it is widely used in java when calculating date and time.</blockquote><h3><strong>Epoch Time</strong></h3><blockquote><strong>The epoch time</strong> (<strong>unix time, posix time, unix epoch time, seconds since epoch</strong>) is the number of seconds elapsed since January 1, 1970 at midnight UTC, excluding leap seconds. In epoch time each day is treated as if it contains exactly 86,400 seconds. So this is not a true representation of UTC time.</blockquote><p><strong>Epoch time</strong> is widely used in operation systems, file formats and in Unix-like operating systems.</p><p><strong>Epoch time</strong> 0 is midnight January 1st 1970 (in ISO 8601: 1970–01–01T00:00:00Z).</p><p>Some systems store epoch dates as a signed 32-bit integer, which might cause problems on January 19, 2038 (known as the Year 2038 problem or Y2038).</p><p><strong>The reason we discussed epoch time is that in java when calculating date and time, epoch time is used so this introduction will help to understand the concepts more clearly.</strong></p><p>Now we are going to discuss the classes used in java in order to calculate date and time.</p><h3>Java.Sql.Date</h3><p>The java.sql.Date class inherits java.util.Date class. In java.sql.Date , it will only deliver the date as an output.</p><p><strong>Java.sql.date</strong> will represent only the SQL date which as <strong>years, months &amp; date.</strong> T<strong>ime is not kept within the sql.Date class</strong>.</p><p>In java.sql.Date the date will be stored in milliseconds from the 1st of January 1970 (epoch time).</p><p>It is better to use sql.date class when handling data related to SQL specific requirements. It adds formatting and parsing operations to support JDBC.</p><h4><strong>This class does not hold any time zone information.</strong></h4><h3><strong>Constructor of the java.sql.Date class</strong></h3><blockquote><strong>Date(long milliseconds) — construct a date using milliseconds time value.</strong></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/765dcf6fd3fb76d14917ff2f308f9ce0/href">https://medium.com/media/765dcf6fd3fb76d14917ff2f308f9ce0/href</a></iframe><p><strong>Output :- 2022–03–01</strong></p><h3><strong>Methods (java.sql.date)</strong></h3><h4><strong><em>void setTime(long time)</em></strong></h4><p><em>Changes current SQL date to given time</em></p><h4><strong><em>Instant toInstant()</em></strong></h4><p><em>Convert current SQL date into instant object</em></p><h4><strong><em>LocalDate toLocalDate()</em></strong></h4><p><em>Convert current SQL date to locale date object</em></p><h4><strong><em>String toString()</em></strong></h4><p><em>Convert this SQL date object to a string</em></p><h4><strong><em>static Date valueOf(LocalDate date)</em></strong></h4><p><em>Returns SQL date object for the given Local Date.</em></p><h4><strong><em>static Date valueOf(String date)</em></strong></h4><p><em>Returns SQL date object for the given String</em></p><h3><strong>Java.util.Date</strong></h3><p>The <strong>java.util.Date</strong> class represents data and time in java.</p><p>Java.util.Date represents a particular moment in time with millisecond precision since 1st of January 1970 epoch time. (00:00:00 GMT).</p><p>The java.util.Date class implements Serializable, Cloneable and Comparable&lt;Date&gt; interface.</p><p>It is inherited by java.sql.Date, java.sql.Time and java.sql.Timestamp interfaces.</p><h3><strong>Constructor of the Java.util.Date Class</strong></h3><p><strong>Date()</strong> —<em> Initializes the object with the current date and time</em></p><p><strong>Date(long millisecond)</strong> —<em> Initializes the object with the specified number of milliseconds since January 1, 1970, 00:00:00 GMT.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/981c9d49eb58f37f9f441d235159284c/href">https://medium.com/media/981c9d49eb58f37f9f441d235159284c/href</a></iframe><p><strong>Output : Tue Mar 01 12:44:35 IST 2022</strong></p><h3>Methods (java.util.date)</h3><h4><strong>boolean after(Date date)</strong></h4><p>Check if the current date is after the given date.</p><h4><strong>boolean before(Date date)</strong></h4><p>Check if the current date is before the given date.</p><h4><strong>Object clone()</strong></h4><p>Return the clone object of the current date.</p><h4><strong>int compareTo(Date date)</strong></h4><p>Compare current date with the given date.</p><h4><strong>boolean equals(Object date)</strong></h4><p>Check whether the current date and the given date are equal.</p><h4><strong>long getTime()</strong></h4><p>returns the time represented by this date object.</p><h4><strong>int hashCode()</strong></h4><p>returns the hash code value for this date object.</p><h4><strong>void setTime(long time)</strong></h4><p>Sets this Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.</p><h4><strong>String toString()</strong></h4><p>Converts this Date object to a String.</p><h3><strong>Java Date</strong></h3><blockquote><strong>Due to the fact that some core issues were identified in java.util.Date package and java.util.Calendar package, in java 8 a new API was introduced to handle date and time.</strong></blockquote><p>These are the issues which arrived because of the previous data and time APIs</p><ol><li>Issues with regards to thread safety.</li><li>API design and ease of understanding.</li><li>Issues with regards to dates and times in different time zones .</li></ol><h4><strong>Thread Safety</strong></h4><p>Date and calendar classes are not thread safe. Developers have to dedicate additional time and logic to make it thread safe. Newly constructed APIs are immutable and thread safe.</p><h4><strong>API design and ease of understanding</strong></h4><p>Design of the data and calendar APIs are poorly constructed. Consist of a wide variety of utility methods to support date and time related operations.</p><h4><strong>Issues with regards to dates and times in different time zones</strong></h4><p>In the previous API, had to implement additional logic when it comes to execute time zones specific requirements. Newly constructed API is included with Local and zonedDate/ time APIs.</p><blockquote><strong>Now we are going to discuss about the newly introduced java date and time API.</strong></blockquote><h4><strong>Following are some of the classes introduced newly to java 8.</strong></h4><ol><li><strong>Java LocalDate class.</strong></li><li><strong>Java LocalTime class.</strong></li><li><strong>Java LocalDateTime class.</strong></li><li><strong>Java MonthDay class.</strong></li><li><strong>Java OffsetTime class.</strong></li><li><strong>Java OffsetDateTime class.</strong></li><li><strong>Java Clock class.</strong></li><li><strong>Java ZonedDateTime class.</strong></li><li><strong>Java ZoneId class.</strong></li><li><strong>Java ZoneOffset class.</strong></li><li><strong>Java Year class.</strong></li><li><strong>Java YearMonth class.</strong></li><li><strong>Java Period class.</strong></li><li><strong>Java Duration class.</strong></li><li><strong>Java Instant class.</strong></li><li><strong>Java DayOfWeek class.</strong></li><li><strong>Java Month enum.</strong></li></ol><p><strong>Local:</strong> Simplified date-time API with no complexity of time zone handling.</p><p><strong>Zoned:</strong> Specialized date-time API to deal with various time zones.</p><p>Each of these classes consist of methods which will help to get relevant tasks done quite efficiently. You can refer to those by going through the referenced links attached to this article.</p><p>To work with local date and time, api provides classes such as below in order to get the required task done efficiently.</p><ul><li>LocalDate</li><li>LocalTime</li><li>LocalDateTime</li></ul><p>Following class is implemented in order to manage date and time with respect to time zones. There are 40 different time zones specified.</p><ul><li>ZonedDateTime</li></ul><p><strong><em>Hope you had a better understanding regarding java date classes, Hope to see you again in the future with an another interesting article.</em></strong></p><p>Here I have included the sources which I referred.</p><p><a href="https://www.javatpoint.com/java-sql-date">java.sql.Date — Javatpoint</a></p><p><a href="https://www.w3schools.com/java/java_date.asp">Java Date and Time (w3schools.com)</a></p><p><a href="https://www.javatpoint.com/java-util-date">java.util.Date — Javatpoint</a></p><p><a href="https://www.w3schools.blog/java-8-date-time-api">Java 8 date time api tutorial — W3schools</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63b02ddab117" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding The Core Concepts Behind JVM, JRE and JDK in Java.]]></title>
            <link>https://oshanvikasith1998.medium.com/understanding-the-core-concepts-behind-jvm-jre-and-jdk-in-java-ce67c1be81f5?source=rss-f641e7e89be------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce67c1be81f5</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[java-tips]]></category>
            <category><![CDATA[java-programming]]></category>
            <category><![CDATA[java-fundamentals]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Oshan Vikasith]]></dc:creator>
            <pubDate>Sun, 06 Feb 2022 11:18:06 GMT</pubDate>
            <atom:updated>2022-02-06T15:09:58.272Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7QoUjsZ6GDEvcwFd" /><figcaption>Photo by <a href="https://unsplash.com/@ffstop?utm_source=medium&amp;utm_medium=referral">Fotis Fotopoulos</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>What is Java? Do you know the concepts behind JVM, JRE &amp; JDK !</strong></h3><p>Java is a High level, object oriented (class based) programming language which was initially invented by James Gosling at Sun Microsystems. Previous java implementations were owned by Sun Microsystems and currently it is owned by Oracle.</p><p>Java uses both interpretation and compilation techniques when executing a program. First the java code will be compiled into bytecode. A “.class” file will be generated through this process. Then JVM will go through the interpretation process. Finally the output relevant to the java program will be available.</p><h4><strong>Now we are going to discuss some of the basic fundamentals which a developer should know about java.</strong></h4><blockquote><em>Java comes with three main components, namely</em></blockquote><ol><li><strong>JDK — Java Development Kit</strong></li></ol><p><strong>2. JRE — Java Runtime Environment</strong></p><p><strong>3. JVM — Java Virtual Machine</strong></p><p>If you are going to develop a java program it is essential that you should know what these components do.</p><p>In order to create a java program you can use any java enabled IDE/Notepad and a platform which consists of java.</p><h3><strong>What is JDK (Java Development Kit)?</strong></h3><blockquote>JDK is the software development environment which is used to develop a java program. It consists of the Java runtime environment, libraries, compiler and the interpreter in order to develop a java based program.</blockquote><h3><strong>What is JRE (Java Runtime Environment)?</strong></h3><blockquote>JRE provides implementations regarding java specifications. JRE provides the environment to run a java program (not for development purposes).</blockquote><p>JRE is operating system dependent, which means for a windows machine we have to use JRE compatible for a windows environment. Similarly for mac environments have to have a JRE compatible for Mac.</p><p><strong>Now we are going to discuss deeply about Java Virtual Machine. In order to discuss JVM you should know about virtual machines.</strong></p><h3><strong>Java Virtual Machine (JVM)</strong></h3><h4><strong>Virtual Machine</strong></h4><p>“<strong>Virtual</strong>” means something that does not exist physically, but it gives the experience, just as the real entity with the help of a software or through an artificial influence.</p><p>“Virtual Machine” means something that does not exist physically but it gives the experience as if it is real and helps to get the relevant tasks done efficiently. That’s the general Idea of “<strong>Virtual Machine</strong>”.</p><p><strong>There are two types of Virtual Machines in the field of computing.</strong></p><ul><li>System Based Virtual Machine</li><li>Application Based Virtual Machine</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*dOb0lHuN0HWIOfK9RfPoGg.jpeg" /><figcaption>Figure 1: Types of Virtual Machines</figcaption></figure><h4><strong>What is JVM (Java Virtual Machine)?</strong></h4><blockquote>JVM is a process or a program which is not a physical entity; that holds specifications which is relevant to java.</blockquote><p>You cannot install or download JVM because it is not a physical entity. JVM comes with the JRE.</p><p><strong>Is the JVM platform independent ?</strong></p><p><strong>JVM is highly platform dependen</strong>t, which means the answer for the above question is <strong>“No”</strong>. The reason behind this is that when we install JRE for windows operating system, JRE will execute code necessary to create JVM instance for windows operating system. If we install JRE for the Mac environment then we will end up with a JVM instance authenticated for the Mac environment. So it is dependable with the operating system.</p><p><strong><em>Similarly JRE and JDK are also platform dependent but the language Java is not platform dependent.</em></strong></p><h3><strong>Creation and destruction of JVM instance</strong></h3><h4><strong>Creation of JVM Instance</strong></h4><p>When we create a java program first what we do is save the code and compile using j<em>avac</em> command. If there are no errors in the program then we have the ability to move to the next command, which is by giving java and the name of the java file in the command line environment.</p><p><strong>If the Name of the file is Application.java</strong></p><p><strong>In order to compile</strong> — javac Application.java</p><p><strong>Run java program </strong>— java Application</p><p>The moment we call <strong>“java Application”</strong> in the command line, what happens is, a JVM instance will be created. Simply calling java in the command line invokes a JVM instance. Then the program will run on that JVM instance.</p><p>In the same environment if we implement another java program, then another JVM instance will be created. So there will be two JVM instances created in the system. If we implement multiple java programs then java will facilitate the creation of multiple JVM instances which is equal to the number of programs executed. <strong>Each program will run on a separate JVM instance;</strong> <strong>not all programs run on the same JVM instance.</strong></p><p><em>Eg-: Run 10 java programs, 10 JVM instances will be created.</em></p><p>The JVM instance will exist only till the program runs. If the program terminates then the relevant JVM instance will also get destroyed.</p><h4><strong>Destruction of JVM instance</strong></h4><p>Now we are going to discuss how a JVM instance gets destroyed. There are 2 methods</p><ol><li>If all non daemon threads are destroyed (JVM instance will exist only till single non daemon thread exists)</li><li>Calling System.Exit() method.</li></ol><p>Given above are the two ways that a JVM instance can be destroyed.</p><p><em>Will discuss more about daemon and non daemon threads in a future article.</em></p><h3><strong>JVM Architecture</strong></h3><p>There are 3 main components exist in JVM, they are as follows</p><ol><li><strong>Class Loader</strong></li><li><strong>Memory Area</strong></li><li><strong>Execution Engine</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*iyXDphU4GKMNXR4oACBHGw.png" /><figcaption>Figure 2: JVM Architecture (<a href="https://www.freecodecamp.org/news/content/images/size/w1000/2021/01/image-39.png">https://www.freecodecamp.org/news/content/images/size/w1000/2021/01/image-39.png</a>)</figcaption></figure><h4><strong>Class Loader</strong></h4><p>Main responsibility of the class loader is to load the class information into the method area of the memory area.</p><p><strong>Class Loader is responsible to execute three phases, which are</strong></p><ol><li><strong>Loading</strong></li><li><strong>Linking</strong></li><li><strong>Initialization</strong></li></ol><h3><strong>Loading</strong></h3><p>Processes which undertake in loading phase is as follows.</p><ol><li><strong>Capture relevant information and store them in the memory(method area)</strong></li></ol><p>In the loading phase what happens is initially it reads the “.class” file and generates relevant binary data then stores it in the method area. Below mentioned details will be stored in the memory(method area).</p><ul><li>Fully qualified name of the loaded class and it’s immediate parent class.</li><li>Immediate parent class information.</li><li>Whether it’s a class, interface or enum.</li><li>Instance variable information.</li></ul><p><strong>2. Create a class type object and assign it with the loaded class</strong></p><p>After reading the above information JVM will create an object from the class type (class pre-defined in java.lang package) and assign it with the loaded class. Finally this object will be stored into heap memory.</p><p>This class type object will be created only once for a loaded class.</p><p><strong><em>Eg-:</em></strong><em> If there is an Employee class, In the initial stage class loader will load the class and it will read the above-mentioned details and store data in the method area. Then an object from the class type will be created and it will get assigned with the loaded class. Finally the created object will be stored in the heap memory.</em></p><h3><strong>Linking</strong></h3><p>In the Linking process there are 3 phases as follows</p><ol><li><strong><em>Verification</em></strong></li><li><strong><em>Preparation</em></strong></li><li><strong><em>Resolution</em></strong></li></ol><h4><strong>Verification</strong></h4><p>In the verification process it will check whether the .class file is safe to execute or not. Ensures the correctness of the .class file.</p><p>Java has a component created especially to ensure the correctness of the “.class” file which is the <strong>ByteCodeVerifier</strong>.</p><p><strong>ByteCodeVerifier</strong> will check whether the file is properly formatted and whether the file is generated from a valid compiler.</p><p>If any issues are identified then a run time exception will be thrown. (<strong>java.lang.VerifyError</strong>)</p><p>This verifying process will be the key activity undergoing in the verification phase.</p><h4><strong>Preparation</strong></h4><p>Default values will be assigned to any instance variables and static variables declared in the class through the preparation phase.</p><h4><strong>Resolution</strong></h4><p>In the resolution phase symbolic references will be replaced by the direct links.</p><h3><strong>Initialization</strong></h3><p>In the initialization phase all the static variables declared in the class and static block(if any) will get assigned with their values.</p><p>This process is executed from top to bottom in a class and from parent to child in class hierarchy.</p><p>JVM has a limitation that each class should be initialized before it’s active use.</p><p><strong>How is class considered to be in active use ?</strong></p><ol><li>New keyword used.</li><li>Invoke static method.</li><li>Assign values to a static field.</li><li>If the initial class is the one which consists of the main method.</li><li>Use of reflection API (getInstance()).</li><li>Instance of a subclass.</li></ol><p><em>If the class is subjected to any of the above points then it is mandatory to go through the initialization process otherwise it is not required.</em></p><p><strong>In java there are multiple ways to initialize a class, below are the ways in which we can use to do the same.</strong></p><ol><li>Using the new Keyword.</li><li>Using the Clone method. (clone())</li><li>Using reflection API. (getInstance())</li><li>Using IO.ObjectInputStream Class</li></ol><blockquote><strong>Now we covered the functionalities of the class loader and how the class loader performs its actions. When it comes to class loaders there are types which we are not going to discuss further through this article. Here I have mentioned the types of class loaders for you.</strong></blockquote><ol><li>Bootstrap Class Loader</li><li>Extension Class Loader</li><li>System/Application Class Loader</li></ol><p><em>Now we are going to discuss about the second core component of the JVM which is the memory area.</em></p><h3><strong>Memory Area</strong></h3><p>Memory area is included with 5 components, they are as follows</p><ol><li>Method Area</li><li>Heap area</li><li>Stack area</li><li>PC Registers</li><li>Native method area</li></ol><h3><strong>Architectural View of Memory Area</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kr-pjCATR4B0_nFJrOLsDQ.jpeg" /><figcaption>Figure 3: Architecture of Memory Area</figcaption></figure><p>Now we are going to discuss the functionalities of these components.</p><h4><strong>Method Area</strong></h4><p>Class level information will be stored in the method area such as class name, immediate parent class name, method and variable information including static variables.</p><h4><strong>Heap Area</strong></h4><p>Information regarding to all the objects will be stored inside the heap area.</p><h4><strong>Stack Area</strong></h4><p>Run time stack created for every thread will be stored in the stack.</p><p>Every block of this stack is named as activation record/ stack frame which will store the method calls.</p><p>All the local variables of that method will be stored in the corresponding stack frame.</p><p>Responsible for storing method information.</p><p>Run time stack will be destroyed after the termination of the corresponding thread.</p><h4><strong>PC Registers</strong></h4><p>If a non native method was executed then pc registers will store the information about the next execution. When a native method gets executed the pc registers will not store any information.</p><p><strong>Native method</strong> is a java method which is implemented through a different programming language such as C++.</p><h4><strong>Native method Area</strong></h4><p>Stores native method information.</p><p>After discussing the functionalities of the memory area, it’s better to identify core data types which are used commonly in JVM.</p><p>There are two types of data types used in the JVM, namely.</p><ol><li>Primitive data type.</li><li>Referenced data type.</li></ol><p><strong>Primitive data type — </strong>Hold the value in the variable itself.</p><p><strong>Referenced data type</strong> — Hold the reference to the value.</p><p>Here in this diagram shows the flow of data types which are used in the JVM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H1GWYi8JmSVHwn3McKPp8Q.jpeg" /><figcaption>Figure 4: JVM Data Types</figcaption></figure><p>Here we are going to discuss the final component of the JVM which is the execution engine.</p><h3><strong>Execution Engine</strong></h3><p>Execution engine is the one which will dedicate its time to execute bytecode.</p><p>“.class” file will be read line by line and the data which are stored in different parts of the memory area will be used in the execution process.</p><p>Execution engine also consist with three major components, namely</p><ol><li>Interpreter</li><li>Just-In-Time Compiler (JIT)</li><li>Garbage Collector</li></ol><h4><strong>Interpreter</strong></h4><p>Interpreter will read the byte code (line by line) and it will be converted into the machine code.</p><p>If a single method gets called multiple times then, it is required to go through the interpretation process each time.</p><p>Time taken to complete the execution process of an entire code will take some time.</p><p>These issue were resolved by the Just-In-Time-Compiler.</p><h4><strong>Just-In-Time-Compiler (JIT)</strong></h4><p>Main purpose of this component is to improve the efficiency within the interpreter.</p><p>Re-interpretation is not required when a certain method gets called multiple times.</p><h4><strong>Garbage Collector</strong></h4><p>Garbage collector will destroy unreferenced/unused objects in the memory. This is an automated mechanism.</p><p>In Languages such as C and C++ this process is done through inbuilt methods, through a manual calling process but in Java this process is automated.</p><p>This mechanism provides many advantages; through this process it doesn’t let unused objects be stored in the memory for a long time.</p><p>Crashing of the development environment due to memory shortage will be managed by destroying unused objects.</p><p>Memory efficient and automated are the core benefits of garbage collectors, the process of ensuring memory efficiency is complex, which will be discussed in a future article.</p><blockquote>Hope you got a clear and better understanding regarding the core fundamental aspects of java. Hope to see you again in a future article, Thank you for reading !</blockquote><p>Here I have included the sources which I have referred.</p><p><a href="https://www.youtube.com/watch?v=bUtIIWbaFKc">What is JVM — Java Virtual Machine — YouTube</a></p><p><a href="https://www.geeksforgeeks.org/jvm-works-jvm-architecture/">How JVM Works — JVM Architecture? — GeeksforGeeks</a></p><p><a href="https://www.freecodecamp.org/news/jvm-tutorial-java-virtual-machine-architecture-explained-for-beginners/">JVM Tutorial — Java Virtual Machine Architecture Explained for Beginners (freecodecamp.org)</a></p><p><a href="https://www.geeksforgeeks.org/garbage-collection-java/">Garbage Collection in Java — GeeksforGeeks</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce67c1be81f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>