Learning Objectives

By the end of this chapter, you will be able to:

  • Define a programming language.
  • Differentiate between low-level and high-level programming languages.
  • Describe the generations of programming languages.
  • Understand the role of a compiler and an interpreter.
  • Identify common languages and their typical uses.

What is a Programming Language?

A programming language is a formal language comprising a set of instructions that produce various kinds of output. Programming languages are used in computer programming to implement algorithms.

Most programming languages consist of instructions for computers. There are programmable machines that use a set of specific instructions, rather than general programming languages.

Every language has syntax (the rules for writing statements correctly, like grammar) and semantics (what the statements mean). A program with a syntax error will not run; a program with a logic error runs but gives wrong results.

Low-Level vs. High-Level Languages

Programming languages can be broadly categorized into two types: low-level and high-level.

Low-Level Languages

Low-level languages are closer to the computer’s native machine code and provide little to no abstraction from the hardware.

  • Machine Language: The lowest-level language, consisting of binary code (0s and 1s) that the CPU can directly execute. It is not human-readable.
  • Assembly Language: A step above machine language, assembly uses mnemonics (short, human-readable words) to represent machine-level instructions. It must be converted to machine code by an assembler.

High-Level Languages

High-level languages are closer to human language and provide a high degree of abstraction from the hardware. They are designed to be easy for humans to read, write, and maintain.

  • Characteristics: Use English-like syntax, are easier to learn, and are more portable across different computer architectures.
  • Examples: Python, Java, C++, C#, JavaScript, and Ruby.
flowchart TB
    HL[High-Level Languages<br/>Python, Java, C++]
    ASM[Assembly Language]
    ML[Machine Language<br/>Binary 0s and 1s]
    HL -->|Compiler or Interpreter| ML
    ASM -->|Assembler| ML

Figure 1: Programming Language Levels

The same task at different levels

Adding two numbers:

Level Example code
Machine language 10110000 00000101 (binary instructions)
Assembly language MOV AL, 5 then ADD AL, 3
High-level (Python) total = 5 + 3
Aspect Low-level languages High-level languages
Readability Hard for humans Easy, English-like
Speed of program Very fast, efficient Slightly slower (depends on translator)
Portability Tied to one CPU type Runs on many machines
Development time Long; error-prone Short; easier to debug and maintain
Use Device drivers, embedded systems Business apps, websites, data analysis

Generations of Programming Languages

Generation Type Example
1GL Machine language Binary code
2GL Assembly language MOV, ADD mnemonics
3GL Procedural high-level languages C, Java, Python, COBOL
4GL Closer to human language; say what, not how SQL, report generators
5GL Problem solving with constraints and AI Prolog

For example, in SQL (a 4GL) a manager writes SELECT Name FROM Customers WHERE City = 'Pokhara'; without describing step by step how to search the data.

Compilers and Interpreters

Since computers can only understand machine code, high-level languages must be translated. This is done by either a compiler or an interpreter.

  • Compiler: A compiler translates the entire source code of a program into machine code before the program is run. The resulting machine code is then saved as an executable file that can be run at any time.
    • Process: Source Code -> Compiler -> Machine Code (Executable File)
    • Examples: C and C++ are typically compiled languages.
  • Interpreter: An interpreter translates and executes the source code line by line, at the same time. No separate executable file is created.
    • Process: Source Code -> Interpreter -> Execution (line by line)
    • Examples: Python and JavaScript are typically interpreted languages.
flowchart LR
    SRC[Source Code]
    SRC -->|Compiler| EXE[Machine Code Executable]
    EXE --> RUN1[Run Program]
    SRC -->|Interpreter| RUN2[Execute Line by Line]

Figure 2: Compile vs Interpret Flow

Aspect Compiler Interpreter
Translation Whole program at once Line by line
Output Executable file No separate file
Execution speed Faster once compiled Slower
Error reporting Lists errors after compiling the whole program Stops at the first error
Example languages C, C++ Python, JavaScript

Java uses both: it is compiled to an intermediate bytecode, which the Java Virtual Machine then runs on any device.

Language Typical use
Python Data analysis, AI, automation, web back ends
JavaScript Interactive websites and web apps
Java Enterprise systems, Android apps, banking software
C / C++ Operating systems, games, embedded devices
C# Windows applications, games (Unity)
PHP Websites (e.g., WordPress)
SQL Querying and managing databases
Kotlin / Swift Android / iOS mobile apps

Choosing a language

Factors include the type of application (web, mobile, data), performance needs, availability of developers and libraries, cost and support, and compatibility with existing systems. A Nepali software company building a bank’s mobile app might use Kotlin and Swift for the apps, Java for the back end, and SQL for the database.

Summary

Programming languages are the tools we use to give instructions to computers. They range from low-level languages like machine and assembly language, which are close to the hardware, to high-level languages like Python and Java, which are closer to human language, and they have developed through five generations up to 4GLs such as SQL and 5GLs. High-level languages must be translated into machine code by either a compiler (which translates the whole program at once) or an interpreter (which translates it line by line) before the computer can execute them. Different languages suit different purposes, from websites to data analysis to mobile apps.

Key Takeaways

  • Programming languages are used to write instructions for computers.
  • Low-level languages (machine, assembly) are close to the hardware, while high-level languages (Python, Java) are closer to human language.
  • Languages have evolved through five generations, from machine code to AI-oriented languages.
  • Compilers translate the entire program at once, while interpreters translate it line by line.
  • The choice of language depends on the application, performance, skills, and cost.

Discussion Questions

  1. What are the main advantages of using a high-level language over a low-level language?
  2. What is the difference between a compiler and an interpreter?
  3. If you were creating a new software application, what factors would you consider when choosing a programming language?

Exam-Style Questions

Short answer

  1. What is a programming language? Differentiate between syntax and logic errors.
  2. What is assembly language? What is an assembler?
  3. Differentiate between a compiler and an interpreter.

Long answer

  1. Compare low-level and high-level languages with examples.
  2. Explain the generations of programming languages.