Introduction to Computer Science and Programming

56
Introduction to Computer Science and Programming

description

Introduction to Computer Science and Programming. The Computer. To understand at a conceptual level: What is a computer?. The Computer. WHICH IS SMARTER?. The Computer. WHICH IS SMARTER? A Computer. The Computer. WHICH IS SMARTER? A Computer - OR A Toaster. - PowerPoint PPT Presentation

Transcript of Introduction to Computer Science and Programming

Page 1: Introduction to Computer Science and Programming

Introduction to Computer Science and Programming

Page 2: Introduction to Computer Science and Programming

The Computer

• To understand at a conceptual level:

– What is a computer?

Page 3: Introduction to Computer Science and Programming

The Computer

• WHICH IS SMARTER?

Page 4: Introduction to Computer Science and Programming

The Computer

• WHICH IS SMARTER?

A Computer

Page 5: Introduction to Computer Science and Programming

The Computer

• WHICH IS SMARTER?

A Computer - OR A Toaster

Page 6: Introduction to Computer Science and Programming

The Computer

• To understand at a conceptual level:

– What is a computer?

-nothing but a box filled with wires and lights

Page 7: Introduction to Computer Science and Programming

The Computer

• To understand at a conceptual level:

– What is a computer?

-nothing but a box filled with wires and lights

- it needs software to be anything more than this.- software gives the box the ‘intelligence’

Page 8: Introduction to Computer Science and Programming

The Computer

• To understand at a conceptual level:

– What is a computer?

- two branches of Computer Science

SOFTWARE --------------------- hardware

Page 9: Introduction to Computer Science and Programming

The Computer

• What does the computer understand?

How does a computer ‘see’ the world?

(let’s go inside the mind of a computer)

Page 10: Introduction to Computer Science and Programming

The Computer

• What does the computer understand?

ON / OFFHigh voltage / Low (no, absence of) voltage

Humans represent these two ‘states’ asone (1) and zero (0)

Page 11: Introduction to Computer Science and Programming

The Computer

• What does the computer understand?

One (1) and Zero (0)

Two states

Binary Numerical System (base 2)

We use decimal (base 10) numerical system

- why?

Page 12: Introduction to Computer Science and Programming

The Computer

• What does the computer understand?

Decimal: 0,1,2,3,4,5,6,7,8,9 (repeat)

Binary: 0, 1 (repeat)

Page 13: Introduction to Computer Science and Programming

The Computer

• What does the computer understand?

Decimal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (repeat) 10,11,12,13,14,15,16,17,18,19 (repeat) 20,21,22,23,24,25,26,27,28,29 ….

Binary: 0, 1 (repeat) 10, 11 (repeat) 100,101,110,111 (repeat) 1000,1001,1010,1011,1100,1101,1111 (repeat)

Page 14: Introduction to Computer Science and Programming

The Computer• What does the computer understand?

Direct translation of systems:

BINARY DECIMAL 0 = 0 1 = 1 10 = 2 11 = 3100 = 4101 = 5110 = 6111 = 7

Page 15: Introduction to Computer Science and Programming

The Computer• What does the computer understand?

Direct translation of systems:

VERY %$*!@# CONFUSING !!!!!

Do not think of binary as ‘numbers’Think of binary as ‘symbols’

• Do not look at 1001 and see ‘one thousand and one’see this as the ‘symbol for ‘nine’

Page 16: Introduction to Computer Science and Programming

The Computer• What does the computer understand?

Direct translation of systems:

each position in a number is the base of the number

Decimal: 2459 2 is in the thousands position

4 is in the hundreds position 5 is in the tens position 9 is in the ones position

1000 100 10 1 2 4 5 9

(2 x 1000) + (4 x 100) + (5 x 10) + (9 x 1)

Page 17: Introduction to Computer Science and Programming

The Computer• What does the computer understand?

Direct translation of systems:

each position in a number is the base of the number

