21
Software – Computer Programs “Computers do exactly what you tell them to do. This is often quite different from what you meant to tell them to do.”

Introduction to Programming II

Embed Size (px)

DESCRIPTION

programming2

Citation preview

Page 1: Introduction to Programming II

Software – Computer Programs

“Computers do exactly what you tell them to do. This is often quite different from what you meant to tell them to do.”

Page 2: Introduction to Programming II

Programming What is programming?

Creation of order Planning or scheduling the performance

of a task What is computer programming?

“The process of specifying the data types and the operations for a computer to apply to data in order to solve a problem”.

Page 3: Introduction to Programming II

Data and Information Information

any knowledge that can be communicated.

Data information in a form the computer can use comes in different forms : letters, words,

integer numbers, real numbers, dates, times, coordinates on a map etc.

Each type of data is said to have a specific data type

Page 4: Introduction to Programming II

Computer program

“Data type specifications and instructions for carrying out

operations that are used by a computer to solve a problem”

Page 5: Introduction to Programming II

How do we write a Program?

Analysis and specification

General solution

(algorithm)

verify

Concrete solution (program)

Test

Maintenance phase

PROBLEM-SOLVING PHASE IMPLEMENTATION PHASE

Page 6: Introduction to Programming II

Programming Language Set of rules, symbols and special words used

to construct a computer program

Simplified form of English ( with math symbols) that adheres to a strict set of grammatical rules

Why not translate from English directly into instructions for the computer? Too complicated Too ambiguous

Page 7: Introduction to Programming II

Other terms Coding

Translating an algorithm into a programming language

Running code Execution of code

Debugging Determining what is wrong with a program

and modifying it, or the algorithm, to fix it. Implementation

Coding and testing of an algorithm

Page 8: Introduction to Programming II

Differences in implementation

John’s Java code

John’s C++ code

John’s Pascal code

Peter’s Java code

Mary’s Java code

PROBLEM

Algorithm

Simon’s Java code

Programming shortcut: More time spent debugging and revising program

“Think first and code later!”

Page 9: Introduction to Programming II

“Programmers who pay close attention to their programs by checking them before running them actually spend significantly less time producing successful programs. In contrast those programmers who simply write a program and then run it to see what it does spend more time.”

Page 10: Introduction to Programming II

How is a program converted into a form that a computer can use?

What is the form of data that the computer uses? All data is converted into a set of

binary codes, strings of 1s and 0s Binary codes are distinguished by the

manner in which the computer uses them.

Machine language

Page 11: Introduction to Programming II

Machine language to High-level languages Machine language

made up binary-coded instructions used directly by the computer

tedious and error prone programs were difficult to read and modify

Assembly language Low-level programming language in which a

mnemonic is used to represent each of the machine language instructions for a particular computer

Assembly Language Machine LanguageADD 100101SUB 010011

Page 12: Introduction to Programming II

Machine language to High-level languages Assembly language

Computer not able to process instructions directly hence a program, written in machine language, was used to translate from assembly language to machine language: Assembler

Easier for humans to use than machine language however programmers still forced to think in terms of individual machine instructions

High-level languages Closer to English, and other natural languages,

than assembly and machine languages.

Page 13: Introduction to Programming II

HUMAN THOUGHT NATURAL LANGUAGE

HIGH LEVEL PROGRAMMING LANGUAGE

MACHINE CODE

problem

PROBLEM SOLVING TECHNIQUES ALGORITHMSPSEUDOCODEJAVA

COMPILER

Page 14: Introduction to Programming II

Converting a high-level language to machine language Compiler

A program that translates a program written in a high-level language into machine code

Source code Data type specifications and instructions written

in a high-level programming language Object code

A machine language version of a source code Bytecode

A standard machine language into which Java source code is compiled

Page 15: Introduction to Programming II

Java compiler produces Bytecode that can be run on any machine with the JVM

Java program Java Compiler

Java Bytecode

Windows PCRunning JVM

UNIX WorkstationRunning JVM

MacintioshRunning JVM

• Java Virtual Machine (JVM) a program that serves as a language interpreter

• Bytecode is the machine language for the JVM

Java Bytecode

JVM Running on X

Machine Language for machine X

Program running

INTERPRETATION

Page 16: Introduction to Programming II

Type of instructions Reflect the operations a computer can perform A computer can

transfer data from one place to another receive input from and input device and write it to

an output device compare data values for equality or inequality perform arithmetic operations branch to a different section of the instructions

Programming languages require control structures to express algorithms as source code.

Page 17: Introduction to Programming II

Sequence

Statement Statement Statement

Selection Statement1

Statement2

Condition

True

False

Selection

Statement1

Condition

True

False

Page 18: Introduction to Programming II

Subprogram/Method/Function

SUBPROGRAM1

SUBPROGRAM1A meaningful collection of any of the other control statements

STATEMENT1 STATEMENT2

EVENT EVENTHANDLERA subprogram executedwhen an event occurs

Asynchronous Control

(Asynchronous –“not at the same time”, events can occur at any time)

Page 19: Introduction to Programming II

Object-Oriented Programming Languages Earlier programming languages focused on the

operations and control structures of programming – procedural languages

Procedural languages paid little explicit attention to the relationship between the operations and the data. There were few simple data types

Object-oriented languages focuses on the relationship between the operations and data

Page 20: Introduction to Programming II

Object-Oriented Programming Languages OOPL allow us to collect a data type

and its associated operations into a single entity called an object.

Objects make the relationship between the data type and operations explicit.

Objects are complete and self-contained hence promote reusability

Page 21: Introduction to Programming II

Object-oriented terminology Class

A description of an object that specifies the types of data values that it can hold and the operations that it can perform

Classes are usually collected into packages

Instantiate To create an object based on the

description supplied by a class