CS2 (Java) Exam 1 Review - Pennsylvania State University

Download Report

Transcript CS2 (Java) Exam 1 Review - Pennsylvania State University

Computer Science Theory & Introduction

Week 1 Lecture Material Doug Hogan Penn State University CMPSC 201 – C++ Programming for Engineers

Hardware vs. Software

Hardware  essentially, things you can touch  input, output, storage devices Software  essentially, what the computer knows   data, 0s and 1s programs

Components of a Computer

Central processing unit (CPU) Memory Input devices Output devices Storage devices

Central Processing Unit (CPU)

Basic job: handle processing of instructions  What’s an instruction?

Two parts:  

Control Unit (CU) Arithmetic and Logic Unit (ALU)

The ALU

Built up from

digital logic gates

 AND    OR NOT most primitive level

Memory

Holds programs that are currently running and the data being used by those programs. Two categories: 

Read-only memory (ROM)

  can only read data

Random-access memory (RAM)

   can read and write information primary storage - computer’s main memory volatile

Sequential Access vs. Random Access

Sequential Access:

must access each location in memory in order

Random Access:

can access memory locations using addresses, in any order Track 1 Track 2 Speed implications?

Memory: sizes

base unit: 1

bit

8 bits = 1

byte

= binary digit, 0 or 1 (B) 1000 bytes ≈ 1

kilobyte

(KB) 1000 KB ≈ 1,000,000 B ≈ 1

megabyte

(MB) 1000 MB ≈ 1,000,000,000 B ≈ 1

gigabyte

(GB)

Memory

Related data organized into

files

Storage Devices

Floppy disk  3.5 inches, 1.44 MB Hard disk  typically sizes in GB Compact disc (CD)  650-700 MB    CD-ROM: read-only memory CD-R: recordable CD-RW: rewritable

More Storage Devices

Digital Versitale/Video Disc (DVD)  4.7 GB Flash drives  varies Zip disks and tape drives  varies

Input Devices

mouse keyboard scanner camera microphone

Output Devices

monitor  cathode ray tube (CRT)  liquid crystal display (LCD) printer speakers

Software Overview

System software

   Controls basic operations of computer The operating system  manages memory, files, application software File management tasks – deleting, etc.

Software Overview

Application software

   Not essential to system running Enables you to perform specific tasks Ex:  Office software    Web browsers Media players Games

Algorithms and Languages

An

algorithm

is a set of instructions to solve a problem.

Think recipes.

Many algorithms may solve the same problem.

 How do we choose?

We use a our algorithms to computer and write programs.

programming language

to explain

Programming Paradigms/Models

Procedural Programming: solve problem, use methods, methods could get long Object-Oriented Programming (OOP): objects to model real-world phenomena, send messages to objects, typically shorter methods presses, etc. Others: specify steps to Event-Driven Programming: that respond to events like mouse clicks, key Functional, logic, etc. create create methods

Compiled vs. Interpreted Languages

Interpreted Language

  Requires software called an interpreter to run the code Code is checked for errors as it runs (erroneous code: do the best we can…)  Examples: HTML, JavaScript, PHP

Compiled Language

  Requires software called a compiler to run the code Code must be compiled into an executable before running (and thus error free)  Examples: C, C++, Pascal, FORTRAN, BASIC

Compiling Process

Source Code (C++) compiler Object Code linker Executable Program Object Code from Libraries

Errors

Syntax Errors

 Misuse of the language, much like using incorrect punctuation in English  Compiler reports; program won’t run until they’re resolved

Logic Errors

 Program doesn’t solve the problem at hand correctly

Runtime Errors

 Errors that occur while the program is running, e.g. problems accessing memory, divide by zero

Abstraction

Poll:  Who can use a CD player?

   Who can explain how a CD player works?

Who can drive a car?

Who is an auto mechanic?

Abstraction

    Principle of ignoring details that allows us to use complex devices Focus on the WHAT, not the HOW Fundamental to CS Other examples?

Levels of Abstraction

0. Digital Logic 1. Microprocessor 2. Machine Language 3. Operating System 4. Assembly Language 5. High-Level Language 6. Application Software

Binary Numbers

Use two symbols: 0 and 1 Base 2 Compare with decimal number system  Uses symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9  Base 10 At the lowest level of abstraction, everything in a computer is expressed in binary.

100 101 110 111 10 11 0 1

Binary Numbers, ctd.

1000 1001 1010 1011 1100 1101 1110 1111 10000 Places:   Decimal: 1s, 10s, 100s, etc.

Binary, 1s, 2s, 4s, 8s, etc. Conversion between decimal and binary is done by multiplying or adding by powers of 2. “There are 10 kinds of people in the world…”

Other Number Systems

Any positive integer could be the base of a number system. (Big topic in number theory.) Others used in computer science:  

Octal:

Base 8 Hexadecimal:   Base 16 New symbols A, B, C, D, E, F

ASCII

Every character on a computer -- letters, digits, symbols, etc. -- is represented by a numeric code behind the scenes.

This system of codes is called

ASCII

, short for

American Standard Code for Information Interchange

.

We’ll learn more in lab…

# Transistors on a Processor

Data for Intel processors: Data from Section 4.1 of : Yates, Daniel S., and David S. Moore and Daren S. Starnes.

The Practice of Statistics

. 2nd Ed. New York: Freeman, 2003.

Processor

4004 8008 8080 8086 286 386 486 DX Pentium Pentium II Pentium III Pentium 4

Date

1971 1972 1974 1978 1982 1985 1989 1993 1997 1999 2000

Number of Transistors

2,250 2,500 5,000 29,000 120,000 275,000 1,180,000 3,100,000 7,500,000 24,000,000 42,000,000

A Graphical View

Pay attention to the units on the axes… Graph from Intel's web site ( http://www.intel.com/technology/mooreslaw/index.htm

); Retrieved 9/24/2006

Moore’s Law

Prediction from Gordon Moore of Intel in 1965.

Implication: The speed of processors doubles roughly every 12 to 18 months.

  Exponential relationship in the data. For the curious: the regression equation from the data two slides back is ˆ  1648.16

 1.393

x

Can this go on forever?

