Introduction%20to%20High-Level%20Language%20Programming - PowerPoint PPT Presentation

View by Category
About This Presentation
Title:

Introduction%20to%20High-Level%20Language%20Programming

Description:

Chapter 9: The Tower of Babel. Invitation to Computer Science, Java Version, ... Developed in 1959 1960 by a group headed by Grace Hopper of the U.S. Navy ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 100
Provided by: paru7
Learn more at: http://faculty.sjcny.edu
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Introduction%20to%20High-Level%20Language%20Programming


1
Chapter 9 Introduction to High-Level Language
Programming
1
2
Objectives
  • In this chapter, you will continue to learn about
    the progression from assembly language to
    high-level languages
  • Introduction to Java
  • Virtual data storage
  • Statement types
  • Meeting expectations

3
Objectives
  • Managing complexity
  • Object-oriented programming
  • Graphical programming
  • The big picture software engineering

4
Objectives
  • After studying this chapter, students will be
    able to
  • Explain the advantages of high-level programming
    languages over assembly language
  • Describe the general process of translation from
    high-level source code to object code
  • Compare and contrast the ways languages express
    basic operations (Ada, C, C, Java, and Python)
  • Explain the Favorite Number and Data Cleanup
    examples for each programming language

5
Objectives (continued)
  • After studying this chapter, students will be
    able to
  • Explain why the software development life cycle
    is necessary for creating large software programs
  • List the steps in the software development life
    cycle, explain the purpose of each, and describe
    the products of each
  • Explain how agile software development differs
    from the traditional waterfall model

6
Where Do We Stand?
  • Early days of computing
  • Programmers were satisfied with assembly language
  • Programs mostly written by very technically
    oriented people
  • Later decades
  • Programmers demanded a more comfortable
    programming environment
  • Programs were now also written by non-techie
    people

7
Some Disadvantages of Assembly Language
  • Programmer manually managed the movement of
    data in memory locations
  • Programmer must break down a task into smaller
    subtasks at the level of individual memory
    locations
  • Assembly language is machine specific.
  • Statements are not English like ( although they
    are closer than binary).

8
The Language Progression
  • Assembly language improves on machine language
  • Assembly language disadvantages
  • Programmer must manage movement of data among
    memory locations and registers
  • Microscopic view of task
  • Machine specific languages
  • Far from natural language

9
High-level Languages
  • High-level programming languages
  • Called third-generation languages
  • Created to overcome deficiencies of assembly
    language
  • Expectations of a high-level language program
  • Programmer need not manage details of movement of
    data items within memory or exactly where those
    items are stored

10
High-level Languages (continued)
  • Expectations of a high-level language program
    (continued)
  • Programmer can take a macroscopic view of tasks
    primitive operations can be larger
  • Programs will be portable
  • Programming statements will be closer to standard
    English and use standard mathematical notation

11
The Language Progression (continued)
  • High-level programming languages improve on
    assembly language
  • Expectations
  • Programmer need not manage data in memory
  • Macroscopic view of tasks (e.g., add B and C)
  • Programs portable from one machine to another
  • Program statements closer to natural language and
    math notation
  • Third-generation languages

12
The Language Progression (continued)
  • Need translator from high level languages
  • Compiler converts source code to assembly code or
    similar
  • Assembler or other translator creates object code
  • Code libraries contain object code for useful
    tools
  • Linker integrates multiple files of object code
    to create an executable module

13
(No Transcript)
14
A Family of Languages
  • Procedural (imperative) languages
  • Popular kind of programming language
  • Programs are sequences of statements
  • Examples Ada, C, C, Java, and Python
  • Same underlying philosophy/model
  • Variations in
  • Syntax how statements are written
  • Semantics meaning of statements

15
Two Examples in Five-Part Harmony
  • Examine similarities and differences of the
    languages (Ada, C, C, Java, Python) through
    examples
  • Favorite Number
  • Ask user for her favorite number, tell her that
    your favorite number is one greater than hers
  • Data Cleanup
  • Converging Pointers algorithm from Chapter 3

