Introduction to Programming
Prepared by: Ms. Aiza Syahida binti Zakaria
Computer Programming Basics
Computer programs are a detailed set of
instructions given to the computer.
They tell the computer:
1. What actions you want the computer to perform
2. The order those actions should happen in
An effective program therefore needs:
1. A thorough understanding of the problem
2. A well thought-out, step-by-step solution to the
problem
Computer Programming Basics conts.
Activity
Working in groups of 2 students
Create a set of instructions that
will tell us:
How to eat a banana
Make your instructions as
detailed as possible, so that
even someone who has never
eaten a banana before can
understand them
How To Eat A Banana:
A Detailed List of Instructions
1. Using your hand, get a yellow crescent-shaped fruit
called a “banana”
2. Peel the outer skin off the banana (by breaking off the
outer stem and peeling back the yellow peel)
3. Eat the banana
1. Put a small section of banana in your mouth
2. Bite down on the banana
3. Chew the banana by opening and closing your mouth
4. Once the banana has been chewed, swallow the banana
5. Repeat until banana is finished
4. Throw out the used banana peel
What is Programming?
A procedure that outlines
What actions you want the computer to perform
and
The order in which they happen
is called an ALGORITHM
An ALGORITHM is basically an outline for
how your computer program will work
What is Programming? conts.
Developing an Algorithm is really just a type of
Problem Solving
We have to:
READ and understand the problem
THINK about different solutions to the
problem
DESIGN an approach that will solve the
problem
IF NEEDED
IMPLEMENT that design
TEST to see if it works
What is Programming? conts.
THINKING about the solution often means
breaking down complex tasks into smaller,
easier to understand tasks
These tasks must be well-defined so that we
understand what the action is acting on
e.g. telling a person to grab a banana will only work if
the person knows what a banana is
The tasks have to be easy to understand
e.g. telling a person to PEEL a banana will only work
if they understand what peeling means
What is Programming? conts.
When the algorithm is written out as a
well-thought series of steps, it is
sometimes called PSEUDOCODE
It is written in easy to understand language,
but is written very similar to the way that you
would code it into your 3rd Generation
Language
How To Eat A Banana:
A Detailed List of Instructions
1. Using your hand, get a yellow crescent-shaped fruit
called a “banana”
2. Peel the outer skin off the banana (by breaking off the
outer stem and peeling back the yellow peel)
3. Eat the banana
1. Put a small section of banana in your mouth
2. Bite down on the banana
3. Chew the banana by opening and closing your mouth
4. Once the banana has been chewed, swallow the banana
5. Repeat until banana is finished
4. Throw out the used banana peel
What is Programming? conts.
• The algorithm can also be written as a FLOW
CHART.
• The FLOW CHART is a graphic organiser (a
picture that helps organize your thoughts).
• It uses a collection of basic symbols that are
used to organize your algorithm.
• These symbols are connected by arrows that show how
the algorithm “flows”.
What is Programming? conts.
Flow Chart Symbols
What is Programming? conts.
Example 1: Basic Flow Chart
Writing Source Code?
Source Code
Source code is the fundamental component of a
computer program that is created by a
programmer.
It can be read and easily understood by a
human being.
When a programmer types a sequence
of statements into Notepad, for example, and
saves the sequence as a text file, the text file is
said to contain the source code.
Compilation
Compiler translates source into target (a machine language program).
Compiler goes away at execution time.
Compiler is itself a machine language program, presumably created
by compiling some other high-level program.
Machine language, when written in a format understood by the OS is
object code.
Interpretation
The interpreter stays around during execution.
It reads and executed statements one at a time.
Compilation vs Interpretation
• Compilation:
▫ Syntax errors caught before running the program
▫ Better performance
▫ Decisions made once, at compile time
• Interpretation:
▫ Better diagnostics (error messages)
▫ More flexibility
▫ Supports late binding (delaying decisions about program implementation
until runtime)
Can better cope with PLs where type and size of variables depend on input
▫ Supports creation/modification of program code on the fly (e.g. Lisp, Prolog)
Mixture of Compilation vs Interpretation
Many programming languages implement this.
Interpreter implements a Virtual Machine (VM).
JAVA
For flexibility: Just in Time (JIT) compiler translates
bytecode into Meta-Language (ML) just before
execution.