<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ali ELKAROUAOUI</title>
    <description>The latest articles on Forem by Ali ELKAROUAOUI (@vimex).</description>
    <link>https://forem.com/vimex</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1580364%2F80ef23e3-b013-49ee-8ebe-3ca4d5d3b4a4.jpg</url>
      <title>Forem: Ali ELKAROUAOUI</title>
      <link>https://forem.com/vimex</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/vimex"/>
    <language>en</language>
    <item>
      <title>How the JVM Works?</title>
      <dc:creator>Ali ELKAROUAOUI</dc:creator>
      <pubDate>Wed, 17 Sep 2025 20:52:40 +0000</pubDate>
      <link>https://forem.com/vimex/how-the-jvm-works-43d0</link>
      <guid>https://forem.com/vimex/how-the-jvm-works-43d0</guid>
      <description>&lt;h1&gt;
  
  
  How the JVM Works: The Magic Behind Java 🧙‍♂️☕️
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://nextlevelcoding.vercel.app/" rel="noopener noreferrer"&gt;https://nextlevelcoding.vercel.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Java is famous for its mantra: &lt;em&gt;“Write once, run anywhere.”&lt;/em&gt; But how does the same Java program run on Windows, Linux, or macOS without changing a single line of code? The secret is the &lt;strong&gt;JVM&lt;/strong&gt;—the Java Virtual Machine. Let’s peek behind the curtain and see how it works!  &lt;/p&gt;




&lt;h2&gt;
  
  
  Step 1: From Java Code to Bytecode 📜➡️💻
&lt;/h2&gt;

&lt;p&gt;When you write a Java program, you create &lt;strong&gt;source code&lt;/strong&gt; (&lt;code&gt;.java&lt;/code&gt; files). But your computer doesn’t understand Java directly.  &lt;/p&gt;

&lt;p&gt;Here’s the journey:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Compilation&lt;/strong&gt;: The Java compiler (&lt;code&gt;javac&lt;/code&gt;) translates your source code into &lt;strong&gt;bytecode&lt;/strong&gt; (&lt;code&gt;.class&lt;/code&gt; files).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bytecode&lt;/strong&gt;: A platform-independent, intermediate language. Think of it as a recipe written in “Java language for computers,” understandable by any JVM.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Bytecode is the key to Java’s &lt;em&gt;write once, run anywhere&lt;/em&gt; magic!&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 2: Enter the JVM 🏰
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;JVM&lt;/strong&gt; is like a mini-computer inside your real computer. Its job: execute Java bytecode.  &lt;/p&gt;

&lt;p&gt;The JVM has a few main components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Class Loader&lt;/strong&gt;: Loads &lt;code&gt;.class&lt;/code&gt; files into memory.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bytecode Verifier&lt;/strong&gt;: Checks your bytecode for security and correctness.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interpreter &amp;amp; Just-In-Time (JIT) Compiler&lt;/strong&gt;: Executes bytecode. More on this below!
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memory Areas&lt;/strong&gt;: Stack, Heap, Method Area, and more for storing data and managing program execution.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step 3: Memory Management 🧠
&lt;/h2&gt;

&lt;p&gt;The JVM organizes memory into several regions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Heap&lt;/strong&gt;: Stores Java objects and class instances. Garbage collected automatically.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stack&lt;/strong&gt;: Stores method calls, local variables, and frames. Follows LIFO.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Method Area&lt;/strong&gt;: Stores class-level information (methods, constants).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PC Register &amp;amp; Native Method Stack&lt;/strong&gt;: Helps the JVM keep track of executing instructions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of the JVM’s memory like a multi-level kitchen: ingredients (objects) in the fridge (heap), chef’s tools (local variables) on the counter (stack), and recipe books (methods) on the shelf (method area).  &lt;/p&gt;




&lt;h2&gt;
  
  
  Step 4: Execution – Interpreter + JIT ⚡
&lt;/h2&gt;

&lt;p&gt;When the JVM runs bytecode, it can do it in two ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Interpreter&lt;/strong&gt;: Reads and executes bytecode line by line. Simple but slower.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JIT Compiler&lt;/strong&gt;: Converts frequently executed bytecode into native machine code for speed. Think of it as a smart chef who memorizes favorite recipes to cook faster next time.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This combination makes Java programs safe, portable, and surprisingly fast.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 5: Garbage Collection 🧹
&lt;/h2&gt;

&lt;p&gt;You don’t need to manually free memory in Java. The &lt;strong&gt;Garbage Collector (GC)&lt;/strong&gt; automatically finds objects that are no longer used and removes them, keeping the heap tidy.  &lt;/p&gt;

&lt;p&gt;Analogy: The JVM is a chef who cleans the kitchen automatically after cooking—no dishes left behind!&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion: Why JVM Matters 🚀
&lt;/h2&gt;

&lt;p&gt;Here’s the JVM journey in a nutshell:  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Java Code → Bytecode → JVM → Execution (Interpreter/JIT) → Memory &amp;amp; GC → Output&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;Thanks to the JVM, Java programs can run safely and efficiently on any platform. Next time you run a Java app, imagine this little virtual machine orchestrating everything behind the scenes!  &lt;/p&gt;




&lt;h3&gt;
  
  
  Fun Fact
&lt;/h3&gt;

