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

View by Category
About This Presentation



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:


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

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

Chapter 9 Introduction to High-Level Language
  • 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

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

  • 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

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

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

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
  • Assembly language is machine specific.
  • Statements are not English like ( although they
    are closer than binary).

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

High-level Languages
  • High-level programming languages
  • Called third-generation languages
  • Created to overcome deficiencies of assembly
  • 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

High-level Languages (continued)
  • Expectations of a high-level language program
  • 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

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

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

(No Transcript)
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

Two Examples in Five-Part Harmony
  • Examine similarities and differences of the
    languages (Ada, C, C, Java, Python) through
  • 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

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)

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

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

Figure 9.9 Ada converging-pointers algorithm
(part 1)
Figure 9.9 (continued) Ada converging-pointers
algorithm (part 2)
Figure 9.9 (continued) Ada converging-pointers
algorithm (part 3)
Figure 9.9 (continued) Ada converging-pointers
algorithm (part 4)
Figure 9.10 C converging-pointers algorithm
(part 1)
Figure 9.10 (continued) C converging-pointers
algorithm (part 2)
Figure 9.10 (continued) C converging-pointers
algorithm (part 3)
Figure 9.11 C converging-pointers algorithm
(part 1)
Figure 9.11 (continued) C converging-pointers
algorithm (part 2)
Figure 9.11 (continued) C converging-pointers
algorithm (part 3)
Figure 9.11 (continued) C converging-pointers
algorithm (part 4)
Figure 9.12 Java converging-pointers algorithm
(part 1)
Figure 9.12 (continued) Java converging-pointers
algorithm (part 2)
Figure 9.12 (continued) Java converging-pointers
algorithm (part 3)
Figure 9.12 (continued) Java converging-pointers
algorithm (part 4)
Figure 9.13 Python converging-pointers algorithm
(part 1)
Figure 9.13 (continued) Python converging-pointers
algorithm (part 2)
(No Transcript)
Feature Analysis
  • Compare language features, and compare to
  • Syntax
  • Describing data or variables
  • Grouping things, making loops or conditionals
  • Semantics
  • Meaning of function call
  • Meaning of operations
  • Deeper structure
  • Modules, classes, scope

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

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

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

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
  • 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.

The Software Life Cycle (continued)
  • Coding- translate designs into computer code
  • 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

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

(No Transcript)
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

(No Transcript)
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

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

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
  • Logic errors errors in the algorithm itself

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
  • 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

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

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

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

  • 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

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

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

  • Figure 9.2 A Simple Java Program

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

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

  • Figure 8.4
  • Some of the Java Primitive Data Types

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
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

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

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

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

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)

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

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

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

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)

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

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

  • Figure 9.13
  • If-Else with Empty Else

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

  • Figure 9.15
  • While Loop

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

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

  • Figure 9.22 Structure Charts

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

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
  • Overall form of a method invocation
  • class-identifier.method-identifier(argument list)

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

  • Some Java Terminology

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

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

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

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

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

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

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

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

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

  • 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

  • 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

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