This content originally appeared on DEV Community and was authored by Farhan Shahriar
When I first started learning to code, I wondered: How does my computer know what to do when I write some text and click βRunβ?
In this first lesson, Iβll share what I learned β and trust me, understanding this makes you appreciate programming so much more!
Letβs Compare It To Something You Know
Imagine you want to watch a video on your computer. You need video player software β like VLC or Windows Media Player.Or, you want to play a game β you first install the game on your machine.
Running code is very similar.
When you write code, your computer needs a special program that knows how to understand and execute it.For example:
To run C++, you need a compiler like GCC.
To run Java, you need the Java Development Kit (JDK) installed.
If you run your code online, you use an online IDE (like Replit or CodeSandbox). Your code runs on another computer (a server) somewhere in the world. Still, it always needs a machine to run.
What Happens When You Run Code?
Letβs take a simple C++ example:
#include <iostream>
using namespace std;
int main() {
// Your code goes here
cout << "Hi...";
return 0;
}
When you hit Run, your computer does this in two main steps:
1⃣ Compilation Phase
It checks your code line by line.
It finds any errors β like typos or wrong syntax.
2⃣ Execution Phase
It looks for the entry point β in C++ thatβs int main().
Then, it starts running your instructions step by step.
Hereβs a quick Java example too:
import java.util.*;
import java.lang.*;
import java.io.*;
class FirstCode {
public static void main(String[] args) throws java.lang.Exception {
// Your code goes here
}
}
Again, Java finds the main method and starts executing your logic from there.
So Much Happens Behind the Scenes!
Behind that Run button, there are thousands of lines of code written by other developers β the compiler, the interpreter, the virtual machine. All of this software does the hard work of translating your code into instructions your computer can understand.
If it wasnβt for these tools, weβd have to write those low-level instructions ourselves. Thankfully, people already did that work and packaged it for us!
Does Every Language Run the Same Way?
Most programming languages follow a similar flow:
Check for errors
Find the starting point
Execute the code step by step
The exact details depend on the language (some are compiled, some are interpreted, some use virtual machines). But the big idea stays the same: You write instructions β A special program understands them β Your computer does the work
Key Takeaway
Whenever you write code, youβre actually giving instructions to a machine. The compiler or interpreter is your translator β it converts your words into something the computerβs hardware understands.
So next time you click Run, appreciate the invisible magic happening behind your screen!
Final Thoughts
Understanding how code runs is the first step to becoming a confident programmer.I hope this helped you β follow my journey as I share more beginner-friendly lessons!
This content originally appeared on DEV Community and was authored by Farhan Shahriar