16
Two Examples in Five-Part Harmony
  • Focus on big picture, not grasping every detail
  • Look for commonalities across languages
  • Look for these identifiable patterns
  • Creation/declaration of variables
  • Assignment of variables to values
  • Arithmetic operations
  • Reading input and writing output
  • Markers for beginning and end of sections
  • Conditionals (if statements)
  • Loops (for or while loops)

17
Two Examples in Five-Part Harmony (continued)
  • First example Favorite Number
  • Simple program, no loops or conditionals
  • Focus on input/output, variable creation and
    assignment

18
(No Transcript)
19
(No Transcript)
20
(No Transcript)
21
(No Transcript)
22
(No Transcript)
23
Two Examples in Five-Part Harmony (continued)
  • Second example Data Cleanup, Converging Pointers
  • Focus on loops and conditionals

24
Figure 9.9 Ada converging-pointers algorithm
(part 1)
25
Figure 9.9 (continued) Ada converging-pointers
algorithm (part 2)
26
Figure 9.9 (continued) Ada converging-pointers
algorithm (part 3)
27
Figure 9.9 (continued) Ada converging-pointers
algorithm (part 4)
28
Figure 9.10 C converging-pointers algorithm
(part 1)
29
Figure 9.10 (continued) C converging-pointers
algorithm (part 2)
30
Figure 9.10 (continued) C converging-pointers
algorithm (part 3)
31
Figure 9.11 C converging-pointers algorithm
(part 1)
32
Figure 9.11 (continued) C converging-pointers
algorithm (part 2)
33
Figure 9.11 (continued) C converging-pointers
algorithm (part 3)
34
Figure 9.11 (continued) C converging-pointers
algorithm (part 4)
35
Figure 9.12 Java converging-pointers algorithm
(part 1)
36
Figure 9.12 (continued) Java converging-pointers
algorithm (part 2)
37
Figure 9.12 (continued) Java converging-pointers
algorithm (part 3)
38
Figure 9.12 (continued) Java converging-pointers
algorithm (part 4)
39
Figure 9.13 Python converging-pointers algorithm
(part 1)
40
Figure 9.13 (continued) Python converging-pointers
algorithm (part 2)
41
(No Transcript)
42
Feature Analysis
  • Compare language features, and compare to
    pseudocode
  • Syntax
  • Describing data or variables
  • Grouping things, making loops or conditionals
  • Semantics
  • Meaning of function call
  • Meaning of operations
  • Deeper structure
  • Modules, classes, scope

43
Meeting Expectations
  • Programmer need not manage data in memory
  • In each language, programmers must declare names
    (and sometimes types) for variables
  • Program manages movement of data associated with
    a given variable name
  • Macroscopic view of tasks (e.g., add B and C)
  • Languages provide statements for high-level math
  • Details of conditionals and loops hidden

44
Meeting Expectations (continued)
  • Programs portable from one machine to another
  • Programming languages are standardized
  • Compiled languages (Ada, C, Java, C)
  • Compilers written for particular platform support
    standard, and translate to machine-specific forms
  • Programmers distribute executable or low level
    bytecode, not source
  • Interpreted languages (like Python) require an
    interpreter on each machine, and distribute
    source code

45
Meeting Expectations (continued)
  • Program statements closer to natural language and
    math notation
  • Math notation fairly standard across languages
  • Conditionals and loops are closer to natural
    language than assembly

46
The Software Life Cycle
  • Each step in the software development life cycle
  • Has a specific purpose and activities
  • Should result in a written document
  • The feasibility study evaluates project and
    compares the costs and benefits of various
    solutions
  • Problem specification- clear, concise statement
    of the problem
  • Program design (divide and conquer or top-down
    approach)- plan what is to be done, select
    algorithms, etc.

