Home › CSE Hub › Programming Basics (C, Python, Java)

Programming Basics (C, Python, Java)

Core programming concepts — variables, data types, conditions, loops, functions and OOP — explained side by side in C, Python and Java with simple examples.

हिंदी में: प्रोग्रामिंग की बुनियादी बातें — C, Python और Java में एक साथ, आसान उदाहरणों के साथ।

What is a program?

A program is a set of precise instructions that a computer follows to solve a problem. Before writing code, good programmers first write an algorithm (step-by-step logic) or draw a flowchart, then translate it into a programming language.

Compiled vs interpreted

C Python Java
How it runs Compiled to machine code Interpreted (bytecode run by the Python VM) Compiled to bytecode, run on the JVM
Typing Static Dynamic Static
Memory Manual (malloc/free) Automatic (garbage collection) Automatic (garbage collection)
Paradigm Procedural Multi-paradigm Object-oriented
Best known for Systems, embedded, OS Scripting, data, AI/ML, automation Enterprise, Android, back-end

Hello, World

#include <stdio.h>
int main(void) {
    printf("Hello, World\n");
    return 0;
}
print("Hello, World")
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World");
    }
}

Variables and data types

A variable is a named storage location. Common types:

  • Integer – whole numbers (int in C/Java, int in Python).
  • Floating point – decimals (float, double).
  • Character / String – text (char, String, str).
  • Boolean – true/false (bool in C99 via <stdbool.h>, boolean in Java, bool in Python).

Operators

Arithmetic (+ - * / %), relational (== != < > <= >=), logical (&& || ! in C/Java; and or not in Python), assignment (= += -=) and bitwise (& | ^ ~ << >>).

Note: in C and Java, 7 / 2 with integers gives 3. In Python 3, 7 / 2 gives 3.5 and 7 // 2 gives 3.

Decisions and loops

marks = 72
if marks >= 60:
    print("First division")
elif marks >= 45:
    print("Second division")
else:
    print("Keep practising")

for i in range(1, 6):   # 1 to 5
    print(i * i)
for (int i = 1; i <= 5; i++) {
    printf("%d\n", i * i);
}

Loop types: for, while, do…while (C/Java). Use break to exit a loop and continue to skip to the next iteration.

Functions

Functions break a program into reusable pieces.

static int factorial(int n) {
    return (n <= 1) ? 1 : n * factorial(n - 1);   // recursion
}

Key ideas: parameters and arguments, return values, pass by value (C, Java primitives), recursion (a function calling itself with a base case).

Arrays and strings

An array stores many values of the same type in contiguous memory, accessed by index starting at 0. Strings in C are character arrays ending with '\0'; in Java and Python strings are objects and are immutable.

Pointers (C)

A pointer stores a memory address. int x = 10; int *p = &x; — *p gives 10. Pointers enable dynamic memory, arrays, linked lists and efficient function arguments, but must be used carefully to avoid crashes and memory leaks.

Object-Oriented Programming (OOP)

Pillar Meaning
Encapsulation Keep data and the methods that use it together; hide internal details
Abstraction Expose only what is necessary
Inheritance A class reuses and extends another class
Polymorphism One interface, many forms (method overloading and overriding)
class Student:
    def __init__(self, name, branch):
        self.name = name
        self.branch = branch
    def intro(self):
        return f"{self.name} studies {self.branch}"

print(Student("Asha", "CSE").intro())

Good habits

  • Choose meaningful names and keep functions short.
  • Comment why, not what.
  • Test edge cases (0, negative values, empty input).
  • Use version control (Git) from day one.

Quick revision

  • C: compiled, procedural, manual memory. Python: interpreted, dynamic. Java: JVM bytecode, OOP.
  • Array indexes start at 0.
  • Four OOP pillars: encapsulation, abstraction, inheritance, polymorphism.