High-Level Programming Languages

Slides:



Advertisements
Similar presentations
An Introduction to Programming General Concepts. What is a program? A program is an algorithm expressed in a programming language. programming language.
Advertisements

Programming Languages and Paradigms
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Chapter 1: Introduction
1 Chapter 1 Introduction to Object-Oriented Programming.
Chapter 1 Introduction to Object- Oriented Programming and Problem Solving.
Computers: Tools for an Information Age
Chapter 8 High-Level Programming Languages Nell Dale John Lewis.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
11/1/06 1 Hofstra University, CSC005 Chapter 8 (Part 3) High Level Programming Languages.
Chapter 1 Program Design
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Chapter 8: Introduction to High-Level Language Programming Invitation to Computer Science, C++ Version, Fourth Edition.
Object-Oriented Design and High-Level Programming Languages
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Chapter 9 High-Level Programming Languages: C++. Chapter Goals Describe the expectations of high level languages Distinguish between functional design.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Invitation to Computer Science 5th Edition
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
High-Level Programming Languages: C++
Chapter 8 High-Level Programming Languages. 2 Compilers High-level language A language that provides a richer (more English like) set of instructions.
Chapter 9 Object-Oriented Design and High-Level Programming Languages.
O BJECT O RIENTATION F UNDAMENTALS Prepared by: Gunjan Chhabra.
CIS Computer Programming Logic
Problem Solving and Algorithms
Flow of Control. 2 Control Structures Control structure: An instruction that determines the order in which other instructions in a program are executed.
Chapters 7, 8, & 9 Quiz 3 Review 1. 2 Algorithms Algorithm A set of unambiguous instructions for solving a problem or subproblem in a finite amount of.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
Chapter 9 Programming Languages
Chapter 6 Programming Languages. © 2005 Pearson Addison-Wesley. All rights reserved 6-2 Chapter 6: Programming Languages 6.1 Historical Perspective 6.2.
CPS120: Introduction to Computer Science
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Chapter 6 Programming Languages © 2007 Pearson Addison-Wesley. All rights reserved.
CPS120: Introduction to Computer Science Decision Making in Programs.
CPS120: Introduction to Computer Science Functions.
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Copyright © 2015 Pearson Education, Inc. Chapter 6: Programming Languages.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
Chapter 8 High-Level Programming Languages. 2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is.
Chapter 9 ProgrammingLanguages.  Describe the evolution of programming languages from machine language to high-level languages.  Understand how a program.
Introduction to OOP CPS235: Introduction.
CPS120: Introduction to Computer Science Variables and Constants.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
CPS120 Introduction to Computer Science High Level Language: Paradigms.
Programming Languages 2nd edition Tucker and Noonan
CSCI-235 Micro-Computer Applications
An Introduction to Programming
Developing Applications
Computer Programming.
Chapter 8: Introduction to High-Level Language Programming
High Level Programming Languages
Chapter 6: Programming Languages
Low Level Programming Languages
Overview of Programming Paradigms
Flow of Control.
The Data Element.
An Introduction to Programming
The Data Element.
Presentation transcript:

High-Level Programming Languages Chapter 8 High-Level Programming Languages

Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation, and execution Name four distinct programming paradigms and name a language characteristic of each Describe the following constructs: stream input and output, selection, looping, and subprograms

Chapter Goals Construct Boolean expressions and describe how they are used to alter the flow of control of an algorithm Define the concepts of a data type and strong typing Explain the concept of a parameter and distinguish between value and reference parameters

Chapter Goals Describe two composite data-structuring mechanisms Name, describe, and give examples of the three essential ingredients of an object-oriented language

Compilers High-level language A language that provides a richer (more English like) set of instructions Compiler A program that translates a high-level language program into machine code

Compilers How does this differ from the assembly process? Figure 8.1 Compilation process