47
The Software Life Cycle (continued)
  • Coding- translate designs into computer code
    (program)
  • Debugging- locate and correct errors ( syntax,
    run-time and logic errors)
  • Testing, verification, and benchmarking (running
    on many data sets)
  • Documentation- all the written material that
    makes a program understandable and usable
  • Maintenance- adapting and modifying

48
The Big Picture Software Engineering
  • Software development life cycle
  • Process required to create large-scale software
    projects
  • 25 to 40 of time spent on problem specification
    and program design
  • 10 to 20 of time spent on initial
    implementation
  • 40 to 65 of time spent reviewing, modifying,
    fixing, and improving software

49
(No Transcript)
50
The Big Picture Software Engineering (continued)
  • Large software scale issues
  • Orders of magnitude larger than beginner programs
  • Compare one sentence to 300-page novel
  • Software engineering
  • Development of large software projects
  • Requires collaboration, management, organization
  • Formal processes for development

51
(No Transcript)
52
The Big Picture Software Engineering (continued)
  • Life cycle
  • Feasibility study
  • Assess costs and benefits
  • Consider alternatives
  • Problem specification
  • Clear statement of problem to be solved
  • Problem specification document

53
The Big Picture Software Engineering (continued)
  • Life cycle
  • Program design phase
  • Divide-and-conquer, top-down decomposition
  • Break problem into tasks and subtasks
  • Program design document
  • Algorithm selection/development and analysis
  • Choose or design an algorithm for each subtask
  • Analyze efficiency
  • Document describe algorithm in pseudocode,
    provide efficiency analysis, and rationale

54
The Big Picture Software Engineering (continued)
  • Life cycle
  • Coding
  • Translate pseudocode and design into working code
  • Better design easier coding
  • Debugging
  • Correcting program errors
  • Syntax errors ungrammatical code statements
  • Runtime errors illegal operations like
    divide-by-zero
  • Logic errors errors in the algorithm itself

55
The Big Picture Software Engineering (continued)
  • Life cycle
  • Testing, verification, and benchmarking
  • Empirical testing develop suite of tests to
    check correctness
  • Unit testing tests on each module/subtask
  • Integration testing test how modules work
    together
  • Regression testing when changes occur, test to
    be sure the change did not introduce errors
  • Program verification prove code correct
  • Benchmarking check performance on inputs

56
The Big Picture Software Engineering (continued)
  • Life cycle
  • Documentation
  • Internal documentation comments in code
  • External documentation all earlier documents
    (problem spec, program design, etc.)
  • Technical documentation information for
    programmers to understand the code
  • User documentation help users run programs
  • Program maintenance
  • Add features, fix bugs, improve performance

57
The Big Picture Software Engineering Modern
Environments
  • Integrated development environment (IDE)
  • speed up program development by providing
  • Program editor
  • File manager
  • Compiler/interpreter
  • Debugger
  • Prototype tools
  • Version and document management

58
The Big Picture Software Engineering (continued)
  • Agile software development
  • Alternative to the waterfall model shown before
  • Philosophy
  • Problem specification is never done
  • Change is expected, respond in agile way
  • Customer/user involved throughout process
  • Pair programming
  • Two programmers, one computer
  • Code writer and observer roles, switched
    frequently

59
Summary
  • High-level languages
  • Hide details of memory and hardware operations
  • Enable code portability
  • Shift code statements toward natural language and
    math notation
  • Programming languages may share an underlying
    philosophy, but vary in syntax and semantics
  • Ada, C, C, Java, and Python are all procedural
    languages

60
Introduction to Java A Simple Java Program
  • Comments
  • Give information to human readers of code
  • Class header
  • Announces that a class is about to be defined
  • Class
  • A collection of methods
  • Method
  • A section of code that performs a service

61
Introduction to Java Simple Java Code
  • int num1 2
  • int num2 4
  • int sum
  • sum num1 num2
  • System.out.println ( The sum is sum)
  • // This outputs the value 6