Binary: 11011 1 is in the sixteenth position 1 is in the eighths position

0 is in the fourths position 1 is in the twos position 1 is in the ones position

16 8 4 2 1 1 1 0 1 1

(1 x 16) + (1 x 8) + (0 x 4) + (1 x 2) + (1 x 1) = 27 (decimal)

Page 18: Introduction to Computer Science and Programming

The Computer

• What does the computer understand?

Binary Numbers:

- So What ???????

Page 19: Introduction to Computer Science and Programming

The Computer• What does the computer understand?

Binary Numbers:

- So What ???????

- humans need a method of telling the computer what to do

- some way to ‘communicate’ with the machine

- otherwise it is just lights and wires in a box…

Page 20: Introduction to Computer Science and Programming

The Computer

• What does the computer understand?

Binary Numbers:- we use numbers to ‘communicate’ with the machine - a computer is limited to understanding only binary (on / off)- so, we use binary

Page 21: Introduction to Computer Science and Programming

The Computer• What does the computer understand?

Binary Numbers:

break binary (on / off ) into units.

one binary is a BIT a BIT is either a 1 or a 0 -> 1 eight BITs strung together is a BYTE a BYTE is a combination of eight 1’s and 0’s -> 1100 1001

Page 22: Introduction to Computer Science and Programming

The Computer• What does the computer understand?

Binary Numbers: byte = 8 bits

kilobyte = 1,000 bytes (or 1,024 bytes) megabyte = 1,000,000 bytes or 1,048,576 bytes or 1,024,000 bytes gigabyte = 1,000,000,000 bytes or 1,072,436,586 bytes or 1,024,000,000 bytes terabyte = 1,000,000,000,000 bytes…

Page 23: Introduction to Computer Science and Programming

The Computer

• What does the computer understand?

Binary Numbers: byte = (one alphabetic character)

kilobyte = one third (1/3) of a page megabyte = one half (1/2) average size book gigabyte = 500 books terabyte= 500,000 books…

next we will see what this has to do with programming

Page 24: Introduction to Computer Science and Programming

The Computer• So, we have these machines

We know they only understand on / off (0 / 1)

How do we it get the machines to do anything

• Answer: talk to them in their language: 11010101001001 - this is known as machine language

- (the lowest level language)

• - a machine may be designed to take each byte, break it in half (called a nybble – or four bits) and process the ones and zeros

- an instruction to the computer could look like: 10110000 01100010

Page 25: Introduction to Computer Science and Programming

The Computer

• - an instruction to the computer could look like: 10110000 01100010

- the next line could be:

10010000 10111011

These are actual machine instructions telling the computer to remember the number 97 and then to add 35 to itself and remember that number.

Page 26: Introduction to Computer Science and Programming

The Computer - this was fine but awful tedious, awful hard and just plain awful

- a better way had to be found.

- assembly language was created it associated certain numeric instruction to near English mnemonics like MOV for move and ADD for add 10110100 01111101 becomes MOV a1,61h

10012000 10010111 becomes ADD a1,23h A different program (an assembler) inside the computer assembles (translates) the MOV back to 0100, a1 becomes the address 0110 and 111101 is 61h.

Page 27: Introduction to Computer Science and Programming

The Computer - okay but still awful tedious, awful hard and just plain awful

- a yet better way had to be found.

- higher level languages where created Fortran and COBOL and C MOV a1,61h becomes x := 97

ADD a1,23h becomes x:= x + 35 A different program (a compiler) inside the computer compiles (translates) the := back to 0100, x becomes the address a1 and 111101 is 97 (61 in hex).

Page 28: Introduction to Computer Science and Programming

The Computer - BUT !!!!!

- these languages could all be machine dependent

- machine A may break instructions down into nybbles (4 bits) but machine B may keep instructions at one byte (8 bits).

- the compiler made for Machine A will cause errors in Machine B because when it translates four bits only the computer will be

expecting eight.

