<?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>DEV Community: Shankar L</title>
    <description>The latest articles on DEV Community by Shankar L (@polyvexr).</description>
    <link>https://dev.to/polyvexr</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3547911%2Fdeada772-6751-4ab6-ab89-af98c11c0e32.jpeg</url>
      <title>DEV Community: Shankar L</title>
      <link>https://dev.to/polyvexr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/polyvexr"/>
    <language>en</language>
    <item>
      <title>How a Computer Actually Runs Your Code</title>
      <dc:creator>Shankar L</dc:creator>
      <pubDate>Sun, 19 Jul 2026 04:30:00 +0000</pubDate>
      <link>https://dev.to/polyvexr/how-a-computer-actually-runs-your-code-3klb</link>
      <guid>https://dev.to/polyvexr/how-a-computer-actually-runs-your-code-3klb</guid>
      <description>&lt;h2&gt;
  
  
  Why should you care?
&lt;/h2&gt;

&lt;p&gt;Every developer writes code every day, but very few understand what actually happens after pressing the &lt;strong&gt;Run&lt;/strong&gt; button.&lt;/p&gt;

&lt;p&gt;Whether you write Java, Python, C++, or JavaScript, your code does not magically execute. It goes through several transformations before the CPU can understand it.&lt;/p&gt;

&lt;p&gt;Understanding this process helps you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write better and more efficient code.&lt;/li&gt;
&lt;li&gt;Debug errors more effectively.&lt;/li&gt;
&lt;li&gt;Learn programming languages faster.&lt;/li&gt;
&lt;li&gt;Understand compilers, interpreters, virtual machines, and operating systems.&lt;/li&gt;
&lt;li&gt;Build a strong foundation for system design, operating systems, and computer architecture.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Programming becomes much easier when you know what is happening behind the scenes.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;Imagine writing the following Java program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello World"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You click &lt;strong&gt;Run&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A second later, your terminal prints:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello World
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But how?&lt;/p&gt;

&lt;p&gt;Your computer only understands electrical signals represented as binary instructions consisting of 0s and 1s.&lt;/p&gt;

&lt;p&gt;It does not understand words like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;cout&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So who translates your code into something the processor can execute?&lt;/p&gt;




&lt;h2&gt;
  
  
  The Concept
&lt;/h2&gt;

&lt;p&gt;Every program follows a pipeline before it reaches the CPU.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Source Code
      ↓
Compiler / Interpreter
      ↓
Machine Instructions
      ↓
Operating System
      ↓
CPU Execution
      ↓
Output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each stage has a specific responsibility.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: You write source code
&lt;/h3&gt;

&lt;p&gt;This is the human readable program.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Humans understand this language.&lt;/p&gt;

&lt;p&gt;Computers do not.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 2: Translation
&lt;/h3&gt;

&lt;p&gt;This stage depends on the programming language.&lt;/p&gt;

&lt;p&gt;Compiled languages like C++ convert the entire program into machine code before execution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C++ Code
      ↓
Compiler
      ↓
Executable (.exe)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Interpreted languages like Python execute the program one statement at a time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Python Code
      ↓
Interpreter
      ↓
Execution
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Languages like Java use a hybrid approach.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Java Code
      ↓
Java Compiler
      ↓
Bytecode
      ↓
JVM
      ↓
Machine Code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 3: Operating System
&lt;/h3&gt;

&lt;p&gt;The operating system loads the program into memory.&lt;/p&gt;

&lt;p&gt;It provides the program with resources such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;RAM&lt;/li&gt;
&lt;li&gt;CPU time&lt;/li&gt;
&lt;li&gt;File access&lt;/li&gt;
&lt;li&gt;Keyboard input&lt;/li&gt;
&lt;li&gt;Display output&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without an operating system, most applications would not know how to communicate with hardware.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 4: CPU Execution
&lt;/h3&gt;

&lt;p&gt;The CPU executes instructions using a continuous cycle.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Fetch
Decode
Execute
Repeat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For every instruction, the processor:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Fetches the next instruction from memory.&lt;/li&gt;
&lt;li&gt;Decodes what the instruction means.&lt;/li&gt;
&lt;li&gt;Executes it.&lt;/li&gt;
&lt;li&gt;Moves to the next instruction.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This cycle repeats billions of times every second.&lt;/p&gt;




&lt;h2&gt;
  
  
  Simple Explanation
&lt;/h2&gt;

&lt;p&gt;Think of programming languages as different spoken languages.&lt;/p&gt;

&lt;p&gt;You may speak English.&lt;/p&gt;

&lt;p&gt;Someone else speaks Japanese.&lt;/p&gt;

&lt;p&gt;The CPU speaks only one language.&lt;/p&gt;

&lt;p&gt;Machine code.&lt;/p&gt;

&lt;p&gt;Every programming language must eventually be translated into machine instructions before execution.&lt;/p&gt;

&lt;p&gt;No exceptions.&lt;/p&gt;




&lt;h2&gt;
  
  
  Real world Analogy
&lt;/h2&gt;

&lt;p&gt;Imagine ordering food at a restaurant.&lt;/p&gt;

&lt;p&gt;You tell the waiter:&lt;/p&gt;

&lt;p&gt;"I want a pizza."&lt;/p&gt;

&lt;p&gt;The waiter writes your order in a format the kitchen understands.&lt;/p&gt;

