19
Copyright Copyright ©2005 ©2005 Department of Computer & Information Science Department of Computer & Information Science Introducing Introducing Programming Programming

Copyright ©2005 Department of Computer & Information Science Introducing Programming

Embed Size (px)

Citation preview

Page 1: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

Introducing ProgrammingIntroducing Programming

Page 2: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

GoalsGoals

By the end of this lecture you By the end of this lecture you should …should …

• Understand what a program is.Understand what a program is.• Understand the differences among Understand the differences among

machine, assembly and high-level machine, assembly and high-level languageslanguages

• Understand how programming Understand how programming languages evolved.languages evolved.

Page 3: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

What is a Program?What is a Program?

• Sets of instructions that get the Sets of instructions that get the computer to do somethingcomputer to do something

• Programs may be a few lines or Programs may be a few lines or millions of lines of codemillions of lines of code

• All instructions are translated, All instructions are translated, eventually, to machine language.eventually, to machine language.

Page 4: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

Programming TasksProgramming Tasks

• Each program has three distinct Each program has three distinct purposes:purposes:

1.1. To gather input data.To gather input data.

2.2. To manipulate that data.To manipulate that data.

3.3. To give meaningful information To give meaningful information back to the user (output).back to the user (output).

Page 5: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

Families of LanguagesFamilies of Languages

1.1. Machine LanguagesMachine Languages

2.2. Assembly LanguagesAssembly Languages

3.3. High Level Languages:High Level Languages:• Procedural LanguagesProcedural Languages• Object Oriented LanguagesObject Oriented Languages

Page 6: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

Machine LanguagesMachine Languages

• Machine language commands Machine language commands are comprised of binary digits are comprised of binary digits (bits – 1s and 0s) which are (bits – 1s and 0s) which are translated to electrical impulses translated to electrical impulses that get the computer to do that get the computer to do something.something.

• ““Native” language of computersNative” language of computers

Page 7: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

Assembly LanguagesAssembly Languages

• Assembly language commands are Assembly language commands are "shortcuts" for machine code that "shortcuts" for machine code that represent some basic commands. represent some basic commands. These commands still need to be These commands still need to be translated to machine language.translated to machine language.

• Assembly language commands are Assembly language commands are hard-coded into a specific hard-coded into a specific processor.processor.

Page 8: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

High Level LanguagesHigh Level Languages

• High level language commands High level language commands are very close, in syntax, to are very close, in syntax, to English, thus resulting in English, thus resulting in comparatively low error rate.comparatively low error rate.

• High level commands need to be High level commands need to be translated to machine language translated to machine language using an using an interpreterinterpreter or or compilercompiler … …

Page 9: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

Translation Using an Translation Using an Interpreter Interpreter

• Interpreters translate code into Interpreters translate code into machine language on a line-by-machine language on a line-by-line basis. line basis.

• Typically, the translation speed is Typically, the translation speed is comparatively quicker than a comparatively quicker than a compiler, but the execution compiler, but the execution speed is slower.speed is slower.

Page 10: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

Translation Using a Translation Using a CompilerCompiler

• Compiler translate code into Compiler translate code into machine language by translating machine language by translating the entire program at once. the entire program at once.

• Typically, the translation speed is Typically, the translation speed is comparatively slower than an comparatively slower than an interpreter, but the execution interpreter, but the execution speed is much quicker.speed is much quicker.

Page 11: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

Common OperationsCommon Operations

• All types of high level All types of high level languages share three families languages share three families of operations:of operations:

1.1. Sequential OperationsSequential Operations

2.2. Conditional OperationsConditional Operations

3.3. Looping OperationsLooping Operations

Page 12: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

Sequential OperationsSequential Operations

• Sequential operations are lines of Sequential operations are lines of code that execute in order.code that execute in order.

• Sequential operations are the Sequential operations are the default operations in default operations in programming.programming.

Page 13: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

Conditional OperationsConditional Operations

• Conditional operations Conditional operations (sometimes called decision (sometimes called decision structures) alter the course of a structures) alter the course of a program based on the result of a program based on the result of a TRUE/FALSE test.TRUE/FALSE test.

• Programmers construct those Programmers construct those tests using relational operators.tests using relational operators.

Page 14: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

Looping OperationsLooping Operations

• Looping operations are those Looping operations are those structures in which code repeats structures in which code repeats until a given condition is met.until a given condition is met.

• Similar to conditional operations, Similar to conditional operations, programmers construct looping programmers construct looping operations using relational operations using relational operators.operators.

Page 15: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

Procedural LanguagesProcedural Languages

• Early high-level languages were Early high-level languages were procedural in nature.procedural in nature.

• The focus of procedural The focus of procedural languages was on structure.languages was on structure.

• Examples include QuickBasic, Examples include QuickBasic, Fortran, Pascal, and early Fortran, Pascal, and early versions of Visual Basic.versions of Visual Basic.

Page 16: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

Object-Oriented LanguagesObject-Oriented Languages

• Object-oriented languages are a more Object-oriented languages are a more recent development, where the focus recent development, where the focus is on data (the “Primacy of Data”). is on data (the “Primacy of Data”).

• In OOP, programmers include data and In OOP, programmers include data and the ways to manipulate that data into the ways to manipulate that data into one entity – the object. Examples one entity – the object. Examples include Java, C# and VB.NET.include Java, C# and VB.NET.

Page 17: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

SummarySummary

• A program is a set of instructions to A program is a set of instructions to get your computer to do something.get your computer to do something.

• All programs have three basic types All programs have three basic types of instructions: (1) input of instructions: (1) input instructions; (2) processing instructions; (2) processing instructions and (3) output instructions and (3) output instructions.instructions.

Page 18: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

SummarySummary

• Machine languages are comprised Machine languages are comprised of 1s and 0s and are the native of 1s and 0s and are the native languages of computers.languages of computers.

• Assembly language commands Assembly language commands are tied to specific processors are tied to specific processors and represent shortcuts to and represent shortcuts to machine language.machine language.

Page 19: Copyright ©2005  Department of Computer & Information Science Introducing Programming

Copyright Copyright ©2005 ©2005 Department of Computer & Information ScienceDepartment of Computer & Information Science

SummarySummary

• High level languages are close, High level languages are close, in syntax, to English. To translate in syntax, to English. To translate high-level languages, we must high-level languages, we must use compilers or interpreters.use compilers or interpreters.

• All high-level languages share All high-level languages share three basic groups of operations: three basic groups of operations: sequential, conditional & looping.sequential, conditional & looping.