Title: Introduction%20to%20High-Level%20Language%20Programming
1Chapter 9 Introduction to High-Level Language
Programming
1
2Objectives
- 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
3Objectives
- Managing complexity
- Object-oriented programming
- Graphical programming
- The big picture software engineering
4Objectives
- 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
5Objectives (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
6Where 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
7Some 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).
8The 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
9High-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
10High-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
11The 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
12The 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)
14A 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
15Two 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
16Two 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)
17Two 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)
23Two Examples in Five-Part Harmony (continued)
- Second example Data Cleanup, Converging Pointers
- Focus on loops and conditionals
24Figure 9.9Ada converging-pointers algorithm
(part 1)
25Figure 9.9 (continued)Ada converging-pointers
algorithm (part 2)
26Figure 9.9 (continued)Ada converging-pointers
algorithm (part 3)
27Figure 9.9 (continued)Ada converging-pointers
algorithm (part 4)
28Figure 9.10C converging-pointers algorithm
(part 1)
29Figure 9.10 (continued)C converging-pointers
algorithm (part 2)
30Figure 9.10 (continued)C converging-pointers
algorithm (part 3)
31Figure 9.11C converging-pointers algorithm
(part 1)
32Figure 9.11 (continued)C converging-pointers
algorithm (part 2)
33Figure 9.11 (continued)C converging-pointers
algorithm (part 3)
34Figure 9.11 (continued)C converging-pointers
algorithm (part 4)
35Figure 9.12Java converging-pointers algorithm
(part 1)
36Figure 9.12 (continued)Java converging-pointers
algorithm (part 2)
37Figure 9.12 (continued)Java converging-pointers
algorithm (part 3)
38Figure 9.12 (continued)Java converging-pointers
algorithm (part 4)
39Figure 9.13Python converging-pointers algorithm
(part 1)
40Figure 9.13 (continued)Python converging-pointers
algorithm (part 2)
41(No Transcript)
42Feature 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
43Meeting 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
44Meeting 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
45Meeting 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
46The 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.
47The 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
48The 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)
50The 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)
52The 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
53The 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
54The 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
55The 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
56The 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
57The 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
58The 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
59Summary
- 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
60Introduction 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
61Introduction 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
63Running 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
64Virtual 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
66Virtual 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
67Statement 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
68Statement 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
69Input 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
70Input Statements (continued)
- Methods
- readInt
- readDouble
- readChar
- Syntax
- variable1 Console.readInt(prompt)
- variable2 Console.readDouble(prompt)
- variable3 Console.readChar(prompt)
71Output 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)
72The Assignment Statement
- General form
- variable expression
- Expression is evaluated first the result is
written into the memory location named on the left
73The 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
74Control 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
75Control 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)
76Control 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
79Control 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 81Meeting 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
82Managing 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
84Using Methods
- Method
- A module of code in Java
- Named using ordinary Java identifiers
- By custom, name starts with a lowercase letter
85Using 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)
86Writing 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 88Object-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
89OOP - 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
90Java 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
91Java 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
92What Have We Gained?
- Two major advantages of OOP
- Software reuse
- A more natural world view
93Graphical 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
94Graphics 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
95Graphics 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
96Meeting 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
97Summary
- 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
98Summary
- 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
99Summary (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