COMP 14 Introduction to Programming - PowerPoint PPT Presentation

1 / 51
About This Presentation
Title:

COMP 14 Introduction to Programming

Description:

Discover what a compiler is and what it does. Examine a Java program. ... OS monitors overall activity of the computer and provides services ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 52
Provided by: jasonj3
Category:

less

Transcript and Presenter's Notes

Title: COMP 14 Introduction to Programming


1
COMP 14Introduction to Programming
  • Jason Jerald
  • June 23, 2006

2
from Last Time
  • Homework 1 due at midnight
  • Review of Chapter 1
  • Installation of jGRASP
  • jGRASP getting started tutorial
  • Did anyone make it to page 20
  • Any problems?

3
Objectives
  • Learn about different types of computers.
  • Explore the hardware and software components of a
    computer system.
  • Learn what an algorithm is and explore
    problem-solving techniques.
  • Become aware of structured and object-oriented
    programming design methodologies.

4
Chapter 1 Objectives
  • Learn about the language of a computer.
  • Learn about the evolution of programming
    languages.
  • Examine high-level programming languages.
  • Discover what a compiler is and what it does.
  • Examine a Java program.
  • Examine how a Java program is processed.

5
Reading Check-Up
  • ________- computer components including the CPU,
    main memory, I/O devices, and secondary storage
  • ________ - the brain of the computer that
    processes data
  • ________ - computer instructions to solve a
    problem
  • The digits 0 and 1 are called _________
  • or the shortened term ________

6
An Overview of the History of Computers
  • 1950s Very large devices available to a select
    few.
  • 1960s Large corporations owned computers.
  • 1970s Computers got smaller and cheaper.
  • 1990s Computers got cheaper and faster and were
    found in most homes.

7
Elements of a Computer System
  • A computer has two components
  • Hardware
  • Software

8
Hardware Organization
CPU
memory
motherboard
hard drive
9
Hardware vs. Software
A computer is made up of hardware and software
Software
Hardware
  • CPU
  • ex 2 GHz Pentium IV
  • input/output
  • keyboard
  • monitor
  • network card
  • main memory
  • ex 256 MB RAM
  • secondary memory
  • ex 20 GB hard drive
  • operating systems
  • Windows XP
  • Mac OS X
  • applications
  • games
  • Microsoft Word
  • Internet Explorer

10
Main Memory
  • Ordered sequence of cells
  • AKA Random Access Memory (RAM)
  • Directly connected to the CPU
  • All programs must be brought into main memory
    before execution
  • When power is turned off, everything in main
    memory is lost

11
The CPU and Main Memory
Memory
CPU
Central Processing Unit - A chip that
executes program instructions
Each memory cell has a numeric address, which
uniquely identifies it
12
Secondary Storage
  • Provides permanent storage for information
  • Retains information even when power is off
  • Examples of secondary storage
  • Hard Disks
  • Floppy Disks
  • ZIP Disks
  • CD-ROMs
  • Tapes

13
Input Devices
  • Definition devices that feed data and computer
    programs into computers
  • Examples
  • Keyboard
  • Mouse
  • Secondary Storage

14
Output Devices
  • Definition devices that the computer uses to
    display results
  • Examples
  • Printer
  • Monitor
  • Secondary Storage

15
Input/Output Devices
I/O devices facilitateuser interaction
16
Opening MS Word
  • Use the mouse to select MS Word
  • The CPU requests the MS Word application
  • MS Word is loaded from the hard drive to main
    memory
  • The CPU reads instructions from main memory and
    executes them one at a time
  • MS Word is displayed on your monitor

17
Questions
  • _________ - a unique location in memory
  • _________ - stores information permanently
  • Instructions executed by the CPU must be first
    loaded to ________

18
Software Categories
  • Operating System
  • controls all machine activities
  • provides the user interface to the computer
  • first program to load when a computer is turned
    on
  • manages computer resources, such as the CPU,
    memory, and hard drive
  • examples Windows XP, Linux, Mac OS X
  • Application
  • generic term for any other kind of software
  • examples word processors, missile control
    systems, games

19
Operating System (OS)
  • OS monitors overall activity of the computer and
    provides services
  • Written using programming language
  • Example services
  • memory management
  • input/output
  • storage management

20
Application Programs
  • Perform a specific task
  • Run by the OS
  • Written using programming languages
  • Example programs
  • Word Processors
  • Spreadsheets
  • Games

21
Questions
  • Classify the following pieces of software as
    operating system (OS) or application (app)
  • Microsoft Windows 2000
  • Microsoft PowerPoint
  • Linux
  • Your COMP 14 programs

___
___
___
___
22
Problem Solving
  • The purpose of writing a program is to solve a
    problem
  • The general steps in problem solving are
  • understand the problem
  • dissect the problem into manageable pieces
  • design a solution
  • consider alternatives to the solution and refine
    it
  • implement the solution
  • test the solution and fix any problems that exist

23
Algorithm
  • A sequence of instructions used to carry out a
    task or solve a problem
  • May be written in either English or pseudocode
  • outline of a program that could be translated
    into actual code
  • May need refinement as you work
  • Write out your algorithm before you begin
    programming

24
Problem-Analysis-Coding-Execution
most important step
without computer
with computer
25
Algorithm Design Example
  • Problem Convert change in cents to number of
    half-dollars, quarters, dimes, nickels, and
    pennies to be returned.
  • Example
  • given 646 cents
  • number of half-dollars divide 646 by 50
  • quotient is 12 (number of half-dollars)
  • remainder is 46 (change left over)
  • number of quarters divide 46 by 25
  • quotient is 1 (number of quarters)
  • remainder is 21 (change left over)
  • number of dimes, nickels, pennies
  • result 12 half-dollars, 1 quarter, 2 dimes, 0
    nickels, 1 penny