62
  • Figure 9.2 A Simple Java Program

63
Running a Java Program
  • File containing the Java code
  • Same name as the class
  • File extension .java
  • Example TravelPlanner.java
  • To run a Java program
  • Program compiled
  • Example file TravelPlanner.class created
  • Translation to object code linking, loading, and
    execution of the program

64
Virtual Data Storage
  • Identifiers
  • Names in a programming language
  • Keyword
  • Has a special meaning in Java
  • Java case-sensitive, free-format language
  • Variable
  • A named location in memory
  • Must be declared before it can be used

65
  • Figure 8.4
  • Some of the Java Primitive Data Types

66
Virtual Data Storage (continued)
  • An array
  • Groups together a collection of memory locations,
    all storing data of the same type

Figure 8.5 A 12-Element Array Hits
67
Statement Types
  • Input/output statement
  • Input statement
  • Collects a specific value from the user for a
    variable within the program
  • Output statement
  • Writes a message or the value of a program
    variable to the users screen or to a file

68
Statement Types (continued)
  • Assignment statement
  • Assigns a value to a program variable
  • Control statement
  • Directs the flow of control
  • Can cause it to deviate from the usual sequential
    flow

69
Input Statements
  • A prompt
  • A message that tells the user what kind of input
    the program wants
  • Console class
  • Not a standard Java class written for this book
  • Can be used to handle both the prompt and the
    retrieval of the value in one statement

70
Input Statements (continued)
  • Methods
  • readInt
  • readDouble
  • readChar
  • Syntax
  • variable1 Console.readInt(prompt)
  • variable2 Console.readDouble(prompt)
  • variable3 Console.readChar(prompt)

