Introduction

Computer programming is the process of creating a set of instructions that a computer can understand and follow to perform specific tasks.

Popular languages include Python, JavaScript, Java, C++, C#, and C, each suited for different purposes. This documentation compares these languages side-by-side to highlight similarities and differences.

Why is it important?
  • Problem-Solving and Automation - Programming allows us to create solutions that make tasks faster, easier, and more accurate. It can automate repetitive work, process large amounts of data, and solve complex problems that would be difficult for humans to handle manually.
  • Innovation and Technology Development - Almost every modern technology, from smartphones and medical equipment to social media platforms and artificial intelligence, relies on programming. It drives innovation, making it possible to build new tools, applications, and systems that improve daily life.
  • Career and Economic Growth - Programming skills are highly valuable in today’s job market. They open opportunities in fields like software development, data science, cybersecurity, and engineering. On a larger scale, programming supports industries and economies by enabling digital transformation and technological advancement.
Programming Languages Overview
  • Python: Interpreted, beginner-friendly, widely used in AI, data science, web apps.
  • JavaScript: Language of the web, used for interactive websites and Node.js apps.
  • Java: Statically typed, cross-platform, used in enterprise, Android, and backend systems.
  • C++: Extension of C with OOP, popular for performance-heavy applications.
  • C#: Microsoft language, used in Windows apps, Unity game development, and enterprise solutions.
  • C: Low-level, powerful, often used for OS development and embedded systems.
Hello World

The "Hello World" program is traditionally the first program that beginners write when learning a new programming language. It's a simple program that displays the text "Hello, World!" on the screen.

This seemingly simple task teaches you the basic structure of a program in each language - how to write code that the computer can understand and execute. While the goal is the same across all languages, you'll notice that each language has its own way of accomplishing this task.

Key concepts: Output/printing, basic program structure, syntax differences

# Print text to the console
print("Hello, World!")
// Print text to the browser console (press F12 β†’ Console)
console.log("Hello, World!");
// Main class definition
public class HelloWorld {
    // Entry point of the program
    public static void main(String[] args) {
        System.out.println("Hello, World!"); // Print to console
    }
}
#include <iostream>            // Include IO library for cout
using namespace std;            // Use standard namespace (for brevity)

int main() {
    cout << "Hello, World!" << endl; // Print to console
    return 0;                           // Exit program
}
using System;                   // Import base .NET namespace

class HelloWorld {
    static void Main() {
        Console.WriteLine("Hello, World!"); // Print to console
    }
}
#include <stdio.h>              // Include standard I/O header

int main() {
    printf("Hello, World!\n");  // Print to console
    return 0;                   // Exit program
}
Variables and Data Types

Variables are like containers that store data values. Think of them as labeled boxes where you can put different types of information. The "name" of the variable is how you refer to that box later in your code.

Common data types include:

  • Integers: Whole numbers like 5, 10, -3
  • Floats/Doubles: Decimal numbers like 3.14, 2.5
  • Strings: Text like "Hello", "Alice"
  • Booleans: True or False values

Some languages require you to specify what type of data a variable will hold (static typing), while others figure it out automatically (dynamic typing).

Key concepts: Variable declaration, data types, static vs dynamic typing

# Integer, float, string, and boolean variables
x = 10            # int
y = 3.14          # float
name = "John"    # str
is_student = True # bool
// Variables in JavaScript (block-scoped with let)
let x = 10;           // number
let y = 3.14;         // number
let name = "John";   // string
let is_student = true;// boolean
// Variables in Java (static types required)
int x = 10;           // 32-bit integer
double y = 3.14;      // 64-bit floating point
String name = "John";// sequence of characters
boolean isStudent = true; // boolean value
// Variables in C++ (static, strongly typed)
int x = 10;           // integer
double y = 3.14;      // double-precision float
std::string name = "John"; // string (requires <string>)
bool isStudent = true;      // boolean value
// Variables in C# (static, strongly typed)
int x = 10;           // integer
double y = 3.14;      // double-precision float
string name = "John";// string (alias for System.String)
bool isStudent = true;// boolean value
// Variables in C (manual memory model)
int x = 10;           // integer
double y = 3.14;      // double-precision float
char name[] = "John";// C-style string (array of chars)
int isStudent = 1;    // C uses 1 for true, 0 for false
Loops