Interpreters Interpreter A translating program that translates and executes the statements in sequence Assembler or compiler produce machine code as output, which is then executed in a separate step An interpreter translates a statement and then immediately executes the statement Interpreters can be viewed as simulators

Java Introduced in 1996 and became instantly popular Portability was of primary importance Java is compiled into a standard machine language called Bytecode A software interpreter called the JVM (Java Virtual Machine) takes the Bytecode program and executes it

Do you understand the difference? Portability Portability The ability of a program to be run on different machines Compiler portability A program in a standardized language can be compiled and run on any machine that has the appropriate compiler Bytecode portability A program translated into Bytecode can be run on any machine that has a JVM Do you understand the difference?

Portability Figure 8.2 Portability provided by standardized languages versus interpretation by Bytecode

Portability Figure 8.2 Portability provided by standardized languages versus interpretation by Bytecode

Programming Language Paradigms Imperative or procedural model Program describes the processing FORTRAN, COBOL, BASIC, C, Pascal, Ada, and C++ Functional model Program is written terms of mathematical functions LISP, Scheme (a derivative of LISP), and ML

Programming Language Paradigms Logic model Program consists of facts about objects and rules that question the relationships among facts PROLOG Object-oriented model Program consists of a set of objects and the interactions among the objects Smalltalk and Simula C++ is as an imperative language with some object-oriented features Java is an object-oriented language with some imperative features

Programming Language Paradigms We examine procedural and object-oriented languages in the rest of this chapter by looking at the functionality provided in these languages We give examples in different languages to show how syntax used to provide the functionality

Functionality of Imperative Languages Sequence Executing statements in sequence until an instruction is encountered that changes this sequencing Selection Deciding which action to take Iteration (looping) Repeating an action Do these concepts sound familiar? Let's review them.

Boolean Expressions Boolean expression A sequence of identifiers, separated by compatible operators, that evaluates to true or false A Boolean expression can be A Boolean variable An arithmetic expression followed by a relational operator followed by an arithmetic expression A Boolean expression followed by a Boolean operator followed by a Boolean expression

Boolean Expressions Variable A location in memory that is referenced by an identifier that contains a data value Thus, a Boolean variable is a location in memory that can contain either true or false

Remember the relational operators? Boolean Expressions Remember the relational operators? List them!

Strong Typing Data type A description of the set of values and the basic set of operations that can be applied to values of the type Strong typing The requirement that only a value of the proper type can be stored into a variable

Data Types Integer numbers Real numbers Characters Boolean values Strings Give examples of each

Integers What determines the range of an integer value? Is the range of an integer value the same in all languages? What operations can be applied to integers?

Reals How are real values like integer values? How do real values differ from integer values?

Characters Do you remember ASCII? Extended ASCII? UNICODE? How many characters in Extended ASCII? How many characters in UNICODE? What does a relational operator between two characters mean?

Boolean and Strings What values can a Boolean variable be? For what are Boolean expressions used? What is a string? What operations can be applied to strings?

Declarations Declaration A statement that associates an identifier with a variable, an action, or some other entity within the language that can be given a name; the programmer can refer to that item by name Reserved word A word in a language that has special meaning Case-sensitive Uppercase and lowercase letters are considered the same

Declaration Example

Assignment statement Assignment statement An action statement (not a declaration) that says to evaluate the expression on the right-hand side of the symbol and store that value into the place named on the left-hand side Named constant A location in memory, referenced by an identifier, that contains a data value that cannot be changed Remember?

Input/Output Structures Pseudocode algorithms used the expressions Read or Get and Write or Print High-level languages view input data as a stream of characters divided into lines Key to the processing The data type determines how characters are to be converted to a bit pattern (input) and how a bit pattern is to be converted to characters (output)

Input/Output Structures Read name, age, hourlyWage name is a string; age is an integer; hourlyWage is a real The data must be a string, an integer, and a real in that order.

Control Structures Control structure An instruction that determines the order in which other instructions in a program are executed Can you name the ones we defined in the functionality of pseudocode?

