close

Вход

Забыли?

вход по аккаунту

?

Chapter 8: Introduction to High

код для вставкиСкачать
Chapter 8: Introduction to
High-Level Language
Programming
Invitation to Computer Science,
Java Version, Third Edition
Objectives
In this chapter, you will learn about
пЃ®
Where do we stand?
пЃ®
High-level languages
пЃ®
Introduction to Java
пЃ®
Virtual data storage
пЃ®
Statement types
Invitation to Computer Science, Java Version, Third Edition
2
Objectives (continued)
пЃ®
Meeting expectations
пЃ®
Managing complexity
пЃ®
Object-oriented programming
пЃ®
Graphical programming
пЃ®
The big picture: Software engineering
Invitation to Computer Science, Java Version, Third Edition
3
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 “nontechie”
people
Invitation to Computer Science, Java Version, Third Edition
4
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
пЃ±
The programmer need not manage the details of
the movement of data items within memory nor
exactly where those items are stored
Invitation to Computer Science, Java Version, Third Edition
5
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
пЃ±
Program will be portable
пЃ±
Programming statements will be closer to
standard English and use standard mathematical
notation
Invitation to Computer Science, Java Version, Third Edition
6
Introduction to Java: A Simple Java
Program
пЃ®
Comments
пЃ±
пЃ®
Class header
пЃ±
пЃ®
Announces that a class is about to be defined
Class
пЃ±
пЃ®
Give information to human readers of code
A collection of methods
Method
пЃ±
A section of code that performs a service
Invitation to Computer Science, Java Version, Third Edition
7
Figure 8.2 A Simple Java Program
Invitation to Computer Science, Java Version, Third Edition
8
Running a Java Program
пЃ®
File containing the Java code
пЃ±
пЃ±
пЃ±
пЃ®
Same name as the class
File extension .java
Example: TravelPlanner.java
Running a Java program
пЃ±
Program compiled
пЃ®
пЃ±
Example: File TravelPlanner.class created
Translation to object code completed; program
linked, loaded, and executed
Invitation to Computer Science, Java Version, Third Edition
9
Virtual Data Storage
пЃ®
Identifiers
пЃ±
пЃ®
Names in a programming language
Keyword
пЃ±
Has a special meaning in Java
пЃ®
Java is a case-sensitive, free-format language
пЃ®
Variable
пЃ±
A named location in memory
пЃ±
Must be declared before it can be used
Invitation to Computer Science, Java Version, Third Edition
10
Figure 8.4
Some of the Java Primitive Data Types
Invitation to Computer Science, Java Version, Third Edition
11
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
Invitation to Computer Science, Java Version, Third Edition
12
Statement Types
пЃ®
Input/output statements
пЃ±
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 user’s screen or to a file
Invitation to Computer Science, Java Version, Third Edition
13
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
Invitation to Computer Science, Java Version, Third Edition
14
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
Invitation to Computer Science, Java Version, Third Edition
15
Input Statements (continued)
пЃ®
пЃ®
Methods
пЃ±
readInt
пЃ±
readDouble
пЃ±
readChar
Syntax
variable1 = Console.readInt(prompt);
variable2 = Console.readDouble(prompt);
variable3 = Console.readChar(prompt);
Invitation to Computer Science, Java Version, Third Edition
16
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("Give me" + 5);
Invitation to Computer Science, Java Version, Third Edition
17
The Assignment Statement
пЃ®
General form
variable = expression;
пЃ®
Expression is evaluated first; the result is written
into the memory location specified on the left
Invitation to Computer Science, Java Version, Third Edition
18
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
Invitation to Computer Science, Java Version, Third Edition
19
Control Statements
пЃ®
Types of control mechanisms
пЃ±
Sequential
пЃ®
пЃ±
Conditional
пЃ®
пЃ±
Instructions are executed in order
The choice of which instructions to execute next
depends on some condition
Looping
пЃ®
A group of instructions may be executed many
times
Invitation to Computer Science, Java Version, Third Edition
20
Control Statements (continued)
пЃ®
Sequential is default mode of execution
пЃ®
Conditional flow of control
пЃ±
Evaluation of a Boolean condition (also called a
Boolean expression)
пЃ±
The programming statement to execute next is
based on the value of the Boolean condition (true
or false)
Invitation to Computer Science, Java Version, Third Edition
21
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;
Invitation to Computer Science, Java Version, Third Edition
22
Figure 8.10
Conditional Flow of Control
(If-Else)
Invitation to Computer Science, Java Version, Third Edition
23
Figure 8.11
If-Else with Empty Else
Invitation to Computer Science, Java Version, Third Edition
24
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;
Invitation to Computer Science, Java Version, Third Edition
25
Figure 8.13
While Loop
Invitation to Computer Science, Java Version, Third Edition
26
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
Invitation to Computer Science, Java Version, Third Edition
27
Meeting Expectations (continued)
пЃ®
Expectations (continued)
пЃ±
The programmer can take a macroscopic view of
tasks, thinking at a higher level of problem solving
пЃ±
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
Invitation to Computer Science, Java Version, Third Edition
28
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
Invitation to Computer Science, Java Version, Third Edition
29
Figure 8.20 Structure Charts
Invitation to Computer Science, Java Version, Third Edition
30
Using Methods
пЃ®
Method
пЃ±
A module of code in Java
пЃ±
Named using ordinary Java identifiers
пЃ±
By custom, name starts with a lowercase letter
Invitation to Computer Science, Java Version, Third Edition
31
Using Methods (continued)
пЃ®
Two types of methods
пЃ±
void method
пЃ®
пЃ±
nonvoid method
пЃ®
пЃ®
Does not pass any value back to the main method
Returns a single new value back to the main
method
Overall form of a method invocation
class-identifier.method-identifier(argument list)
Invitation to Computer Science, Java Version, Third Edition
32
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;
Invitation to Computer Science, Java Version, Third Edition
33
Figure 8.27
Some Java Terminology
Invitation to Computer Science, Java Version, Third Edition
34
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
Key elements of OOP
пЃ±
Encapsulation
пЃ®
A class consists of its subtask modules and its
properties, and both components are
“encapsulated” with the class
Invitation to Computer Science, Java Version, Third Edition
35
What Is It? (continued)
пЃ®
Key elements of OOP (continued)
пЃ±
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
Invitation to Computer Science, Java Version, Third Edition
36
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
Invitation to Computer Science, Java Version, Third Edition
37
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
Invitation to Computer Science, Java Version, Third Edition
38
What Have We Gained?
пЃ®
Two major advantages of OOP
пЃ±
Software reuse
пЃ±
A more natural “world view”
Invitation to Computer Science, Java Version, Third Edition
39
Graphical Programming: Graphics
Hardware
пЃ®
Bitmapped display
пЃ±
пЃ®
Frame buffer
пЃ±
пЃ®
The screen is made up of thousands of individual
picture elements, or pixels, laid out in a twodimensional grid
Memory that stores the actual screen image
Terminal hardware displays the frame buffer
value of every individual pixel on the screen
Invitation to Computer Science, Java Version, Third Edition
40
Figure 8.34
Pixel Numbering System in a Bitmapped Display
Invitation to Computer Science, Java Version, Third Edition
41
Graphics Software
пЃ®
Graphics library
пЃ±
пЃ®
Abstract Windowing Toolkit (AWT)
пЃ±
пЃ®
Contains a collection of software routines that
control the setting and clearing of pixels
Contains routines that allow users to create
powerful interfaces
Swing components
пЃ±
Even more powerful GUI components than AWT
Invitation to Computer Science, Java Version, Third Edition
42
Graphics Software (continued)
пЃ®
Graphics class
пЃ±
Contains drawing commands that allow you to
пЃ®
Draw geometric shapes (lines, rectangles, ovals,
polygons, and so on)
пЃ®
Set, change, and define colors
пЃ®
Fill in or shade objects
пЃ®
Create text in a range of fonts and sizes
пЃ®
Produce graphs and charts
Invitation to Computer Science, Java Version, Third Edition
43
The Big Picture: Software Engineering
пЃ®
Software life cycle
пЃ±
The overall sequence of steps needed to
complete a large-scale software project
пЃ±
Implementation represents a relatively small part
of the cycle
Invitation to Computer Science, Java Version, Third Edition
44
Figure 8.36
Steps in the Software Development Life Cycle
Invitation to Computer Science, Java Version, Third Edition
45
Scaling Up
пЃ®
Programs written by students
пЃ±
пЃ®
Real-world programs
пЃ±
пЃ®
No longer than a few hundred lines
2, 3, or 4 orders of magnitude larger
Large-scale software development
пЃ±
Extensive planning and design needed
пЃ±
A team of programmers needed
пЃ±
Software engineering
Invitation to Computer Science, Java Version, Third Edition
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
пЃ®
Problem specification
пЃ®
Program design
Invitation to Computer Science, Java Version, Third Edition
47
The Software Life Cycle (continued)
пЃ®
Algorithm selection or development, and
analysis
пЃ®
Coding
пЃ®
Debugging
пЃ®
Testing, verification, and benchmarking
пЃ®
Documentation
пЃ®
Maintenance
Invitation to Computer Science, Java Version, Third Edition
48
Modern Environments
пЃ®
Integrated Development Environment (IDE)
speeds program development by providing
пЃ±
A text editor
пЃ±
A file manager
пЃ±
A compiler
пЃ±
A linker and loader
пЃ±
Tools for debugging
Invitation to Computer Science, Java Version, Third Edition
49
Summary
пЃ®
пЃ®
In a high-level language, the programmer
пЃ±
Need not manage storage nor movement of data
values in memory
пЃ±
Can use more powerful program instructions that
are more like natural language
пЃ±
Can write a much more portable program
Java is an object-oriented, high-level
programming language
Invitation to Computer Science, Java Version, Third Edition
50
Summary (continued)
пЃ®
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: Overall sequence of steps
needed to complete a large-scale software
project
Invitation to Computer Science, Java Version, Third Edition
51
Документ
Категория
Презентации
Просмотров
4
Размер файла
1 042 Кб
Теги
1/--страниц
Пожаловаться на содержимое документа