Before we learn recursion, we need a clear picture of what really happens when a program runs. A program does not just "work" by magic. It travels through several stages — from the words you type to actual actions happening inside the computer. Once you understand this journey, recursion will make much more sense later.
Let's follow a program through its whole life, step by step.
Everything starts with source code. This is the set of instructions a programmer writes in a high-level language like C++, Java, or Python.
if, while, and int.Think of source code like a recipe written in English. A human cook can read it easily. But there is a problem: the computer's brain, the CPU, does not understand English. The CPU only understands very simple binary operations — basically patterns of 0s and 1s.
So the recipe written in human language must be translated into the CPU's own language. That need for translation leads us to the next stage.
Translating source code into machine-readable code happens in one of two main ways: compilation or interpretation (and sometimes a mix of both).
Compiled languages (like C, C++, and sometimes Java):
Interpreted languages (like Python and JavaScript):
Either way, the goal is exactly the same: turn human-readable instructions into a form the computer can actually run.
When you run a program, the operating system (OS) turns that code into a running process. A process is simply a program that is actively being executed, with its own space in memory. How the OS does this depends on the language type:
python for a script.py file, or node for a script.js file. The interpreter then reads, translates, and runs your code line by line, all inside its own process.In every case, when execution begins, the OS does three things:
This is where the program finally comes to life. The CPU keeps repeating one core loop called the Fetch-Decode-Execute Cycle:
Then it repeats, again and again, for every instruction in the program.
During this cycle, parts inside the CPU do the real work:
While running, the CPU constantly talks to memory and to input/output devices (keyboard, screen, files, and so on). This stage is what turns those still, silent instructions sitting in memory into real, visible actions on your computer.
Java sits in the middle of these two worlds:
A program's performance — how fast and smoothly it runs — depends on two things:
Optimised code reduces unnecessary operations and makes better use of the CPU's resources. Keeping this big picture in mind — source code, translation, process, and the Fetch-Decode-Execute cycle — is the foundation we will build on when we study recursion next.