26
Resulting Algorithm
  • Get the change in cents
  • Find the number of half-dollars
  • Calculate the remaining change
  • Find the number of quarters
  • Calculate the remaining change
  • Find the number of dimes
  • Calculate the remaining change
  • Find the number of nickels
  • Calculate the remaining change
  • The remaining change is the number of pennies.

27
Exercise
  • Execution of c2ab in a computer

28
Programming Methodologies
  • Two basic approaches to programming design
  • Structured design
  • Object-oriented design

29
Structured Design
  • A problem is divided into smaller sub-problems.
  • Each sub-problem is solved.
  • The solutions of all sub-problems are combined to
    solve the problem.

30
Object-Oriented Design (OOD)
  • In OOD, a program is a collection of interacting
    objects
  • An object consists of data and operations
  • Steps in OOD
  • Identify objects.
  • Form the basis of the solution.
  • Determine how these objects interact.

31
Its All About Data
  • Software is data
  • numbers, characters
  • instructions, programs
  • Hardware stores and processes data
  • read, write
  • add, subtract, multiply, divide

32
Analog vs. Digital
  • Analog
  • continuous wave forms
  • ex sound, music on an audio tape
  • Digital
  • the information is broken down into pieces, and
    each piece is represented separately
  • is ultimately represented as series of 0s and 1s
    for low voltage and high voltage
  • can be copied exactly
  • ex music on a compact disc

33
Language of a Computer
  • Machine language is the most basic language of a
    computer.
  • A sequence of 0s and 1s.
  • Every computer directly understands its own
    machine language.
  • A bit is a binary digit, 0 or 1.
  • A byte is a sequence of eight bits.

34
Representing Text Digitally
  • All information in a computer is digitized,
    broken down and represented as numbers.

H i , H e a t h e r .
72 105 44 32 72 101 97 116
104 101 114 46
Corresponding upper and lower case letters are
separate characters.
35
Language of a Computer
  • Machine language the most basic language of a
    computer
  • A sequence of 0s and 1s
  • binary digit, or bit
  • sequence of 8 bits is called a byte
  • Every computer directly understands its own
    machine language
  • why can't Windows programs run on Apple computers?

36
Bit Permutations
Each additional bit doubles the number of
possible permutations
37
Bit Permutations
  • Each permutation can represent a particular item
  • There are 2N permutations of N bits
  • N bits are needed to represent 2N unique items

21 2 items
22 4 items
23 8 items
24 16 items
25 32 items
38
Binary Numbers
  • N bits to represent 2N values
  • N bits represent values 0 to 2N-1
  • Example 5 bits
  • 32 unique values (0-31)
  • 000002 010
  • 111112 3110

24 23 22 21 20
16 8 4 2 1 31
39
Questions Binary Numbers
  • Whats the maximum value a 6-bit number can
    represent?
  • Whats the decimal representation of 111010?
  • Whats the binary representation of 35?

26-163
25124123122021120058
35101000112
40
Storage Capacity
  • Every memory device has a storage capacity,
    indicating the number of bytes (8 bits) it can
    hold

41
Assembly and Machine Language
42
Machine Language
  • Early computers programmed in machine language
    (only 0s and 1s)
  • Assembly languages were developed to make
    programmers job easier
  • Assembler translates assembly language
    instructions into machine language

43
Programming Languages
  • High-level languages make programming easier
  • Closer to spoken languages
  • Examples
  • Basic
  • FORTRAN
  • COBOL
  • C/C
  • Java

44
Java and Machine Language
  • To run a Java program
  • Java instructions need to be translated into an
    intermediate language called bytecode.
  • The bytecode is interpreted into a particular
    machine language.

45
Compiler
  • Compiler A program that translates a program
    written in a high-level language into the
    equivalent machine language.
  • (In the case of Java, this machine language is
    the bytecode.)
  • Java Virtual Machine (JVM) A hypothetical
    computer developed to make Java programs machine
    independent.

46
A Java Program
  • public class ASimpleJavaProgram
  • public static void main(String args)
  • System.out.println("My first Java
    program.")
  • System.out.println("The sum of 2 and 3
    " 5)
  • System.out.println("7 8 " (7 8))
  • Sample Run
  • My first Java program.
  • The sum of 2 and 3 5
  • 7 8 15

47
Processing a Java Program
  • Program written in Java using the Editor and
    compiled to Bytecode using the Compiler.
  • Loader transfers the compiled code (bytecode)
    into main memory and loads the necessary
    Libraries.
  • Interpreter reads and translates each bytecode
    instruction into machine language and then
    executes it.

48
Chapter Summary
  • A computer system is made up of hardware and
    software components.
  • An algorithm is a step-by-step, problem-solving
    process in which a solution is arrived at in a
    finite amount of time.
  • The three steps of the problem-solving process
    are analyze the problem and design an algorithm,
    implement the algorithm in a programming
    language, and maintain the program.
  • The two basic approaches to programming design
    are structured design and object-oriented design.

49
Chapter Summary
  • Computers understand machine language it is
    easiest for programmers to write in high-level
    languages.
  • A compiler translates high-level language into
    machine language.
  • The Java steps required to execute a program are
    edit, compile, load, and execute.

50
To do
  • Read ch. 2, pages 27-64 (material to be on an
    upcoming quiz Tuesday)
  • Assignment 2 due Wednesday
  • There are many small problems here, so get
    started early, (try to do about 20 of the work
    per day)

51
Whats Ahead...
  • Java Basics
  • Assignments
  • Assignment 1 due tonight
  • Assignment 2 due Tuesday
  • Quiz Tuesday computers and Java basics
Write a Comment
User Comments (0)
About PowerShow.com