Loops are one of the most powerful features in programming. They allow you to repeat a block of code multiple times without having to write it over and over again.

Imagine you want to print numbers from 0 to 4. Without loops, you'd have to write five separate print statements. With a loop, you write the print statement once and tell the computer to repeat it 5 times.

Common types of loops:

  • For loops: Repeat a specific number of times
  • While loops: Repeat as long as a condition is true
  • Do-while loops: Like while loops, but run at least once

Key concepts: Iteration, loop counters, avoiding infinite loops

# For loop from 0 to 4
for i in range(5):
    print(f"For loop: {i}")

# While loop example
count = 0
while count < 3:
    print(f"While loop: {count}")
    count += 1

# Python doesn't have do-while, but we can simulate it
x = 0
while True:
    print(f"Do-while simulation: {x}")
    x += 1
    if x >= 3:
        break
// For loop from 0 to 4
for (let i = 0; i < 5; i++) {
  console.log("For loop: " + i);
}

// While loop example
let count = 0;
while (count < 3) {
  console.log("While loop: " + count);
  count++;
}

// Do-while loop example
let x = 0;
do {
  console.log("Do-while loop: " + x);
  x++;
} while (x < 3);
// For loop from 0 to 4
for (int i = 0; i < 5; i++) {
  System.out.println("For loop: " + i);
}

// While loop example
int count = 0;
while (count < 3) {
  System.out.println("While loop: " + count);
  count++;
}

// Do-while loop example
int x = 0;
do {
  System.out.println("Do-while loop: " + x);
  x++;
} while (x < 3);
// For loop from 0 to 4
for (int i = 0; i < 5; i++) {
  std::cout << "For loop: " << i << std::endl;
}

// While loop example
int count = 0;
while (count < 3) {
  std::cout << "While loop: " << count << std::endl;
  count++;
}

// Do-while loop example
int x = 0;
do {
  std::cout << "Do-while loop: " << x << std::endl;
  x++;
} while (x < 3);
// For loop from 0 to 4
for (int i = 0; i < 5; i++) {
  Console.WriteLine("For loop: " + i);
}

// While loop example
int count = 0;
while (count < 3) {
  Console.WriteLine("While loop: " + count);
  count++;
}

// Do-while loop example
int x = 0;
do {
  Console.WriteLine("Do-while loop: " + x);
  x++;
} while (x < 3);
// For loop from 0 to 4
for (int i = 0; i < 5; i++) {
  printf("For loop: %d\n", i);
}

// While loop example
int count = 0;
while (count < 3) {
  printf("While loop: %d\n", count);
  count++;
}

// Do-while loop example
int x = 0;
do {
  printf("Do-while loop: %d\n", x);
  x++;
} while (x < 3);
Functions

Functions are reusable blocks of code that perform specific tasks. Think of them as mini-programs within your main program. You give a function some input (called parameters), it does something with that input, and gives you back a result (called a return value).

Why use functions?

  • Avoid repetition: Write code once, use it many times
  • Organization: Break complex problems into smaller, manageable pieces
  • Testing: Easier to test small functions than entire programs
  • Collaboration: Different team members can work on different functions

For example, instead of writing the same greeting code multiple times for different people, you create a "greet" function that takes a name as input and returns a personalized greeting.

Key concepts: Function definition, parameters, return values, function calls

# Define a function and call it
def greet(name):                 # Function with one parameter
    return "Hello, " + name      # Return a greeting string

