Programming Languages
Programming Languages
Programming Languages
PROG0101
FUNDAMENTALS OF PROGRAMMING
Chapter 2
Programming Languages
1
PROG0101 Fundamentals of Programming
Programming Languages
Topics
• Definition of Program, Computer Programming, and
Computer Programmer.
• Generations of Programming Language
• Types of Programming Language
2
PROG0101 Fundamentals of Programming
Programming Languages
Computer Program
• A program is a set of instructions following the rules
of the chosen language.
• Without programs, computers are useless.
• A program is like a recipe.
• It contains a list of ingredients (called variables) and
a list of directions (called statements) that tell the
computer what to do with the variables.
3
PROG0101 Fundamentals of Programming
Programming Languages
Programming Language
• A vocabulary and set of grammatical rules (syntax)
for instructing a computer to perform specific tasks.
• Programming languages can be used to create
computer programs.
• The term programming language usually refers to
high-level languages, such as BASIC, C, C++,
COBOL, FORTRAN, Ada, and Pascal.
4
PROG0101 Fundamentals of Programming
Programming Languages
Programming Language
• You eventually need to convert your program into
machine language so that the computer can
understand it.
• There are two ways to do this:
– Compile the program
– Interpret the program
5
PROG0101 Fundamentals of Programming
Programming Languages
Programming Language
• Compile is to transform a program written in a high-
level programming language from source code into
object code.
• This can be done by using a tool called compiler.
• A compiler reads the whole source code and
translates it into a complete machine code program
to perform the required tasks which is output as a
new file.
6
PROG0101 Fundamentals of Programming
Programming Languages
Programming Language
• Interpreter is a program that executes instructions
written in a high-level language.
• An interpreter reads the source code one instruction
or line at a time, converts this line into machine code
and executes it.
7
PROG0101 Fundamentals of Programming
Programming Languages
Computer Programming
• Computer programming is the process of writing,
testing, debugging/troubleshooting, and maintaining
the source code of computer programs.
• This source code is written in a programming
language like C++, JAVA, Perl etc.
8
PROG0101 Fundamentals of Programming
Programming Languages
Computer Programmer
• A programmer is someone who writes computer
program.
• Computer programmers write, test, and maintain
programs or software that tell the computer what to
do.
9
PROG0101 Fundamentals of Programming
Programming Languages
10
PROG0101 Fundamentals of Programming
Programming Languages
11
PROG0101 Fundamentals of Programming
Programming Languages
12
PROG0101 Fundamentals of Programming
Programming Languages
13
PROG0101 Fundamentals of Programming
Programming Languages
14
PROG0101 Fundamentals of Programming
Programming Languages
15
PROG0101 Fundamentals of Programming
Programming Languages
16
PROG0101 Fundamentals of Programming
Programming Languages
Machine Language
• Machine language is a collection of binary digits or
bits that the computer reads and interprets.
• Machine languages are the only languages
understood by computers.
• While easily understood by computers, machine
languages are almost impossible for humans to use
because they consist entirely of numbers.
17
PROG0101 Fundamentals of Programming
Programming Languages
Machine Language
Machine Language
169 1 160 0 153 0 128 153 0 129 153 130 153 0 131
200 208 241 96
18
PROG0101 Fundamentals of Programming
Programming Languages
Machine Language
Example:
• Let us say that an electric toothbrush has a processor
and main memory.
• The processor can rotate the bristles left and right,
and can check the on/off switch.
• The machine instructions are one byte long, and
correspond to the following machine operations:
19
PROG0101 Fundamentals of Programming
Programming Languages
Machine Language
20
PROG0101 Fundamentals of Programming
Programming Languages
Assembly Language
• A program written in assembly language consists of a
series of instructions mnemonics that correspond to a
stream of executable instructions, when translated by
an assembler, that can be loaded into memory and
executed.
• Assembly languages use keywords and symbols,
much like English, to form a programming language
but at the same time introduce a new problem.
21
PROG0101 Fundamentals of Programming
Programming Languages
Assembly Language
• The problem is that the computer doesn't understand
the assembly code, so we need a way to convert it to
machine code, which the computer does understand.
• Assembly language programs are translated into
machine language by a program called an
assembler.
22
PROG0101 Fundamentals of Programming
Programming Languages
Assembly Language
• Example:
– Machine language :
10110000 01100001
– Assembly language :
mov a1, #061h
– Meaning:
Move the hexadecimal value 61 (97 decimal) into
the processor register named "a1".
23
PROG0101 Fundamentals of Programming
Programming Languages
24
PROG0101 Fundamentals of Programming
Programming Languages
High-Level Language
• Examples of High-level Language:
• ADA
• C
• C++
• JAVA
• BASIC
• COBOL
• PASCAL
• PHYTON
25
PROG0101 Fundamentals of Programming
Programming Languages
Comparisson
Machine Language Assembly Language High-level Languages
Time to execute Since it is the basic A program called an A program called a
language of the ‘assembler’ is required compiler or interpreter
computer, it does not to convert the program is required to convert
require any translation, into machine language. the program into
and hence ensures Thus, it takes longer to machine language.
better machine execute than a Thus, it takes more
efficiency. This means machine language time for a computer to
the programs run program. execute.
faster.
Time to develop Needs a lot of skill, as Simpler to use than Easiest to use. Takes
instructions are very machine language, less time to develop
lengthy and complex. though instruction programs and, hence,
Thus, it takes more codes must be ensures better program
time to program. memorized. It takes efficiency.
less time to develop
programs as compared
to machine language.
26
PROG0101 Fundamentals of Programming
Programming Languages
BASIC
• Short for Beginner's All-purpose Symbolic
Instruction Code.
• Developed in the 1950s for teaching University
students to program and provided with every self-
respecting personal computer in the 1980s,
• BASIC has been the first programming language for
many programmers.
• It is also the foundation for Visual Basic.
27
PROG0101 Fundamentals of Programming
Programming Languages
BASIC
Example:
28
PROG0101 Fundamentals of Programming
Programming Languages
Visual Basic
• A programming language and environment
developed by Microsoft.
• Based on the BASIC language, Visual Basic was one
of the first products to provide a graphical
programming environment and a paint metaphor for
developing user interfaces.
29
PROG0101 Fundamentals of Programming
Programming Languages
Visual Basic
Example:
30
PROG0101 Fundamentals of Programming
Programming Languages
C
• Developed by Dennis Ritchie at Bell Labs in the mid
1970s.
• C is much closer to assembly language than are
most other high-level languages.
• The first major program written in C was the UNIX
operating system.
• The low-level nature of C, however, can make the
language difficult to use for some types of
applications.
31
PROG0101 Fundamentals of Programming
Programming Languages
C
Example:
#include <stdio.h>
int main(void)
{
printf("hello, world\n");
return 0;
}
32
PROG0101 Fundamentals of Programming
Programming Languages
C++
• A high-level programming language developed by
Bjarne Stroustrup at Bell Labs.
• C++ adds object-oriented features to its predecessor,
C.
• C++ is one of the most popular programming
language for graphical applications, such as those
that run in Windows and Macintosh environments.
33
PROG0101 Fundamentals of Programming
Programming Languages
C++
Example:
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
34
PROG0101 Fundamentals of Programming
Programming Languages
Pascal
• A high-level programming language developed by
Niklaus Wirth in the late 1960s.
• The language is named after Blaise Pascal, a
seventeenth-century French mathematician who
constructed one of the first mechanical adding
machines.
• It is a popular teaching language.
35
PROG0101 Fundamentals of Programming
Programming Languages
Pascal
Example:
Program HelloWorld(output);
begin
writeLn('Hello, World!')
end.
36
PROG0101 Fundamentals of Programming
Programming Languages
Java
• A high-level programming language developed by
Sun Microsystems.
• Java was originally called OAK, and was designed for
handheld devices and set-top boxes.
• Oak was unsuccessful so in 1995 Sun changed the
name to Java and modified the language to take
advantage of the burgeoning World Wide Web.
• Java is a general purpose programming language
with a number of features that make the language
well suited for use on the World Wide Web.
37
PROG0101 Fundamentals of Programming
Programming Languages
Java
Example:
38
PROG0101 Fundamentals of Programming
Programming Languages
39