CS Fundamentals
Write and understand your first computer program — a step-by-step guide through writing, compiling, and running code for absolute beginners.
Introduction
There is a beautiful tradition in programming: almost everyone's first program does the same thing — it displays the message "Hello, World!" on the screen. This might seem trivially simple, and in a way it is. But writing your first program is a milestone because it proves that your entire development environment is working correctly. You have installed the right software, you know how to write code, you can compile or run it, and you can see the output. Every programmer in history — from the creators of Google to the student reading this — started with this same step.
In this chapter, we will write "Hello, World!" in multiple languages so you can see how different programming languages express the same simple idea. More importantly, we will understand every part of what happens when you run a program, from the moment you type code to the moment output appears on screen.
What You Need Before Writing Code
Before you can write and run a program, you need two things: a text editor (to write the code) and a compiler or interpreter (to translate and execute it).
A text editor is software where you type your code. You could use simple Notepad, but most programmers use specialized code editors like Visual Studio Code (VS Code), Sublime Text, or Atom. These provide helpful features like syntax highlighting (coloring different parts of code for readability), auto-completion (suggesting code as you type), and error detection (highlighting mistakes before you run the code).
A compiler or interpreter translates your human-readable code into instructions the computer can execute. For C language, you need a compiler like GCC. For Python, you need the Python interpreter. For Java, you need the JDK (Java Development Kit). Installing the appropriate tool for your chosen language is the first practical step.
Hello World in C
C is often the first language taught in Indian universities for BCA students. Here is the complete "Hello, World!" program in C:
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}Let us understand every single line. The first line, #include <stdio.h>, is a preprocessor directive that tells the compiler to include the Standard Input/Output library — this library contains the printf function we need. Without this line, the compiler would not know what printf means.
The line int main() defines the main function — this is where every C program begins executing. The word "int" means this function will return an integer value. The parentheses () indicate this is a function that takes no parameters. The curly braces {} contain all the code that belongs to this function.
Inside main, printf("Hello, World!") calls the printf function (print formatted) to display the text between the quotation marks on the screen. The semicolon at the end marks the end of this statement — every statement in C must end with a semicolon.
Finally, return 0 tells the operating system that the program finished successfully (zero traditionally means "no error"). The closing curly brace ends the main function.
Hello World in Python
Python is known for its simplicity. The same program in Python is just one line:
print("Hello, World!")That is it — no includes, no main function, no return statement, no semicolons. Python is designed to minimize the amount of code needed to accomplish tasks. The print function is built-in (no need to import anything), and Python automatically handles program startup and termination.
This simplicity is why Python is increasingly popular for beginners. You can focus on learning programming logic without being distracted by language-specific boilerplate code.
Hello World in Java
Java requires more structure than Python but is widely used in enterprise software:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}In Java, all code must be inside a class (here named HelloWorld). The main method is the entry point — its signature (public static void main(String[] args)) must be exactly this for Java to recognize it as the starting point. System.out.println prints the text followed by a new line.
Compiling and Running Your Program
For compiled languages like C, the process has two steps. First, you compile the source code (the text file you wrote) into an executable file using the compiler. In a terminal, you would type: gcc hello.c -o hello. This creates an executable file. Then you run the executable by typing: ./hello (on Linux/Mac) or hello.exe (on Windows). The output "Hello, World!" appears on screen.
For interpreted languages like Python, there is only one step. Type: python hello.py and the interpreter reads your code, translates it, and executes it all at once. The output appears immediately.
For Java, there is a two-step process of a different kind. First compile: javac HelloWorld.java (creates a .class file containing bytecode). Then run: java HelloWorld (the JVM interprets the bytecode). The output appears.
What Actually Happens Inside
When your "Hello, World!" program runs, here is what happens at a deeper level. The operating system loads your program into RAM. The CPU begins executing instructions from the main function. When it reaches the print/printf statement, it calls an operating system function to write text to the standard output stream (which is connected to your terminal/console). The characters "Hello, World!" are sent to the display. The program reaches its end point and the OS reclaims the memory it used.
This simple program exercises the complete chain: your code → compiler/interpreter → operating system → hardware → display. Understanding this chain helps you debug problems when things go wrong.
Going Beyond Hello World
Once Hello World works, try modifying it. Change the message to your name. Add multiple print statements. Try printing numbers. Experiment with what happens when you make deliberate errors — remove a semicolon in C and see the error message, misspell print in Python and read what Python tells you. Learning to read error messages is one of the most important skills in programming.
Next steps after Hello World typically include: learning variables (storing and manipulating data), learning input (reading data from the user), learning conditional statements (making decisions), and learning loops (repeating actions).
Key Takeaways
- Hello World is every programmer's first milestone — it proves your environment works
- You need a text editor for writing code and a compiler/interpreter for running it
- Different languages express the same logic differently — C requires more boilerplate, Python is minimal
- Compiling translates your code to machine-executable form; interpreting does this on-the-fly
- Understanding what happens behind the scenes helps you debug problems effectively
- After Hello World, practice modifications and deliberately make errors to learn from them
- Every expert programmer started exactly where you are now — this first step leads to everything else
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Your First Program.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Computer Fundamentals topic.
Search Terms
computer-fundamentals, computer fundamentals, computer, fundamentals, programming, first, program, your first program
Related Computer Fundamentals Topics