&lt;p&gt;Some JVMs, like &lt;strong&gt;HotSpot&lt;/strong&gt;, optimize code as it runs. This means your Java program can actually &lt;strong&gt;speed up the longer it runs&lt;/strong&gt;—magic meets engineering! ✨&lt;/p&gt;

&lt;p&gt;&lt;a href="https://nextlevelcoding.vercel.app/" rel="noopener noreferrer"&gt;https://nextlevelcoding.vercel.app/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>bytecode</category>
      <category>jvm</category>
      <category>interpreted</category>
    </item>
    <item>
      <title>What happens when you run a program?</title>
      <dc:creator>Ali ELKAROUAOUI</dc:creator>
      <pubDate>Mon, 15 Sep 2025 15:59:51 +0000</pubDate>
      <link>https://forem.com/vimex/what-happens-when-you-run-a-program-4dbn</link>
      <guid>https://forem.com/vimex/what-happens-when-you-run-a-program-4dbn</guid>
      <description>&lt;h1&gt;
  
  
  What Happens When You Run a Program? 🖥️✨
&lt;/h1&gt;

&lt;p&gt;Here is my official blog website: &lt;a href="https://nextlevelcoding.vercel.app/blog/code-execution" rel="noopener noreferrer"&gt;https://nextlevelcoding.vercel.app/blog/code-execution&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ever double-click an app or type &lt;code&gt;python myscript.py&lt;/code&gt; and wonder: &lt;em&gt;“What’s actually happening inside my computer?”&lt;/em&gt; Behind the scenes, your program embarks on a tiny adventure! Let’s follow its journey, step by step.  &lt;/p&gt;




&lt;h2&gt;
  
  
  Step 1: From Code to Machine 📝➡️💻
&lt;/h2&gt;

&lt;p&gt;Your code starts as plain text—human-readable instructions. But your computer only understands &lt;strong&gt;machine language&lt;/strong&gt;, a series of 1s and 0s.  &lt;/p&gt;

&lt;p&gt;Here’s where &lt;strong&gt;compilers&lt;/strong&gt; and &lt;strong&gt;interpreters&lt;/strong&gt; come in:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Compiler&lt;/strong&gt; (C, C++): Translates your entire program into machine code before running it.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interpreter&lt;/strong&gt; (Python, JavaScript): Translates line by line as the program runs.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of it like translating a recipe: a compiler gives the chef a fully translated cookbook upfront, while an interpreter translates each step on the fly.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 2: Loading into Memory 🧠
&lt;/h2&gt;

&lt;p&gt;Once translated, your program is loaded into &lt;strong&gt;RAM&lt;/strong&gt;, the computer’s temporary workspace. But not all memory is equal:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stack&lt;/strong&gt;: Like a stack of plates, last-in, first-out (LIFO). Stores function calls and local variables.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Heap&lt;/strong&gt;: A messy drawer where you can request and free space anytime. Used for dynamic memory (objects, big arrays, etc.).
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your program organizes its workspace here, so the CPU knows where to find everything.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 3: CPU Executes Instructions ⚡
&lt;/h2&gt;

&lt;p&gt;Now the &lt;strong&gt;CPU&lt;/strong&gt; (the brain of your computer) takes over. It follows the &lt;strong&gt;fetch-decode-execute cycle&lt;/strong&gt;:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Fetch&lt;/strong&gt;: Grab the next instruction from memory.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decode&lt;/strong&gt;: Figure out what it means.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Execute&lt;/strong&gt;: Do it.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Imagine a chef following a recipe step by step—grabbing ingredients (fetch), reading the instructions (decode), and cooking (execute). That’s exactly what your CPU does… billions of times per second!  &lt;/p&gt;




&lt;h2&gt;
  
  
  Step 4: Interacting with the OS 🍽️
&lt;/h2&gt;

&lt;p&gt;Programs don’t work alone—they need the &lt;strong&gt;operating system&lt;/strong&gt;. Want to print something, open a file, or access the internet? That’s a &lt;strong&gt;system call&lt;/strong&gt;:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Think of your program as a customer, the OS as a waiter, and the hardware as the kitchen. Your requests (system calls) go through the waiter (OS) to get the job done.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step 5: Program Ends &amp;amp; Cleanup 🧹
&lt;/h2&gt;

&lt;p&gt;When your program finishes, it cleans up after itself:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;stack&lt;/strong&gt; is cleared automatically.
&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;heap&lt;/strong&gt; should be freed manually (or by garbage collection in languages like Python/Java).
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This keeps memory tidy, so the computer stays fast and healthy.&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion: The Journey in a Nutshell 🚀
&lt;/h2&gt;

&lt;p&gt;Let’s recap the adventure:  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code → Compiler/Interpreter → Memory → CPU → OS → Output&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;Next time you run a program, imagine the tiny journey it’s taking inside your computer—a whirlwind of translation, memory juggling, and instruction execution, all happening faster than the blink of an eye!  &lt;/p&gt;




&lt;h3&gt;
  
  
  Fun Fact
&lt;/h3&gt;

&lt;p&gt;The CPU can execute &lt;strong&gt;billions of instructions per second&lt;/strong&gt;, yet we still wait a few milliseconds for our apps to open. Computers are fast, but the real magic is in the orchestration!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://nextlevelcoding.vercel.app" rel="noopener noreferrer"&gt;https://nextlevelcoding.vercel.app&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>computerscience</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