print(greet("John"))            # Prints: Hello, Alice
// Define a function and call it
function greet(name) {           // Function declaration
  return "Hello, " + name;       // Return a string
}
console.log(greet("John"));     // Logs: Hello, Alice
// Define a static method inside a class and call it
public class Main {
  static String greet(String name) {      // Method returns a String
    return "Hello, " + name;
  }
  public static void main(String[] args) { // Program entry point
    System.out.println(greet("John"));
  }
}
// Define a function and call it
#include <iostream>
#include <string>

std::string greet(const std::string& name) { // Pass by const reference
  return "Hello, " + name;
}
int main() {
  std::cout << greet("John") << std::endl;
  return 0;
}
// Define a method inside a class and call it
using System;

class Program {
  static string Greet(string name) {   // Returns a string
    return "Hello, " + name;
  }
  static void Main() {                 // Entry point
    Console.WriteLine(Greet("John"));
  }
}
// Define a function and call it (C-style strings)
#include <stdio.h>     // printf
#include <string.h>    // sprintf

char* greet(const char* name) {
  static char result[64];             // Static buffer for simplicity
  sprintf(result, "Hello, %s", name); // Format into buffer
  return result;
}
int main() {
  printf("%s\n", greet("John"));
  return 0;
}
Classes and Objects

Classes and objects are fundamental concepts in Object-Oriented Programming (OOP). Think of a class as a blueprint or template, and objects as things built from that blueprint.

Real-world analogy: If you have a blueprint for a house (class), you can build multiple houses (objects) from that same blueprint. Each house will have the same structure but can have different details (like paint color, furniture).

Key components:

  • Properties/Fields: Data that objects store (like a person's name, age)
  • Methods: Actions that objects can perform (like a person saying hello)
  • Constructor: Special method that sets up a new object when it's created

In our example, we create a "Person" class that can store a name and has a method to greet others. Each person object will have their own name but use the same greeting method.

Key concepts: Classes, objects, constructors, methods, encapsulation

# Define a class and create an object
class Person:
    def __init__(self, name):        # Constructor
        self.name = name
    def greet(self):                  # Instance method
        print("Hello, " + self.name)

p = Person("John")                   # Create instance
p.greet()                             # Call method
// Define a class and create an object
class Person {
  constructor(name) {     // Constructor
    this.name = name;
  }
  greet() {               // Method
    console.log("Hello, " + this.name);
  }
}
const p = new Person("John"); // Create instance
p.greet();                     // Call method
// Define a class and create an object
class Person {
  private String name;                 // Field
  Person(String name) { this.name = name; }  // Constructor
  void greet() {                       // Instance method
    System.out.println("Hello, " + name);
  }
}
public class Main {
  public static void main(String[] args) {
    Person p = new Person("John");    // Create instance
    p.greet();                         // Call method
  }
}
// Define a class and create an object
#include <iostream>
#include <string>

class Person {
  std::string name;                    // Private member
public:
  explicit Person(std::string n) : name(std::move(n)) {} // Constructor
  void greet() const { std::cout << "Hello, " << name << std::endl; }
};
int main() {
  Person p("John");                   // Create instance
  p.greet();                           // Call method
  return 0;
}
// Define a class and create an object
using System;

class Person {
  private string name;                 // Field
  public Person(string name) {         // Constructor
    this.name = name;
  }
  public void Greet() {                // Instance method
    Console.WriteLine("Hello, " + name);
  }
}
class Program {
  static void Main() {
    var p = new Person("John");       // Create instance
    p.Greet();                         // Call method
  }
}
// Simulating objects with structs + functions in C
#include <stdio.h>
#include <string.h>

struct Person {
  char name[50];                       // "Field"
};

void greet(struct Person* p) {         // "Method" taking a pointer
  printf("Hello, %s\n", p->name);
}

int main() {
  struct Person p;                     // "Instance"
  strcpy(p.name, "John");             // Set field
  greet(&p);                           // Call "method"
  return 0;
}