2. INTRODUCTION
Mohamed Asarudeen
Computer programming is the act of writing computer programs,
which are a sequence of instructions written using a Computer
Programming Language to perform a specified task by the
computer.
Computer Programming is fun and easy to learn provided you
adopt a proper approach. This tutorial attempts to cover the
basics of computer programming using a simple and practical
approach for the benefit of novice learners.
This EBook has been prepared for the beginners who are willing
to learn computer programming but they are unable to learn it
due to lack of proper guidance.
Copyright & Disclaimer
@ Copyright 2020 by N Mohamed Asarudeen.
All the content and graphics published in this e-book are the
property of N Mohamed Asarudeen. . The user of this e-book is
prohibited to reuse, retain, copy, distribute or republish any
contents or a part of contents of this e-book in any manner
without written consent of the publisher.
Mohamed Asardeen
Asardeen68@gmail.com
3. TABLE OF
CONTENTSOVERVIEW 1…………………………………………..#
INTRODUCTION OF THE PROGRAM 1.1………………........#
INTRODUCTION TO COMPUTER PROGRAMMING…….……..#
USES OF COMPUTER PROGRAM 1.3………………….……#
COMPUTER PROGRAMMER 1.4………………….…..#
ALGORITHM 1.5…………………………………………..#
REPRESENTATION OF AN ALGORITHM................................#
LOW LEVEL PROGRAMMING LANGUAGE 2..….#
MACHINE LANGUAGE 2.1………………………………...#
ASSEMBLY LANGUAGE 2.2………………………………..#
HIGH LEVEL PROGRAMMING LANGUAGE 3..…#
PROGRAMMING LANGUAGE TYPES 4….……….#
SERVER SIDE PROGRAMMING 4.1…………...………….…#
CLIENT SIDE PROGRAMMING 4.2…………………………#
PROGRAMMING AND SCRIPTING……………….……..#
LANGUAGE TRANSLATORS 5……..……………..#
INTERPRETOR 5.1……………………………………...#
COMPILER 5.2……………………………………….…#
TEXT EDITOR 5.3………………………………………#
4. 1.OVERVIEW
4
1.1 Introduction to Computer Program
Before getting into computer programming, let us first understand
computer programs and what they do.
A computer program is a sequence of instructions written using a
Computer Programming Language to perform a specified task by
the computer.
The two important terms that we have used in the above definition
are:
• Sequence of instructions
• Computer Programming Language
To understand these terms, consider a situation when someone asks
you about how to go to a nearby KFC. What exactly do you do to
tell him the way to go to KFC?
You will use Human Language to tell the way to go to KFC,
something as follows:
Here, you have used English Language to give several steps to be
taken to reach KFC. If they are followed in the following sequence,
then you will reach KFC:
1. Go straight
2. Drive half kilometer
3. Take left
4. Drive around one kilometer
5. Search for KFC at your right side
First go straight, after half kilometer, take left from the red light and then drive around one
kilometer and you will find KFC at the right.
5. 5
Now, try to map the situation with a computer program. The above
sequence of instructions is actually a Human Program written in
English Language, which instructs on how to reach KFC from a
given starting point. This same sequence could have been given in
Spanish, Hindi, Arabic, or any other human language, provided the
person seeking direction knows any of these languages.
Now, let's go back and try to understand a computer program,
which is a sequence of instructions written in a Computer Language
to perform a specified task by the computer. Following is a simple
program written in Python programming Language:
The above computer program instructs the computer to print "Hello,
World!" on the computer screen.
• A computer program is also called a computer software, which can
range from two lines to millions of lines of instructions.
• Computer program instructions are also called program source code and
computer programming is also called program coding.
• A computer without a computer program is just a dump box; it is
programs that make computers active.
As we have developed so many languages to communicate among
ourselves, computer scientists have developed several computer-
programming languages to provide instructions to the computer
(i.e., to write computer programs). We will see several computer
programming languages in the subsequent chapters.
print "Hello, World!"
6. 6
1.2 Introduction to Computer Programming
If you understood what a computer program is, then we will say:
the act of writing computer programs is called computer
programming.
As we mentioned earlier, there are hundreds of programming
languages, which can be used to write computer programs and
following are a few of them:
• Java
• C
• C++
• Python
• PHP
• Perl
• Ruby
7. 7
1.3 Uses of Computer Programs
Today computer programs are being used in almost every field,
household, agriculture, medical, entertainment, defense,
communication, etc. Listed below are a few applications of
computer programs:
• MS Word, MS Excel, Adobe Photoshop, Internet Explorer,
Chrome, etc., are examples of computer programs.
• Computer programs are being used to develop graphics and
special effects in movie making.
• Computer programs are being used to perform Ultrasounds, X-
Rays, and other medical examinations.
• Computer programs are being used in our mobile phones for
SMS, Chat, and voice communication.
1.4 Computer Programmer
Someone who can write computer programs or in other words,
someone who can do computer programming is called a Computer
Programmer.
Based on computer programming language expertise, we can name
a computer programmers as follows:
• C Programmer
• C++ Programmer
• Java Programmer
• Python Programmer
• PHP Programmer
8. 8
1.5 Algorithm
An algorithm is a method to show the steps in solving a problem.
An algorithm is a step-by-step procedure for solving a problem. The
need for this is to present a way to solve the problem with a plan.
Example 1 - Let us develop an algorithm to post a letter.
1. Writing the letter
2. Folding the letter
3. Inserting the letter in an envelope
4. Writing the address
5. Sticking the stamp
6. Posting the letter
Thus, a computer programmer lists down all the steps required to
resolve a problem before writing the actual code. Following is a
simple example of an algorithm to find out the largest number from
a given list of numbers:
The above algorithm has been written in a crude way to help
beginners understand the concept. You will come across more
standardized ways of writing computer algorithms as you move on
to advanced levels of computer programming.
1. Get a list of numbers L1, L2, L3....LN
2. Assume L1 is the largest, Largest = L1
3. Take next number Li from the list and do the following
4. If Largest is less than Li
5. If Li is last number from the list then
6. Print value stored in Largest and come out
9. 9
1.6 REPRESENTATION OFAN ALGORITHM
Flowchart
A flowchart is a type of diagram that represents
a workflow or process. A flowchart can also be defined as a
diagrammatic representation of an algorithm, a step-by-step
approach to solving a task.
The symbols given in table are used to indicate different functions.
10. 10
E.g. 1 - Finding the area of a circle.
E.g. 2 - Finding whether a number is odd or even
11. 2.LOWLEVELPROGRAMMING
LANGUAGE
11
2.1 Machine Language
Sometimes referred to as machine code or object code, machine
language is a collection of binary digits or bits that the computer
reads and interprets. Machine language is the only language a
computer is capable of understanding.
The exact machine language for a program or action can differ
by operating system. The specific operating system dictates how a
compiler writes a program or action into machine language.
Machine language example
Below is an example of machine language (binary) for the text
"Hello World."
Below is another example of machine language (non-binary), which
prints the letter "A" 1000 times to the computer screen.
01001000 01100101 01101100 01101100 01101111 00100000
01010111 01101111 01110010 01101100 01100100
169 1 160 0 153 0 128 153 0 129 153 130 153 0 131 200 208
241 96
12. 12
2.2 Assembly language
Sometimes referred to as assembly or ASM, an assembly
language is a low-level programming language.
Programs written in assembly languages are compiled by
an assembler. Every assembler has its own assembly language,
which is designed for one specific computer architecture.
Machine language is a series of numbers, which is not easy for
humans to read. Using ASM, programmers can write human-
readable programs that correspond almost exactly to machine
language.
Assembly is called a low-level programming language because
there's (nearly) a one-to-one relationship between what it tells the
computer to do, and what the computer does. In general, one line of
an assembly program contains a maximum of one instruction for the
computer.
13. HIGHLEVELPROGRAMMING
LANGUAGE
13
A high-level language (HLL) is a programming language such
as C, FORTRAN, or Pascal that enables a programmer to
write programs that are more or less independent of a particular
type of computer. Such languages are considered high-level because
they are closer to human languages and further from machine
languages.
In contrast, assembly languages are considered low-level because
they are very close to machine languages.
Advantages of High-Level Languages
• The main advantage of high-level languages over low-level
languages is that they are easier to read, write, and maintain.
Ultimately, programs written in a high-level language must be
translated into machine language by a compiler or interpreter.
• The first high-level programming languages were designed in
the 1950s. Now there are dozens of different languages,
including Ada, Algol, BASIC, COBOL, C, C++,
FORTRAN, LISP, Pascal, and Prolog.
14. 14
4.1 Server-side Programming
Server-side programming can be explained as:
It is the general name for the kind of program that runs directly
on the server.
Or we can say that server-side programming must deal with
dynamic content. It runs on the server. Most web pages are not
static since they deal with searching databases.
Server-side Uses
• It processes the user input
• Displays the requested pages
• Structure of web applications
• Interaction with servers/storages
• Interaction with databases
• Querying the database
• Encoding of data into HTML
• Operations over databases like delete, update.
• Server-side Languages Example
There are several languages that can be used for server-side
programming:
• PHP
• ASP.NET (C# OR Visual Basic)
• C++
• Java and JSP
• Python
• Ruby on Rails and so on.
PROGRAMMINGLANGUAGE
TYPES
15. 4.2 Client-side Programming
Similarly to server-side programming, client-side programming is
also the name of the entire program that runs on the client.
Or we can say that client-side programming mostly deals with the
user interface with which the user interacts in the web. It is mostly a
browser, in the user's machine, that runs the code and is mainly
done in any scripting language like JavaScript (or we can use Flash
instead of JavaScript or VNScript).
Client-side Uses
• Makes interactive web pages
• Make stuff work dynamically
• Interact with temporary storage
• Sends requests to the server
• Retrieval of data from Server
• Interact with local storage
• Provides remote access for client-server program
• Client-side Languages Example
• Works as an interface between user and server
There are many client-side scripting languages too.
• JavaScript
• VBScript
• HTML (Structure)
• CSS (Designing)
• AJAX etc.
16. 16
A translator is a programming language processor that
converts a computer program from one language to
another. It takes a program written in source code and
converts it into machine code. It discovers and identifies the
error during translation.
Purpose of Translator
It translates high-level language program into a machine
language program that the central processing unit (CPU) can
understand. It also detects errors in the program.
All of the above work in some way towards getting a high-
level programming language translated into machine code
that the central processing unit (CPU) can understand.
Examples of CPUs include those made by Intel (e.g., x86),
AMD (e.g., Athlon APU), NXP (e.g., PowerPC), and many
others. It’s important to note that all translators, compilers,
interpreters and assemblers are programs themselves.
5. LANGUAGETRANSLATORS
17. 17
Assembler:
Assembler is the language translator designed to translate assembly
language program (source codes) into machine language program
(object codes). The original assembly language program codes are
called source codes and after translation, the nal machine language
program codes are called object codes.
Compiler
A compiler is a translator used to convert high-level programming
language to low-level programming language. It converts the
whole program in one session and reports errors detected after the
conversion. Compiler takes time to do its work as it translates high-
level code to lower-level code all at once and then saves it to
memory.
A compiler is processor-dependent and platform-dependent. But it
has been addressed by a special compiler, a cross-compiler and a
source-to-source compiler. Before choosing a compiler, user has to
identify first the Instruction Set Architecture (ISA), the operating
system (OS) and the programming language that will be used to
ensure that it will be compatible.
.
18. 18
Compiler
Interpreter
Just like a compiler, is a translator used to convert
high-level programming language to low-level
programming language. It converts the program
one at a time and reports errors detected at once,
while doing the conversion. With this, it is easier
to detect errors than in a compiler. An interpreter
is faster than a compiler as it immediately executes
the code upon reading the code.
It is often used as a debugging tool for software
development as it can execute a single line of code
at a time. An interpreter is also more portable than
a compiler as it is not processor-dependent, you
can work between hardware architectures.
19. 19
Interpreter
Translator Examples
Compiler
Microsoft Visual Studio
GNU Compiler Collection (GCC)
Common Business Oriented Language (COBOL)
Interpreter
OCaml
List Processing (LISP)
Python
Assembler
Fortran Assembly Program (FAP)
Macro Assembly Program (MAP)
Symbolic Optimal Assembly Program (SOAP)
20. 20
1.TEXT EDITOR
A text editor is a type of computer program that edits plain text.
Such programs are sometimes known as "notepad" software,
following the naming of Microsoft Notepad. Text editors are
provided with operating systems and software development
packages, and can be used to change files such as configuration
files, documentation files and programming language source code