22
Chapter 1 What is Programming? Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E. Reingold

Chapter 1 What is Programming?

  • Upload
    wind

  • View
    43

  • Download
    3

Embed Size (px)

DESCRIPTION

Chapter 1 What is Programming?. Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E. Reingold. Chapter Preview. In this chapter we will: demonstrate some problem-solving techniques needed in programming - PowerPoint PPT Presentation

Citation preview

Page 1: Chapter 1 What is Programming?

Chapter 1What is Programming?

Lecture Slides to Accompany

An Introduction to Computer Science Using Java (2nd Edition)

by

S.N. Kamin, D. Mickunas, E. Reingold

Page 2: Chapter 1 What is Programming?

Chapter Preview

In this chapter we will:• demonstrate some problem-solving techniques

needed in programming• design an algorithm to solve a problem• write a program to implement an algorithm• discuss the importance of object-oriented

programming• discuss some basics of computer hardware• describe the process of entering and running Java

programs

Page 3: Chapter 1 What is Programming?

Definitions

• program– a set of directions telling a computer exactly what

to do

• programming languages– languages for specifying sequences of directions

to a computer

• algorithm– a sequence of language independent steps which

may be followed to solve a problem

Page 4: Chapter 1 What is Programming?

Final Maze Solving Program

step forward;

while (inside the maze?) {

turn right;

while (facing a wall?) {

turn left;

}

step forward;

}

Page 5: Chapter 1 What is Programming?

Object-Oriented Programming

• A modern programming paradigm that allows the programmer to model a problem in a real-world fashion

• Objects interact with each other by sending messages

• An object is an instance of a class• A class implements an interface and specifies

the behavior of an object

Page 6: Chapter 1 What is Programming?
Page 7: Chapter 1 What is Programming?
Page 8: Chapter 1 What is Programming?

Object-Oriented Programming and Java

• The use of OOP in Java is pervasive– easy to create multiple objects of the same type– easy to create similar objects without having to

rewrite the overlapping code

• OOP makes programs easier to understand and more reliable

• Prevents objects from having to know any more about structure of other objects than is really necessary

Page 9: Chapter 1 What is Programming?

Computer Organization

• central-processing unit– performs the actual work of executing the program

• main memory– holds the program and during execution

• hard disk– holds all programs not executing and all data files

• input/output devices– allow the computer to communicate with the

outside world

Page 10: Chapter 1 What is Programming?
Page 11: Chapter 1 What is Programming?

Running a Program

• First the program and all its data is copied from the hard disk into main memory

• The CPU goes to the location of the program instruction and reads that word

• The CPU determines what action is requested by decoding its bit pattern representation

• The CPU performs the action• The CPU then moves to the location of the next

program instruction in memory, reads the word, and repeats the process

Page 12: Chapter 1 What is Programming?
Page 13: Chapter 1 What is Programming?

Data Representation

• Computers use binary numbers• Numbers can be used to represent any type

of data– pictures are represented by dividing them into

picture elements known as pixels– video images or animations are represented by

placing several picture one after another– sounds are represented by sampling the wave at

regular intervals

• All data are stored in files on the hard disk

Page 14: Chapter 1 What is Programming?
Page 15: Chapter 1 What is Programming?
Page 16: Chapter 1 What is Programming?
Page 17: Chapter 1 What is Programming?
Page 18: Chapter 1 What is Programming?
Page 19: Chapter 1 What is Programming?
Page 20: Chapter 1 What is Programming?

Running Your Own Java Program

• Enter the program source code in a data file using an editor

• Transform the source program into machine language or Java Bytecode using an compiler (e.g. javac)

• Use an interpreter to execute the compiled program (e.g. java)

• Return to the editor to correct any errors (or bugs) and start the cycle again

Page 21: Chapter 1 What is Programming?

Errors

• Debugging is the process of detecting and fixing errors found in a program

• Syntactic errors are caused by giving the compiler a program it cannot recognize

• Logical errors come from programs that compile correctly but fail to execute as expected

• Programs must be designed carefully and tested thoroughly to ensure that neither error will occur

Page 22: Chapter 1 What is Programming?

Java

• applications– stand-alone programs that run on you own

computer– can read and write data on your disk disk

• applets– executed from within a browser window (e.g.

Netscape or Internet Explorer)– can be loaded from the World Wide Web and

executed on another computer– cannot read or write data on your hard disk