Selection Statements Figure 8.3 Flow of control of if statement

Selection Statements The if statement allows the program to test the state of the program variables using a Boolean expression

Blocks Note the symbols used to indicate blocks in each language

Why does this work correctly? Cascading Ifs If (temperature > 90) Write "Texas weather: wear shorts" Else If (temperature > 50) Write "A little chilly: wear a light jacket" Else If (temperature > 32) Write "Philadelphia weather: wear a heavy coat" Else Write "Stay inside" Why does this work correctly?

Looping Statements Figure 8.4 Flow of control of while statement

Looping Statements A count-controlled loop Set sum to 0 Set count to 1 While (count <= limit) Read number Set sum to sum + number Increment count Write "Sum is " + sum Why is it called a count-controlled loop?

Looping Statements

Looping Statements An event-controlled loop Set sum to 0 Set allPositive to true While (allPositive) Read number If (number > 0) Set sum to sum + number Else Set allPositive to false Write "Sum is " + sum Why is it called an event-conrolled loop? What is the event?

Subprogram Statements We can give a section of code a name and use that name as a statement in another part of the program When the name is encountered, the processing in the other part of the program halts while the named code is executed Remember?

Subprogram Statements What if the subprogram needs data from the calling unit? Parameters Identifiers listed in parentheses beside the subprogram declaration; sometimes called formal parameters Arguments Identifiers listed in parentheses on the subprogram call; sometimes called actual parameters

Subprogram Statements Figure 8.5 Subprogram flow of control

Subprogram Statements Figure 8.5 Subprogram flow of control

Subprogram Statements Value parameter A parameter that expects a copy of its argument to be passed by the calling unit Reference parameter A parameter that expects the address of its argument to be passed by the calling unit

Subprogram Statements Think of arguments as being placed on a message board

Subprogram Statements

Recursion Recursion The ability of a subprogram to call itself Base case The case to which we have an answer General case The case that expresses the solution in terms of a call to itself with a smaller version of the problem

Recursion For example, the factorial of a number is defined as the number times the product of all the numbers between itself and 0: N! = N * (N  1)! Base case Factorial(0) = 1 (0! is 1) General Case Factorial(N) = N * Factorial(N-1)

Asynchronous Processing Not synchronized with the program's action Clicking has become a major form of input to the computer Mouse clicking is not within the sequence of the program A user can click a mouse at any time during the execution of a program

Composite Data Types Records A named heterogeneous collection of items in which individual items are accessed by name Arrays A named homogeneous collection of items in which an individual item is accessed by its position (index) within the collection

Composite Data Types Declare Record

Declare record variable Composite Data Types Declare record variable Use record variable

Composite Data Types An Array Figure 8.8 Array variable tenThings accessed from 0..9

Composite Data Types Declare Array

Composite Data Types Access an Array

Functionality of Object-Oriented Languages Remember the definitions from Chapter 6? Encapsulate Object class Object in problem-solving phase Object in implementation phase Class in implementation phase Instantiate Don't worry! We'll review these concepts

Review Object class (problem-solving phase) A description of a group of objects with similar properties and behaviors Object (problem-solving phase) An entity or thing that is relevant in the context of a problem Instantiate Create an object from a class

Review Encapsulation A language feature that enforces information hiding (second definition) Class (implementation phase) A language construct that is a pattern for an object and provides a mechanism for encapsulating the properties and actions of the object class Object (implementation phase) An instance of a class

Review Remember the pattern? From problem to general description to class definition to program

Inheritance and Polymorphism A construct that fosters reuse by allowing an application to take an already-tested class and derive a class from it that inherits the properties the application needs Polymorphism The ability of a language to have duplicate method names in an inheritance hierarchy and to apply the method that is appropriate for the object to which the method is applied

Inheritance and Polymorphism Inheritance and polymorphism work together How? They combine to allow the programmer to build useful hierarchies of classes that can be put into a library to be reused in different applications