<?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 Harshana Jayasinghe on Medium]]></title>
        <description><![CDATA[Stories by Harshana Jayasinghe on Medium]]></description>
        <link>https://medium.com/@harshanajay?source=rss-0f4fb3c527da------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*p3vIGeBg4W3hBurp</url>
            <title>Stories by Harshana Jayasinghe on Medium</title>
            <link>https://medium.com/@harshanajay?source=rss-0f4fb3c527da------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 03:51:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@harshanajay/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[How JVM Makes Your Java Code Faster While You Sleep]]></title>
            <link>https://medium.com/@harshanajay/how-jvm-makes-your-java-code-faster-while-you-sleep-3e86e7975f24?source=rss-0f4fb3c527da------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e86e7975f24</guid>
            <dc:creator><![CDATA[Harshana Jayasinghe]]></dc:creator>
            <pubDate>Tue, 30 Dec 2025 15:53:49 GMT</pubDate>
            <atom:updated>2025-12-30T15:53:49.771Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*ZCpTFa_HPxf6eNXnBNOWWQ.png" /></figure><p>As a java learner, I have wondered : “Why does everyone says that Java is fast when if feels so complex?”</p><p>Then I learned that secret lies behind something amazing happening behind the scenes.</p><p>When we learn Java, We write the code, compile it with “javac”, and run it with “java”. But here’s the fascinating part: your isn’t running the code you wrote. It’s running something completely different — and much faster. In this article let me show you how this incredible transformation happens automatically.</p><h3>The Journey Your Code Takes</h3><p>Let’s start with the basics, Let’s go step by step. When you write java code &amp; compile it, something interesting happens that makes java different from languages like C++ or Python.</p><p><strong>Step 1: From Your Code to Bytecode</strong></p><p>When you run “javac Example.java” , the compiler doesn’t create machine code (the 1s and 0s your processor understands). Instead, it creates something called bytecode — an intermediate code that sits between your human-readable code and machine code.</p><p>We can think of bytecode as a universal language that any JVM(Java Virtual Machine) can understand, regardless of your OS. This bytecode is platform-independent, meaning it can run on any system that has a JVM installed.</p><p><strong>Step 2: The JVM’s Secret Weapon — Just-In-Time Compilation</strong></p><p>Now here’s where the magic begins. When the JVM runs your bytecode, it doesn’t just interpret it line by line forever. Instead, it watches your code, study it, run and makes an intelligent decisions like : “This piece of code is being used a lot. Let me make it super fast.”</p><p>The JIT compiler comes into action whenever a Java method is called frequently, compiling the bytecode of that method into native machine code. This means your code literally gets faster the more it runs!</p><h3>How JVM Learns About Your Code</h3><p>Think of the JVM as an extremely intelligent investigator that keeps an eye on everything your program does. The JVM spends time closely observing the code as it runs, determining which sections are frequently executed and how it is run.</p><p>It is searching for the following:</p><p>Hotspots: These hot spots, or sections of the code that are frequently executed, are identified by the JVM and sent to the JIT compiler for optimization. Consider this: if you continue to travel the same path to work each day, you will eventually discover the quickest route. Your code is treated in the same way by the JVM.</p><p>Method Behavior: The JVM notices patterns. If you have a method like this:</p><pre>public int add(int a ,int b){<br>   return a + b;//Simple method called thousands of times<br> }</pre><p>After seeing this method called thousands of times, the JVM thinks: “This is simple and used constantly. Instead of going through the overhead of method calls, let me just paste this code directly where it’s needed.”</p><h3>The Two-Stage Performance Boost</h3><p>The JVM uses a clever two-stage approach that balances quick startup with maximum performance:</p><p>Stage 1: The Quick Start (C1 Compiler)</p><p>When your program first starts, the JVM needs to get you running quickly. For that the JVM uses a compiler that provides basic optimizations without consuming too many resources. It performs simple optimizations like removing unnecessary code and combining constant values</p><p>Stage 2: The Performance Breakthrough (C2 Compiler)</p><p>After your code has run for a while and the JVM has collected enough data, it starts to unleash the heavy-duty optimizations. This is where your code get more optimized and become dramatically faster — sometimes 10 times faster or more!</p><h3>Method Inlning : The Ultimate Speed Trick</h3><p>Let me explain one of the most powerful optimizations with a simple example. The JIT compiler optimizes code by inlining frequently called methods, which means embedding the method code directly into the calling code to reduce method call overhead.</p><p>Consider the code below :</p><pre> public class Calculator {<br><br>    // A simple method that gets called in a loop<br>    public int multiply(int x, int y) {<br>        return x * y;<br>    }<br><br>    public void processNumbers() {<br>        int total = 0;<br>        for (int i = 0; i &lt; 1000000; i++) {<br>            total += multiply(i, 2);  // Method call in hot loop<br>        }<br>        System.out.println(total);<br>    }<br>}</pre><p>After watching this code run, the JVM realizes that the method multiply is called a million times in a loop. It transforms your code into something like this:</p><pre>public class Calculator {<br><br>    public void processNumbers() {<br>        int total = 0;<br>        for (int i = 0; i &lt; 1000000; i++) {<br>            total += i * 2;    // Method call eliminated!<br>        }<br>        System.out.println(total);<br>    }<br>}</pre><p>The method call overhead completely disappears! This happens automatically without you changing a single line of code.</p><h3>Understanding the Warm-Up Effect</h3><p>Often, there is a delay known as the “warm-up time” or “startup time delay” because the more optimization the JIT does, the better the code it produces, but this also lengthens the initial delay.</p><p>This explains why Java apps frequently have slower initial speeds before becoming lightning-fast. It’s comparable to a sports car that requires a brief engine warm-up period before reaching its maximum speed.</p><p>This implies the following for a learning developer :</p><ul><li>Don’t judge Java’s performance by how your small test programs run.</li><li>This warm-up time is very beneficial in production applications.</li><li>The longer your application runs, the faster it becomes.</li></ul><h3>Polymorphism Optimization: When the JVM Gets Really Clever</h3><p>Here’s something that might surprise you. You know how interface calls are supposed to be slower because the JVM needs to figure out which implementation to call? The JVM checks the number of different implementations: monomorphic (one implementation) and bimorphic (two implementations) can get in lined, whereas megamorphic (more than two implementations) typically do not.</p><p>Let’s say you have:</p><pre>interface Animal {<br><br>    void makeSound();<br>}<br><br>// In your main loop, if 99% of animals are dogs:<br>for (Animal animal : animal){<br>     animal.makeSound(); //Looks like expensive interface call<br>} </pre><p>The JVM notices that 99% of the time, animal is actually a Dog , So it optimizes by assuming it’s always a Dog, but keeps a backup plan:</p><pre>// JVM&#39;s optimized version (conceptually):<br>for (Animal animal : animals) {<br><br>  if (animal instanceof Dog) {<br>    // Inlined Dog.makeSound() code here - super fast!<br>    System.out.println(&quot;Woof!&quot;);<br>  } else {<br>    animal.makeSound(); // Fallback for rare cases<br>  }<br>}</pre><h3>The Bottom Line: Your Code is Alive</h3><p>This should excite you as a Java learner because the platform you’re using is actively improving your code rather than just running it. You can see artificial intelligence in action every time you run a Java application, as it analyzes patterns and improves performance in ways that would be impossible for a human programmer to accomplish by hand.</p><p>The JVM doesn’t just execute your bytecode. It studies it, learns from it, and evolves it into something faster and more efficient. Your code is literally alive and improving itself.</p><p>Java is still one of the most effective platforms for creating complex applications because of this. The JVM manages the intricate performance optimizations automatically while you concentrate on learning programming concepts and resolving business issues.</p><p>Continue learning and coding, and never forget that every Java program you create has a group of unseen performance specialists working around-the-clock to improve its speed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e86e7975f24" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Electron.js:]]></title>
            <link>https://medium.com/@harshanajay/getting-started-with-electron-js-36aa04801b17?source=rss-0f4fb3c527da------2</link>
            <guid isPermaLink="false">https://medium.com/p/36aa04801b17</guid>
            <dc:creator><![CDATA[Harshana Jayasinghe]]></dc:creator>
            <pubDate>Thu, 31 Oct 2024 09:58:03 GMT</pubDate>
            <atom:updated>2024-10-31T09:58:03.299Z</atom:updated>
            <content:encoded><![CDATA[<h3>Getting Started with Electron.js: Build Your First Cross-Platform Desktop App only using HTML, CSS and JS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*WsOgxhNw6yPkJNDQoqcQYg.jpeg" /></figure><p>Have you ever wished to create desktop applications only using your web development skills? You can using electron.Js! Electron.Js allows you to create cross platform desktop apps only using familiar web technologies like HTML, CSS, and JavaScript. In this article I will show you how to build a simple desktop application using HTML, CSS, and Js with the help of Electron.</p><h3>Prerequisites</h3><p>Make sure you have the following prerequisites before you begin: a dependable code editor like as Visual Studio Code, Node.js installed on your computer, and a fundamental grasp of HTML, CSS, and JavaScript. Furthermore, although it is not necessary, using the Yarn package manager can make setup easier and is advised for more efficient development.</p><h3>Let’s Build It!</h3><h3>1st Step : Set Up Your Project Using Terminal</h3><p>Create a new folder and set up your project.</p><ul><li>Create and enter a new folder</li></ul><pre>mkdir my-electron-app<br>cd my-electron-app</pre><ul><li>Initialize a new project</li></ul><pre>yarn init -y</pre><p>Because of adding “-y” we are setting a yes flag so that will answer yes to the all the questions that we get when we initializing the project.</p><ul><li>Install Electron</li></ul><pre>yarn add electron --dev</pre><h3>2nd Step : Create Your Files</h3><p>Create these three main files :</p><ol><li>main.js (in the root folder) - This is your app&#39;s main file</li><li>index.html - This is what users will see</li><li>package.json - We&#39;ll update this to run our app</li></ol><h3>3rd Step : Set Up package.json</h3><p>Update your package.json to look like this :</p><pre>{<br>  &quot;name&quot;: &quot;app2&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;main&quot;: &quot;main.js&quot;,<br>  &quot;license&quot;: &quot;MIT&quot;,<br>  &quot;devDependencies&quot;: {<br>    &quot;electron&quot;: &quot;^33.0.2&quot;<br>  },<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;electron .&quot;<br>  }<br>}</pre><h3>4th Step : Create the Main Process</h3><p>In main.js, add this code:</p><pre>const { app, BrowserWindow } = require(&#39;electron&#39;)</pre><pre>// Create the browser window</pre><pre>const createWindow = () =&gt; {<br>  const win = new BrowserWindow({<br>    width: 800,<br>    height: 600<br>  });</pre><pre>// Load your HTML file<br>  win.loadFile(&#39;index.html&#39;);<br>}</pre><pre>// When the app is ready, create the window<br>app.whenReady().then(() =&gt; {<br>  createWindow();<br>});</pre><pre>// Quit the app when all windows are closed<br>app.on(&#39;window-all-closed&#39;, () =&gt; {<br>  if (process.platform !== &#39;darwin&#39;) <br>  app.quit();<br>});</pre><h3>5th Step : Create Your User Interface</h3><p>In index.html, add this code:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;My First Electron App&lt;/title&gt;<br>    &lt;style&gt;<br>        body {<br>            font-family: Arial, sans-serif;<br>            text-align: center;<br>            padding: 20px;<br>            background-color: #f0f2f5;<br>        }<br>        .container {<br>            background-color: white;<br>            padding: 20px;<br>            border-radius: 8px;<br>            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);<br>            max-width: 500px;<br>            margin: 0 auto;<br>        }<br>        button {<br>            background-color: #4299e1;<br>            color: white;<br>            padding: 10px 20px;<br>            border: none;<br>            border-radius: 4px;<br>            cursor: pointer;<br>            font-size: 16px;<br>        }<br>        button:hover {<br>            background-color: #3182ce;<br>        }<br>    &lt;/style&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;div class=&quot;container&quot;&gt;<br>        &lt;h1&gt;Hello Electron! 👋&lt;/h1&gt;<br>        &lt;p&gt;Welcome to your first desktop app!&lt;/p&gt;<br>        &lt;button id=&quot;timeButton&quot;&gt;Show Current Time&lt;/button&gt;<br>        &lt;p id=&quot;timeDisplay&quot;&gt;&lt;/p&gt;<br>    &lt;/div&gt;<br>    &lt;script&gt;<br>        document.getElementById(&#39;timeButton&#39;).addEventListener(&#39;click&#39;, () =&gt; {<br>            const time = new Date().toLocaleTimeString();<br>            document.getElementById(&#39;timeDisplay&#39;).textContent = time;<br>        });<br>    &lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><h3>6th Step : Run Your App</h3><p>Once everything is configured, use the following command in your terminal to launch your application:</p><pre>yarn start</pre><p>That’s it! Your desktop application is currently operational!</p><h3>What Are the Peculiarities of the Application We’ve Just Built?</h3><p>Developing the application, we have successfully created a desktop application that is contained within a single window. It consists of a user interface with a button and a timer to show current time. This application can be used on any operating system, be it Windows, Mac or Linux, making it easy for any user regardless of the Operating System in use.</p><h3>Why Is This Cool?</h3><p>You just finished developing a desktop application by using web technologies that you are already familiar with! There is no need to learn any additional computer language as everything you need is already available — HTML, CSS, and JavaScript. The application can work without issues in other operating systems or in growth, which means that as you will be able to learn more, you will be able to add more aspects into the application.</p><h3>Conclusion</h3><p>Well done! You’ve successfully created your first desktop application based on the web. But remember, this is just the introductory part — Electron.js is capable of so much more with applications varying from basic software to deadline — driven programming applications such as Slack and VS Code. To gain more proficiency, the most appropriate thing to do is to try it out. See if you can implement additional functions, investigate additional Electron modules and adjust the application to fit you best.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36aa04801b17" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build Up an Angular project from the Ground Up]]></title>
            <link>https://medium.com/@harshanajay/build-up-an-angular-project-from-the-ground-up-95a1c9b17dfe?source=rss-0f4fb3c527da------2</link>
            <guid isPermaLink="false">https://medium.com/p/95a1c9b17dfe</guid>
            <dc:creator><![CDATA[Harshana Jayasinghe]]></dc:creator>
            <pubDate>Wed, 30 Oct 2024 06:28:03 GMT</pubDate>
            <atom:updated>2024-10-30T06:28:03.113Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cG1dmP8FyCljewteBl3Yyw.jpeg" /></figure><p>Angular is one of the most popular framework that allows you to develop powerful, scalable web applications. If you are just beginning with Angular and want to start developing your first project from scratch then this article will take you through each necessary steps. In this article you will learn how to set up a new Angular project. So let’s get started!</p><h3>Requirements</h3><p>Before we get stared you have to make sure that you have Node.js is installed in your machine. You can find and install it from the official Node.js website (<a href="https://nodejs.org/">https://nodejs.org</a>). Angular relies on Node.js and npm (Node Package Manager) for handling dependencies and managing the development environment.</p><h3>1st Step : Install the Angular CLI</h3><p>The Angular CLI (Command Line Interface) is a tool that helps us to create and manage angular projects more efficiently. To install Angular CLI first open your CMD ( Terminal in MacOS Devices) and enter following command :</p><pre>npm install -g @angular/cli</pre><p>After the installation is done. You can verify that the Angular CLI is installed successfully by using the following command.</p><pre>ng v</pre><h3>2nd Step : Create a New Project</h3><p>Once you installed Angular CLI then you can create a new Angular project by running the following command in your terminal :</p><pre>ng new your-project-name</pre><p>this command will create a new folder named “your-project-structure” and generate the initial Angular project structure.</p><h3>3rd Step : Navigate to the Project Directory</h3><p>You can enter your newly created project directory by using following command.</p><pre>cd your-project-name</pre><h3>4th Step : Run the Angular Development Server</h3><p>After navigating in to the project directory. Use the following command to run Angular Development Server.</p><pre>ng serve</pre><p>Your project will be compiled and served on a local server. Open a web browser and go to <a href="http://localhost:4200/">http://localhost:4200</a> to view your running Angular application.</p><h3>5th Step : Create a new Component</h3><p>Components are the fundamental building blocks in Angular. You can create a component using the following command:</p><pre>ng generate component component-name</pre><p>This will automatically generate the necessary files for your new component, there a 4 files includes in an Angular component.</p><ul><li>component-name.component.ts: Contains the TypeScript logic for the component.</li><li>component-name.component.html: The HTML template that defines the structure.</li><li>component-name.component.css (or .scss): The component-specific styling file.</li><li>component-name.component.spec.ts: A testing file for unit tests.</li></ul><h3>An Overview and Suggestions</h3><ul><li>You learnt how to start from scratch with an Angular project in this article. From installing the Angular CLI to constructing components, we went over the essential procedures. Here are some last suggestions:</li><li>Learn about the file structure that the Angular CLI creates. It will assist you in effectively planning your project.</li><li>For additional information on the features and capabilities of the framework, visit the official Angular documentation (<a href="https://angular.io/">https://angular.io</a>).</li><li>Participate in forums and discussion groups by joining the Angular community. It’s a fantastic opportunity to share your skills and learn from other devs.</li><li>You are now prepared to begin using Angular to create your own projects! Have fun and never stop learning.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95a1c9b17dfe" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>