71
Output Statements
  • Output to the screen
  • System.out.println(string)
  • The string can be
  • Empty
  • System.out.println( )
  • Literal string
  • System.out.println("Here's your answer." )
  • Composed of two or more items
  • System.out.println(The sum is " sum)

72
The Assignment Statement
  • General form
  • variable expression
  • Expression is evaluated first the result is
    written into the memory location named on the left

73
The Assignment Statement (continued)
  • Examples
  • B 2
  • Suppose that B is an integer variable
  • A B C
  • Suppose that A, B, and C are integer variables
  • Letter 'm'
  • Suppose that Letter is a variable of type char

74
Control Statements
  • Types of control mechanisms
  • Sequential
  • Instructions are executed in order
  • Conditional
  • The choice of which instructions to execute next
    depends on some condition
  • Looping
  • A group of instructions may be executed many times

75
Control Statements (continued)
  • Default mode of execution sequential
  • Conditional flow of control
  • Evaluation of a Boolean condition (also called a
    Boolean expression)
  • The programming statement to execute next
    determined based on the value of the Boolean
    condition (true or false)

76
Control Statements (continued)
  • Conditional flow of control (continued)
  • if-else statement
  • if (Boolean condition)
  • S1
  • else
  • S2
  • if variation of the if-else statement
  • if (Boolean condition)
  • S1

77
  • Figure 9.12
  • Conditional Flow of Control -(If-Else)

78
  • Figure 9.13
  • If-Else with Empty Else

79
Control Statements (continued)
  • Looping (iteration)
  • The loop body may be executed repeatedly based on
    the value of the Boolean condition
  • while statement
  • while (Boolean condition)
  • S1

80
  • Figure 9.15
  • While Loop

81
Meeting Expectations
  • Java meets the four expectations for a high-level
    programming language
  • Expectations
  • The programmer need not manage the details of the
    movement of data items within memory, nor pay any
    attention to where specifically they are stored
  • The programmer can take a macroscopic view of
    tasks, thinking at a higher level of
    problem-solving

82
Managing Complexity Divide and Conquer
  • Divide and conquer
  • Divide the problem into small pieces
  • In a computer program
  • Divide the code into modules or subprograms, each
    of which does some part of the overall task
  • Empower these modules to work together to solve
    the original problem

83
  • Figure 9.22 Structure Charts

84
Using Methods
  • Method
  • A module of code in Java
  • Named using ordinary Java identifiers
  • By custom, name starts with a lowercase letter

85
Using Methods (continued)
  • Two types of methods
  • void method
  • Does not pass any value back to the main method
  • nonvoid method
  • Returns a single new value back to the main
    method
  • Overall form of a method invocation
  • class-identifier.method-identifier(argument list)

86
Writing Methods
  • General form of the method header
  • scope-indicator return-indicator
    identifier(parameter list)
  • Arguments in Java are passed by value
  • A variable declared within a method can be used
    only within that method
  • Return statement
  • Syntax
  • return expression

87
  • Some Java Terminology

88
Object-Oriented Programming What Is It?
  • Object-oriented programming (OOP)
  • A program is a simulation of some part of the
    world that is the domain of interest
  • Each object is an example drawn from a class of
    similar objects

89
OOP - What Is It? (continued)
  • Key elements of OOP
  • Encapsulation
  • A class consists of its subtask modules and its
    properties, both components encapsulated with
    the class
  • Inheritance
  • Once a class A of objects is defined, a class B
    of objects can be defined as a subclass of A
  • Polymorphism
  • One name, the name of the service to be
    performed, has several meanings, depending on the
    class of the object providing the service

90
Java and OOP
  • Java is an object-oriented programming language
  • Static method
  • Can be invoked by giving the class name, a dot,
    the method name, and a list of arguments
  • Objects instances of a class
  • Instance variables properties
  • Instance methods services

91
Java and OOP (continued)
  • Syntax to request an object to invoke a method
  • object-identifier.method-identifier(argument
    list)
  • Calling object
  • The object that invokes a method

92
What Have We Gained?
  • Two major advantages of OOP
  • Software reuse
  • A more natural world view

93
Graphical Programming Graphics Hardware
  • Bitmapped display
  • The screen is made up of thousands of individual
    picture elements, or pixels, laid out in a
    two-dimensional grid
  • Frame buffer
  • Memory that stores the actual screen image
  • Terminal hardware displays the frame buffer value
    of every individual pixel on the screen

94
Graphics Software
  • Graphics library
  • Contains a collection of software routines that
    control the setting and clearing of pixels
  • Abstract Windowing Toolkit (AWT)
  • Contains routines that allow users to create
    powerful interfaces
  • Swing components
  • Even more powerful GUI components than AWT

95
Graphics Software (continued)
  • Graphics class
  • Contains drawing commands that allow you to
  • Draw geometric shapes (e.g., lines, rectangles,
    ovals, polygons)
  • Set, change, and define colors
  • Fill in or shade objects
  • Create text in a range of fonts and sizes
  • Produce graphs and charts

96
Meeting Expectations (continued)
  • Expectations (continued)
  • Programs written in high-level languages will be
    portable rather than machine-specific
  • Programming statements in a high-level language
  • Will be closer to standard English
  • Will use standard mathematical notation

97
Summary
  • In a high-level language, the programmer
  • Need not manage storage or movement of data
    values in memory
  • Can use more powerful and more natural-language-li
    ke program instructions
  • Can write a much more portable program
  • Java is an object-oriented, high-level
    programming language

98
Summary
  • In Java, an if-else statement can be used to
    create a conditional flow of control
  • In Java, a while loop can be used for iteration
  • Software life cycle the overall sequence of
    steps needed to complete a large-scale software
    project

99
Summary (continued)
  • Development of large software is a different kind
    of problem than writing a single algorithm
  • Software development life cycles are designed to
    manage large software development
  • Waterfall model starts with feasibility and
    problem specification and flows through debugging
    and testing
  • Agile development moves quickly through the
    design-implement-test cycle, repeating it many
    times for a single project
About PowerShow.com