&lt;p&gt;The chef prepares the pizza.&lt;/p&gt;

&lt;p&gt;The waiter brings it back to you.&lt;/p&gt;

&lt;p&gt;In this analogy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You are the programmer.&lt;/li&gt;
&lt;li&gt;Your source code is your order.&lt;/li&gt;
&lt;li&gt;The compiler or interpreter is the waiter.&lt;/li&gt;
&lt;li&gt;The CPU is the chef.&lt;/li&gt;
&lt;li&gt;The finished dish is the program output.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You never communicate directly with the chef.&lt;/p&gt;

&lt;p&gt;Similarly, your code never communicates directly with the CPU.&lt;/p&gt;

&lt;p&gt;A translator is always involved.&lt;/p&gt;




&lt;h2&gt;
  
  
  Code Example
&lt;/h2&gt;

&lt;p&gt;Consider this simple C program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%d"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The compiler converts this into thousands of machine instructions.&lt;/p&gt;

&lt;p&gt;Conceptually, the CPU performs operations similar to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nasm"&gt;&lt;code&gt;&lt;span class="nf"&gt;LOAD&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="nf"&gt;LOAD&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="nf"&gt;ADD&lt;/span&gt;
&lt;span class="nf"&gt;STORE&lt;/span&gt; &lt;span class="nv"&gt;RESULT&lt;/span&gt;
&lt;span class="nf"&gt;PRINT&lt;/span&gt; &lt;span class="nv"&gt;RESULT&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The actual machine instructions are much more complex, but the idea remains the same.&lt;/p&gt;

&lt;p&gt;Every high level instruction eventually becomes low level CPU instructions.&lt;/p&gt;




&lt;h2&gt;
  
  
  Common Mistakes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Mistake 1
&lt;/h3&gt;

&lt;p&gt;Believing the CPU understands Java, Python, or C++ directly.&lt;/p&gt;

&lt;p&gt;Reality:&lt;/p&gt;

&lt;p&gt;The CPU only understands machine code.&lt;/p&gt;




&lt;h3&gt;
  
  
  Mistake 2
&lt;/h3&gt;

&lt;p&gt;Thinking compiled languages are always faster.&lt;/p&gt;

&lt;p&gt;Reality:&lt;/p&gt;

&lt;p&gt;Performance depends on many factors including compiler optimizations, runtime environment, memory management, and the algorithm itself.&lt;/p&gt;




&lt;h3&gt;
  
  
  Mistake 3
&lt;/h3&gt;

&lt;p&gt;Confusing the compiler with the operating system.&lt;/p&gt;

&lt;p&gt;The compiler translates code.&lt;/p&gt;

&lt;p&gt;The operating system manages resources and executes programs.&lt;/p&gt;

&lt;p&gt;They solve different problems.&lt;/p&gt;




&lt;h3&gt;
  
  
  Mistake 4
&lt;/h3&gt;

&lt;p&gt;Assuming one line of code equals one CPU instruction.&lt;/p&gt;

&lt;p&gt;In reality, one line of source code may become dozens or even hundreds of machine instructions.&lt;/p&gt;




&lt;h2&gt;
  
  
  Advanced Notes
&lt;/h2&gt;

&lt;p&gt;Once you understand the basic pipeline, you can explore what happens internally.&lt;/p&gt;

&lt;h3&gt;
  
  
  Compiler Optimizations
&lt;/h3&gt;

&lt;p&gt;Modern compilers rewrite your program to make it faster without changing its behavior.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dead code elimination&lt;/li&gt;
&lt;li&gt;Function inlining&lt;/li&gt;
&lt;li&gt;Constant folding&lt;/li&gt;
&lt;li&gt;Loop unrolling&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Virtual Machines
&lt;/h3&gt;

&lt;p&gt;Java and C# use virtual machines.&lt;/p&gt;

&lt;p&gt;Instead of producing machine code immediately, they generate intermediate code.&lt;/p&gt;

&lt;p&gt;The virtual machine later converts this into optimized machine instructions during execution.&lt;/p&gt;

&lt;p&gt;This technique is known as Just In Time compilation.&lt;/p&gt;




&lt;h3&gt;
  
  
  CPU Cache
&lt;/h3&gt;

&lt;p&gt;The processor stores frequently used instructions and data in small, high speed memory called cache.&lt;/p&gt;

&lt;p&gt;Accessing cache is much faster than accessing RAM.&lt;/p&gt;

&lt;p&gt;Understanding cache becomes important when optimizing performance.&lt;/p&gt;




&lt;h3&gt;
  
  
  System Calls
&lt;/h3&gt;

&lt;p&gt;Whenever your program reads a file, accesses the internet, or prints text to the terminal, it requests the operating system to perform those tasks through system calls.&lt;/p&gt;

&lt;p&gt;User programs cannot directly control hardware.&lt;/p&gt;




&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Every program follows a journey before producing output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You write code
        ↓
Compiler or Interpreter translates it
        ↓
Operating System loads it
        ↓
CPU executes machine instructions
        ↓
Output appears
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you understand this pipeline, many advanced topics become easier to learn, including operating systems, compilers, computer architecture, memory management, and system design.&lt;/p&gt;

&lt;p&gt;Every programming language may look different on the surface, but underneath they all follow the same fundamental path to reach the CPU.&lt;/p&gt;




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