- need a machine independent way of making programs.

- but why would machines have different ways of using ones and zeros?

- answer is in the history of how computers came to be created.

Page 29: Introduction to Computer Science and Programming

The Computer

• How long have ‘computers’ been around?

• Imagine the world without computers without the internet without IM without games without graphics (or George Lucas) without ?????

• What is the ‘origin’ of the word (as it applies to this)?

Page 30: Introduction to Computer Science and Programming

The Computer – A Brief History• First ‘computer’ -ABACUS

about 2700 BC

Page 31: Introduction to Computer Science and Programming

The Computer – A Brief History• Next Stage: ’ -the Differential Analyzer

around 1927 (analog computing device)

Page 32: Introduction to Computer Science and Programming

The Computer – A Brief History• Along comes World War Two

need to ‘crunch’ some serious numbers - cannon trajectories - Enigma

around 1942 (electronic computing device: Colossus)

Page 33: Introduction to Computer Science and Programming

The Computer – A Brief History

• Use of the Vacuum Tube (br. Valve)

a tube can be used to create a ‘gate’

(or circuit)

gates can be tied together to create a processing unit

Page 34: Introduction to Computer Science and Programming

The Computer – A Brief History• Put all these tubes in a sequence and you get a computer

ENIAC (1944)

• around 1942 (electronic programmable computing device)

Page 35: Introduction to Computer Science and Programming

The Computer – A Brief History• Programming the ENIAC

- bootstrapping the computer

Page 36: Introduction to Computer Science and Programming

The Computer – A Brief History• The first computer ‘bug’

Grace Hooper (1947)

• - notation by one of the creators of COBOL computer language

Page 37: Introduction to Computer Science and Programming

The Computer – A Brief History• Next came the invention of the transistor (1947)

Notably maybe the single greatest invention of the 20th century

Originally designed to be used in airborne radar

- eventually replaced tubes in everything from radios to x-ray machines- ushered in the ‘electronic’ age

Page 38: Introduction to Computer Science and Programming

The Computer – A Brief History• The transistor removed the big roadblock from larger and more powerful

computers (heat) (size) (weight)

• Transistors could be combined on a silicon ‘wafer’ to create an integrated circuit

• Integrated Circuits allowed the building of ‘modern’ digital devices like the IBM 360.

(1960’s)

Page 39: Introduction to Computer Science and Programming

The Computer – A Brief History• Now computers are the domain of the ‘Business

World’

Computers are great as tabular machines

- used to collate and store data

- the general public only knows computers through tv and movies

Page 40: Introduction to Computer Science and Programming

The Computer – A Brief History• Access to computers is very limited and restricted.

• Business and University have the main availability.

• Input was still laborious

- punch cards - batch jobs

Page 41: Introduction to Computer Science and Programming

The Computer – A Brief History• Then came along the Intel 8800 microchip

(originally designed for calculators)

• Used to make the first home computer

(January, 1975)

it started a revolution

Page 42: Introduction to Computer Science and Programming

The Computer – A Brief History• Overwhelming response to the Altair led to three

major events (2 and half really)

• Creation of Microsoft (1975)

• Creation of the Apple II (1977)

• (which led to the) Creation of the IBM PC (1981)

Page 43: Introduction to Computer Science and Programming

The Computer – A Brief History• Bringing us to concept of Moore’s Law

• “the processing power of the computer will double every 2 years” 1965

Page 44: Introduction to Computer Science and Programming

The Computer – A Brief History• Evolution in Computers

- started with external wires - moved to punch cards - introduction of CRT Monitors (direct input via typing) - introduction of Personal Computers - but: what to do with them? - software for home and business – and games (text based) - creation of sound cards - creation of video cards - faster, smaller more powerful equipment - laptops - computers become ubiquitous – are found everywhere… - Advanced Research Projects Agency, known as ARPA creates the arpanet incase of nuclear war - internet - World Wide Web - on August 29, 1997 (or April 21, 2011) skynet becomes self aware

