Fundamentals of Programming Lec-1
Fundamentals of Programming Lec-1
Fundamentals of Programming
Lecture 1
2023/11/14
Udaya Perera
1
What is Programming language???
As we know, to communicate with a person, we need a specific
language, similarly to communicate with computers, programmers
also need a language is called Programming language.
A programming language is a computer language that is used by
programmers (developers) to communicate with computers. It is a set
of instructions written in any specific language ( C, C++, Java, Python) to
perform a specific task.
2
Why is programming important?
• Programming is important because it allows us to
control computers.
• Computers are becoming increasingly important in our
lives, so it is important to be able to understand how
to program them.
• Programming can also be a creative outlet, allowing us
to design and build our own programs.
3
How to get started with programming
• There are many ways to get started with programming.
• One way is to take a programming class.
• There are also many online resources available, including
tutorials and coding bootcamps.
• Once you have a basic understanding of programming, you
can start experimenting with your own projects.
4
Types of programming languages
• There are many different types of programming
languages, each with its own strengths and weaknesses.
• Some of the most popular programming languages
include Java, Python, C++, and JavaScript.
• The best programming language for you will depend on
your specific needs.
5
Applications of programming
Programming can be used in a wide variety of applications, including:
• Web development
• Software development
• Game development
• Data science
• Artificial intelligence
6
Syntax
7
Machine Language
✔ A language that controls the computer’s on/off circuitry.
✔ Machine language is the only language a computer is capable of
understanding.
8
High-level languages
The instructions that tell a computer what to do are written in machine
code. Machine code is a series of numbers written in binary. Each
number represents a different instruction.
Programmers find machine code difficult to learn, program in and
debug. As a result, the majority of programmers write programs in
high-level programming languages. These languages are close to
natural language - the spoken and written language of humans. For
example, Python uses 'print', ‘if’, 'input' and 'while' statements - all
words from the English language - to form instructions
9
Commonly used high-level languages
• Python
• Java
• C++
• C#
• Visual Basic
• JavaScript
10
Low-level languages
Low-level languages are languages that sit close to the computer's
instruction set. An instruction set is the set of instructions that the
processor understands.
11
Machine code
Machine code is the set of instructions that a CPU understands directly
and can act upon. A program written in machine code would consist of
only 0s and 1s - binary. This is very difficult to write and debug. Even a
very simple program could have thousands of 0s and 1s in it.
12
Assembly language
Assembly language sits between machine code and high-level language
in terms of ease of use. While high-level languages use statements to
form instructions, assembly language uses mnemonics - short
abbreviations. Each mnemonic directly corresponds with a machine
code instruction.
13
Compiler and Interpreter
We generally write a computer program using a programming
language, which is a high-level language. But computers only
understand machine language. A program written in a high-level
language is called source code. We need to convert the source code
into machine code and this is accomplished by these compilers and
interpreters.
14
Compiler Interpreter
15
Translators
Any program written in a high-level language is known as source code.
However, computers cannot understand source code. Before it can be
run, source code must first be translated into a form which a computer
understands.
A translator is a program that converts source code into machine
code. Generally, there are three types of translator:
• compilers
• interpreters
• assemblers
16
Compilers
A compiler takes the source code as a whole and translates it into
machine code all in one go. Once converted, the object code can be run
unassisted at any time. This process is called compilation.
17
Interpreters
An interpreter translates source code into machine code one
instruction at a time. It is similar to a human translator translating
what a person says into another language, sentence by sentence, as
they speak. The resulting machine code is then executed immediately.
The process is called interpretation.
18
Errors
If you started programming the first thing you notice is that things
break and they don't always work as you expected. Those are called
programming errors so it’s useful to know these errors.
• Syntax Errors
• Runtime Errors
• Logical Errors
19
Syntax Error
This happens when the code doesn't respect the syntax rules a
program requires.
• Spelling mistakes
• Missing out quotes
• Missing out brackets
• Using upper case characters in keywords e.g. IF instead of if
• Missing out a colon or semicolon at end of a statement
• Using tokens in the wrong order
20
Examples:
22
Logical errors
As the name implies, these appear when the program runs but behaves
not as expected or gives wrong results.
For example, an algorithm to run properly, the logic must be correct.
23
What is debugging?
• Debugging is the process of finding and fixing errors in
code.
• Debugging is an essential part of programming.
• There are many different debugging tools available,
including debuggers and linters.
24
What is testing?
• Testing is the process of verifying that code meets
its requirements.
• Testing is an essential part of programming.
• There are many different testing techniques,
including unit testing, integration testing, and
system testing.
25
What is version control?
• Version control is a system for tracking changes to
code.
• Version control is an essential part of programming.
• There are many different version control systems
available, including Git and Subversion.
26