Page 45: Introduction to Computer Science and Programming

A Traditional Computer

Central Processing UnitMemoryInput DevicesOutput DevicesSecondary Memory

Page 46: Introduction to Computer Science and Programming

A Traditional Computer• Central Processing Unit (CPU)

(also known as the processor)– Executes instructions

• Main Memory (also known as RAM)– Internal storage that holds the

programs (instructions and data) currently being executed by the CPU

– Made up of electronic “on-off” switches,each of which represents 0 or 1 and iscalled a bit (binary digit)

– It’s volatile (information stored in it is not retained when power is turned off)

Page 47: Introduction to Computer Science and Programming

A Traditional Computer• Secondary Memory : hard disks, CDs,

DVDs, USB sticks– Provide long-term (persistent) storage

for programs and other information– Organized as files, each of which has

a file name and a folder (directory)that contains it.

• Input/Output (I/O) units: keyboard, mouse, screen, printer, webcam, etc.– Used for communicating information from

the user to the computer and vice versa

Page 48: Introduction to Computer Science and Programming

What is Programming ?• Programming is the process

of creating detailed instructions that a computer can execute to accomplish some task:a program

• It is much like:• Writing a recipe for your

favourite dish• Giving someone

directions to your house• Making a robot do what

you want

Page 49: Introduction to Computer Science and Programming

What is a program ?• Programs consist of– Instructions to perform a task– Data values used in performing the task

• Programs are written in a language that a computer can (eventually) understand …

public class HelloWorld {

public static void main(String[ ] args) {

System.out.println("Hello World!");

}

}

Page 50: Introduction to Computer Science and Programming

High Level Languages• Programmers usually write programs in high-

level languages– Examples:• Java, C, C++, C#, Visual Basic, Python, Scheme,

Lisp, Pascal, Fortran, etc. etc.– People-oriented: created to make it easier for

programmers to write programs that perform complicated tasks

– Machine independent: a program in a high level language is not written for any particular kind of computer (Intel, Mac, etc.)

Page 51: Introduction to Computer Science and Programming

High Level Languages– Example of a high-level language program

statement:

• But, computers do not understand high-level languages …

if ((numberOfStudents) > MAX_STUDENTS) { fullCourse = true;}

Page 52: Introduction to Computer Science and Programming

High Level Languages• A high-level language program needs to be translated

into a lower level language• Compiler : software (i.e. a program itself!) that

translates a high-level language program (source code) into a lower level language

• Example: a compiler for the high-level language C translates a C program into a machine language program (executable code)– Why? a computer can only execute machine language

instructions …

Page 53: Introduction to Computer Science and Programming

Machine Level Language• A machine language consists of the set of instructions

that a computer’s CPU can execute directly– Instructions to the CPU (to add, subtract, read, store,

etc.) are made up of patterns of 0’s and 1’s

– Machine dependent : each type of computer has its own machine language instruction set• So, is a C compiler machine dependent or machine

independent?

Page 54: Introduction to Computer Science and Programming

High-Level Language to Machine Language

Compiler

CPU

High-Level LanguageProgram (source code)

Machine LanguageProgram (executable code)

executed

Page 55: Introduction to Computer Science and Programming

Why Don’t We Just Use English?• English is good for

communication between two intelligent humans– Even then we sometimes don’t

understand each other!• Computers are not “intelligent”– They basically know how to add,

compare, store, and load– Programs are very detailed

instructions to a computer• Everything must be precise and

unambiguous !

Page 56: Introduction to Computer Science and Programming

Why Study Programming?• Let’s say I am a biologist…– I’ll use software packages– Why then do I need to study programming?• The applications being developed require expertise in

computer science and biology • The models being developed require biology;

implementing the models requires Computer Science• Studying programming facilitates communication

between fields such as biology, chemistry, physics, math, engineering, medicine, business, geography, sociology, art, music, …and Computer Science