© 2006 pearson education chapter 1: computer systems presentation slides for java software...
TRANSCRIPT
© 2006 Pearson Education
Chapter 1: Computer Systems
Presentation slides for
Java Software Solutionsfor AP* Computer Science A
2nd Edition
by John Lewis, William Loftus, and Cara Cocking
Java Software Solutions is published by Addison-Wesley
Presentation slides are copyright 2006 by John Lewis, William Loftus, and Cara Cocking. All rights reserved.
Instructors using the textbook may use and modify these slides for pedagogical purposes.
Slides updated by [email protected]. Additional slides added from Object-Oriented Programming with Java (McGraw-Hill) instructor PowerPoint notes.
© 2006 Pearson Education 2
Computer Systems
We first need to explore the fundamentals of computer processing
Chapter 1 focuses on:
• components of a computer• how those components interact• how computers store and manipulate information• computer networks• the Internet and the World Wide Web• programming and programming languages• graphic systems
© 2006 Pearson Education
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
A History of Computers
Charles Babbage is credited as the father of computers. Although never actually built, he proposed the computing machines called Difference Engine and Analytical Engine that possessed the core characteristics of today’s computers.
Ada Lovelace, who wrote demonstration programs for Analytical Engine, is credited as the first programmer.
The first modern computer was built by Atanasoff and Berry of Iowa State University in the late 1930s.
An electromechanical computer MARK I was built by Howard Aiken of Harvard.
© 2006 Pearson Education 4
A History of Computers - ENIAC
The first completely electronic computer ENIAC I was built by Mauchly and Eckert of the University of Pennsylvania• Work began in 1943 and was launched in July 1946• Built to calculate artillery firing numbers for the United States • Weighed 54,000 lbs, used 17,468 vacuum tubes and used 150kW of power• Parts of it can be seen in the Smithsonian, UPenn, and other military/collegiate
locations today
Image Source: www.flickr.com
© 2006 Pearson Education 5
A History of Computers - ENIAC
Image Source: http://en.wikipedia.org/wiki/File:Eniac.jpg
© 2006 Pearson Education 6
Hardware and Software
Hardware• the physical, tangible parts of a computer• keyboard, monitor, disks, wires, chips, flash drives, etc.
Software• programs and data• a program is a series of instructions
A computer requires both hardware and software
Each is essentially useless without the other
© 2006 Pearson Education 7
Software Categories
Operating System• controls all machine activities• provides the user interface to the computer• manages resources such as the CPU and memory• Windows 7, Windows XP, Linux, Mac OS X Snow Leopard,
Mac OS X Mountain Lion
Application program• generic term for any other kind of software• word processors, missile control systems, games
Most operating systems and application programs have a graphical user interface (GUI)
© 2006 Pearson Education 8
Analog vs. Digital
There are two basic ways to store and manage data:
Analog• continuous, in direct proportion to the data
represented• music on a record album - a needle rides
on ridges in the grooves that are directly proportional to the voltages sent to the speaker
Digital• the information is broken down into
pieces, and each piece is represented discretely (not the same as discreetly)
• music on a compact disc - the disc stores numbers representing specific voltage levels sampled at specific times
Image Source: www.drummerworld.com
© 2006 Pearson Education 9
Digital Information
Computers store all information digitally:• numbers• text• graphics and images• video• audio• program instructions
In some way, all information is digitized - broken down into pieces and represented as numbers
© 2006 Pearson Education 10
Binary Numbers
Once information is digitized, it is represented and stored in memory using the binary number system
A single binary digit (0 or 1) is called a bit
Devices that store and move information are cheaper and more reliable if they have to represent only two states
A single bit can represent two possible states, like a light bulb that is either on (1) or off (0)
Permutations of bits are used to store values
© 2006 Pearson Education 11
Bit Permutations
1 bit
01
2 bits
00011011
3 bits
000001010011100101110111
4 bits
00000001001000110100010101100111
10001001101010111100110111101111
Each additional bit doubles the number of possible permutations
© 2006 Pearson Education 12
Bit Permutations
Each permutation can represent a particular item
There are 2N permutations of N bits
Therefore, N bits are needed to represent 2N unique items
21 = 2 items
22 = 4 items
23 = 8 items
24 = 16 items
25 = 32 items
1 bit ?
2 bits ?
3 bits ?
4 bits ?
5 bits ?
How manyitems can be
represented by
© 2006 Pearson Education
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Decimal Number Representationdecimal
point
101102103104 100 10 1 10 2 10 3
Position Values
How the decimal number is represented.
How the decimal number is represented.
101102 100 10 1
2 4 8 7
= 2 102 + 4 101+ 8 100+ 7 10 1
= 2 100 + 4 10 + 8 1 + 7 1/10
= 200 + 40 + 8 + 7 /10 = 248.7
Example:
© 2006 Pearson Education
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Binary Number Representation
binarypoint
21222324 20 2 1 2 2 2 3
Position Values
How the binary number is represented.
How the binary number is represented.
= 1 22 + 0 21 + 1 20+ 1 2 1
= 1 4 + 0 2 + 1 1 + 1 1/2
= 4 + 0 + 1 + 1/2 = 5.5
2122 20 2 1
1 0 1 1Example:
© 2006 Pearson Education 15
Decimal to Binary Conversion – Procedure
Convert 156 from decimal to binary• List powers of 2 in descending order until you reach the number 1
• Find highest power of 2 that can be subtracted from 156 In this case, that number is 128 Put a 1 underneath this number and subtract 128 from your number
156-128 = 28• Find the next higher power of 2 that can be subtracted from your remaining
number (28) The highest number that can be taken from 28 is 16 Put a 1 underneath this number and subtract 16 from your number
28-16=12• Continue this process until you have reached a remaining number of 0
If you do not reach 0, you made an error. Go back and retry it! Put 0s underneath all of the powers that you did not use for subtraction This string of 1s and 0s is your answer (should be 10011100)
Note: There’s a good tutorial at http://www.wikihow.com/Convert-from-Decimal-to-Binary showing pictures for each step
© 2006 Pearson Education 16
Binary to Decimal Conversion – Procedure
Convert 10011110 from binary to decimal• List powers of 2 in descending order until you reach the number 1
• Copy the binary sequence below your list of powers of 2, but line it up so that the last binary digit appears under the number 1 in your power of 2 list
• 512, 256, 128, 64, 32, 16, 8, 4, 2, 1
1 0 0 1 1 1 1 0• Anywhere that there is a binary 1, add the decimal number above it and keep a
running tally of this total. When done, this running tally is your answer.• 128 + 16 + 8 + 4 + 2 = 158
Note: There’s a good tutorial at http://www.wikihow.com/Convert-from-Decimal-to-Binary showing pictures for each step
© 2006 Pearson Education 17
Octal and Hex Representation
Very similar to binary representation, except that octal uses base-8 and hex uses base-16• Recall that binary uses 0 and 1 to represent the two values• Octal uses 0 to 7 to represent the eight values• Hex uses 0 to F to represent the sixteen values
0 to 9 represent 0 to 9 A represents 10, B represents 11, …., F represents 15
Image Source: http://www.openbookproject.net/tutorials/getdown/html/lesson5.html
© 2006 Pearson Education 18
Binary, Octal and Hex
A string like 11001 could represent binary, octal, hex or any other base system. We’ve been trained to use base-10 (decimal), but how do we know which one it represents when working with computers?• We use a subscript indicating the base• Example:
The first representation is binary (base-2), followed by decimal (base-10) and hex (base-16)
If there is no base specified, we assume base 10 (like logarithms!)
© 2006 Pearson Education 19
Decimal to Octal – Procedure
Convert 145 decimal to octal First convert the decimal number to binary
• 10010001
Split the binary up into groups of 3, starting from the right• 10 010 001
Convert each of these binary trios to an octal value between 0 and 7• 001 would be 1, 010 would be 2, 011 would be 3, 100 would
be 4, 101 would be 5, 110 would be 6 and 111 would be 7• For this problem, we get 221, so the answer is
Why not ?
© 2006 Pearson Education 20
Octal to Decimal – Procedure
Convert 170 octal to decimal• List powers of 8 in descending order until you reach the
number 1• Copy the binary sequence below your list of powers of 8, but
line it up so that the last octal digit appears under the number 1 in your power of 8 list
• 4096, 512, 64, 8, 1
1 7 0• Multiply each number in your list by the power of 8 above it,
and keep a running tally of this total. When done, this running tally is your answer.
• 64*1 + 8*7 + 1*0 =
© 2006 Pearson Education 21
Decimal to Hexadecimal – Procedure
Convert 212 decimal to hexadecimal First convert the decimal number to binary
• 11010100
Split the binary up into groups of 4, starting from the right• 1101 0100
Convert each of these binary groups to a hexadecimal value between 0 and F• 0001 would be 1, 0010 would be 2, …, 1010 would be A, 1011
would be B, 1100 would be C, 1101 would be D, 1110 would be E, and 1111 would be F
• For this problem, we get D4, so the answer is
© 2006 Pearson Education 22
Hexadecimal to Decimal – Procedure
Convert 195 hexadecimal to decimal• List powers of 16 in descending order until you reach the
number 1• Copy the binary sequence below your list of powers of 16,
but line it up so that the last hexadecimal digit appears under the number 1 in your power of 16 list
• 4096, 256, 16, 1
1 9 5• Multiply each number in your list by the power of 16 above it,
and keep a running tally of this total. When done, this running tally is your answer.
• 256*1 + 16*9 + 1*5 =
© 2006 Pearson Education 23
Conversions – Practice Quiz
These are similar to the upcoming quiz questions…
1. Convert to binary
2. Convert to binary
3. Convert to decimal
4. Convert to binary
5. Convert to binary
6. Convert to hexadecimal
7. Convert to octal
8. Convert to decimal
9. Convert to binary
10.Convert to binary
© 2006 Pearson Education 24
Conversions – Practice Quiz Answers
© 2006 Pearson Education 25
Representing Text Digitally
For example, every character is stored as a number, including spaces, digits, and punctuation
Corresponding upper and lower case letters are separate characters
H i , H e a t h e r .
72 105 44 32 72 101 97 116 104 101 114 46
© 2006 Pearson Education 26
ASCII Conversion Table
© 2006 Pearson Education
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Computer Architecture
CPUCPU
OutputDevicesOutputDevices
Commu-nicationDevices
Commu-nicationDevices
InputDevicesInput
Devices
RAMRAM
StorageDevicesStorageDevices
© 2006 Pearson Education 28
The Central Processing Unit
A CPU is on a chip called a microprocessor
It continuously follows the fetch-decode-execute cycle:
fetch
Retrieve an instruction from main memory
decode
Determine what theinstruction is
execute
Carry out theinstruction
© 2006 Pearson Education 29
The Central Processing Unit
The CPU contains:
Arithmetic / Logic Unit
Registers
Control Unit
Small storage areas
Performs calculations and makes decisions
Coordinates processing steps
© 2006 Pearson Education 30
The Central Processing Unit
The speed of a CPU is controlled by the system clock
The system clock generates an electronic pulse at regular intervals
The pulses coordinate the activities of the CPU
The speed is measured in hertz, though today speeds are so high that we generally list it in gigahertz (GHz)
© 2006 Pearson Education 31
Memory
Main memory is volatile - stored information is lost if the electric power is removed
Secondary memory devices are nonvolatile
Main memory and disks are direct access devices - information can be reached directly
The terms direct access and random access often are used interchangeably
A magnetic tape is a sequential access device since its data is arranged in a linear order - you must get by the intervening data in order to access other information
© 2006 Pearson Education 32
RAM vs. ROM
RAM - Random Access Memory (direct access)
ROM - Read-Only Memory
The terms RAM and main memory are basically interchangeable
ROM could be a set of memory chips, or a separate device, such as a CD ROM
Both RAM and ROM are random (direct) access devices!
RAM probably should be called Read-Write Memory
© 2006 Pearson Education 33
Memory
Main memory is divided into many memory locations (or cells)
92789279
9280928192829283928492859286
Each memory cell has a numeric address, which uniquely identifies it
© 2006 Pearson Education 34
Storing Information
92789279
9280928192829283928492859286
Large values arestored in consecutivememory locations
10011010Each memory cell stores a set number of bits (usually 8 bits, or one byte)
© 2006 Pearson Education 35
Storage Capacity
Every memory device has a storage capacity, indicating the number of bytes it can hold
Capacities are expressed in various units:
KB 210 = 1024
MB 220 (over 1 million)
GB 230 (over 1 billion)
TB 240 (over 1 trillion)
Unit Symbol Number of Bytes
kilobyte
megabyte
gigabyte
terabyte
© 2006 Pearson Education 36
Storage Notation
Bytes are represented with a B, bits with a b• 600 bits = 600 b• 80 bytes = 80 B• 50,411,918 bytes = 50,411,918 B
Similar to distances and sizes it is convenient to represent large numbers with Kilo-, Mega-, Giga-, etc.• Capitalization is important here as well• 1 kB = 1000 bytes, or 8000 bits• 1 KB = , or 1024 bytes (8,192 bits)
As a general rule of thumb, do not use lowercase letters other than to distinguish bits vs. bytes• Example:
© 2006 Pearson Education 37
Storage Notation
File sizes are measured in bytes (KB, MB, GB, etc.)• Example: Word document is 345 KB
Streaming rates such as your Internet connection speed is measured in bits per second (bps, Kbps, Mbps, Gbps, etc.) Example: Comcast may advertise a download speed of 25 Mbps Test your own speed at http://www.speedtest.net/ or on mobile
phones at http://www.speedtest.net/mobile.php Mr. Bixler’s results below
Google fiber promises speeds of 1 Gbps over fiber optic cables! https://fiber.google.com/about/
© 2006 Pearson Education 38
Compact Discs
A CD-ROM is portable read-only memory
A microscopic pit on a CD represents a binary 1 and a smooth area represents a binary 0
A low-intensity laser reflects strongly from a smooth area and weakly from a pit
A CD-Recordable (CD-R) drive can be used to write information to a CD once
A CD-Rewritable (CD-RW) can be erased and reused
The speed of a CD drive (48x) describes the maximum data transfer speed. Writing is typically much slower than reading.
© 2006 Pearson Education 39
DVDs A DVD is the same size as a CD, but can store much more
information
The format of a DVD stores more bits per square inch
• How can it do that? Can a DVD burner also burn CDs? Can a CD burner also burn DVDs?
A CD can store 650 or 700 MB, while a standard DVD can store 4.7 GB• A double sided DVD can store 9.4 GB
• Other advanced techniques can bring the capacity up to 17.0 GB
• HD-DVD (Toshiba and NEC) vs. Blu-ray (Sony) battle Who won?
There are various recordable DVD technologies – the market will determine which will dominate
© 2006 Pearson Education 40
Comparison of HDD and SDD
Hard Disk Drive (HDD)• Uses magnetism to store data on a rotating platter• Read/write head floats above spinning platter to read/write
data• Costs only about $0.10 per gigabyte• Uses 6-7 Watts of power and makes small amount of noise
Solid State Drive (SDD)• Uses embedded processor (its “brain”) to perform read/write
operations• Costs about $1.00 per gigabyte, and dropping quickly• Uses 2-3 Watts of power (conserves battery)• No moving parts results in high reliability and quiet operation• Boots up Windows 7 about twice as fast as a HDD
Also compatible with all other OSs
© 2006 Pearson Education 41
A Computer Specification
Consider the following specification for a personal computer:
• 2.4 GHz Intel Core i7-2760QM Processor• 4 GB RAM• 750 GB Hard Disk Drive• Windows 7 64-bit Operating System• 48x CD-RW / DVD-RW Combo Drive • 24” LCD Display with 1920 x 1200 resolution
What does it all mean?
© 2006 Pearson Education 42
Monitor
The size of a monitor (for example, 24") is measured diagonally, like a television screen
Most monitors these days have multimedia capabilities: text, graphics, video, etc.
A monitor has a certain maximum resolution , indicating the number of picture elements, called pixels, that it can display (such as 1920 by 1200)
High resolution (more pixels) produces sharper pictures
© 2006 Pearson Education 43
Modem
Data transfer devices allow information to be sent and received between computers
Many computers include a modulator-demodulator or modem, which allows information to be moved across a telephone line
A data transfer device has a maximum data transfer rate
A newer cable modem, for instance, may support a data transfer rate of 160 Mbps
© 2006 Pearson Education 44
Networks
A network is two or more computers that are connected so that data and resources can be shared
Most computers are connected to some kind of network
Each computer has its own network address, which uniquely identifies it among the others
A file server is a network computer dedicated to storing programs and data that are shared among network users
© 2006 Pearson Education 45
Network Connections
Each computer in a network could be directly connected to every other computer in the network
These are called point-to-point connections
This technique is not practical formore than a few close machines
Adding a computer requiresa new communication linefor each computer alreadyin the network
© 2006 Pearson Education 46
Network Connections
Most networks share a single communication line
Adding a new computer to the network is relatively easy
Network traffic must taketurns using the line, whichintroduces delays
Often information is brokendown in parts, called packets,which are sent to the receivingmachine and then reassembled
© 2006 Pearson Education 47
Local-Area Networks
LAN
A Local-Area Network(LAN) covers a smalldistance and a smallnumber of computers
A LAN often connects the machinesin a single room or building
© 2006 Pearson Education 48
Wide-Area Networks
LAN
A Wide-Area Network (WAN)connects two or more LANs,often over long distances
A LAN usually is ownedby one organization, buta WAN often connectsgroups in different countries
LAN
© 2006 Pearson Education 49
The Internet
The Internet is a WAN which spans the entire planet
The word Internet comes from the term internetworking, which implies communication among networks
It started as a United States government project, sponsored by the Advanced Research Projects Agency (ARPA) - originally it was called the ARPANET
Internet grew quickly throughout the 1980s and 90s and has exploded since
Less than 600 computers were connected to the Internet in 1983; by the year 2000 there were over 10 million; in 2011, more than 2.2 billion people use the Internet
© 2006 Pearson Education 50
TCP/IP
A protocol is a set of rules that determine how things communicate with each other
The software which manages Internet communication follows a suite of protocols called TCP/IP
The Internet Protocol (IP) determines the format of the information as it is transferred
The Transmission Control Protocol (TCP) dictates how messages are reassembled and handles lost information
© 2006 Pearson Education 51
IP and Internet Addresses
Each computer on the Internet has a unique IP address, such as:
204.192.116.2
Most computers also have a unique Internet name, which also is referred to as an Internet address:
spencer.villanova.edu
kant.gestalt-llc.com
The first part indicates a particular computer (spencer)
The rest is the domain name, indicating the organization (villanova.edu)
© 2006 Pearson Education 52
Domain Names
The last part of each domain name, called a top-level domain (TLD) indicates the type of organization:
educomorgnet
- educational institution- commercial entity- non-profit organization- network-based organization
Sometimes the suffixindicates the country: New TLDs have
recently been added:
aero, asia, biz, cat, coop, info, intjobs, mobi, museum, name, pro
tel, travel, xxx
ukaucase
- United Kingdom- Australia- Canada- Sweden
© 2006 Pearson Education 53
Domain Names
A domain name can have several parts
Unique domain names mean that multiple sites can have individual computers with the same local name
When used, an Internet address is translated to an IP address by software called the Domain Name System (DNS)
There is no one-to-one correspondence between the sections of an IP address and the sections of an Internet address
© 2006 Pearson Education 54
The World Wide Web
The World Wide Web allows many different types of information to be accessed using a common interface
A browser is a program which accesses and presents information
• text, graphics, video, sound, audio, executable programs
A Web document usually contains links to other Web documents, creating a hypermedia environment
The term Web comes from the fact that information is not organized in a linear fashion
© 2006 Pearson Education 55
The World Wide Web
Web documents are often defined using the HyperText Markup Language (HTML)
Information on the Web is found using a Uniform Resource Locator (URL):
http://www.lycos.com
http://www.villanova.edu/webinfo/domains.html
ftp://java.sun.com/applets/animation.zip
A URL indicates a protocol (http), a domain, and possibly specific documents
© 2006 Pearson Education 56
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
© 2006 Pearson Education 57
Problem Solving
Many software projects fail because the developer didn't really understand the problem to be solved
We must avoid assumptions and clarify ambiguities
As problems and their solutions become larger, we must organize our development into manageable pieces
This technique is fundamental to software development
We will dissect our solutions into pieces called classes and objects, taking an object-oriented approach
© 2006 Pearson Education 58
History of Programming Languages
Numerous languages have been developed since the early 2000’s (Cobra, Clojure, Go), but none have seen the adoption rates that previous programming languages have found.
Source: http://en.wikipedia.org/wiki/Timeline_of_computing
© 2006 Pearson Education 59
Programming Community Index
Developed by TIOBE, a software company Tracks popularity of programming languages
Source: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
© 2006 Pearson Education 60
Longer Term View of Language Popularity
They have lost some market shared, but C and Java are clearly still the leaders of the programming world
Source: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
© 2006 Pearson Education 61
Java
A programming language specifies the words and symbols that we can use to write a program
A programming language employs a set of rules that dictate how the words and symbols can be put together to form valid program statements
The Java programming language was created by Sun Microsystems, Inc.
It was introduced in 1995 and it's popularity has grown quickly since, though an increasing number of languages have emerged in recent years
It is an object-oriented language
© 2006 Pearson Education 62
Java Program Structure
In the Java programming language:• A program is made up of one or more classes• A class contains one or more methods• A method contains program statements
These terms will be explored in detail throughout the course
A Java application always contains a method called main
See Lincoln.java (page 27)
© 2006 Pearson Education 63
Java Program Structure
public class MyProgram
{
}
// comments about the class
class header
class body
Comments can be placed almost anywhere
© 2006 Pearson Education 64
Java Program Structure
public class MyProgram
{
}
public static void main (String[] args)
{
}
// comments about the class
// comments about the method
method headermethod body
© 2006 Pearson Education 65
Comments
Comments in a program are called inline documentation
They should be included to explain the purpose of the program and describe processing steps
They do not affect how a program works
Java comments can take three forms:
// this comment runs to the end of the line
/* this comment runs to the terminating symbol, even across line breaks */
/** this is a javadoc comment */
© 2006 Pearson Education 66
Identifiers
Identifiers are the words a programmer uses in a program
An identifier can be made up of letters, digits, the underscore character ( _ ), and the dollar sign
Identifiers cannot begin with a digit
Java is case sensitive - Total, total, and TOTAL are different identifiers
By convention, Java programmers use different case styles for different types of identifiers, such as• title case for class names - Lincoln
• upper case for constants - MAXIMUM
© 2006 Pearson Education 67
Identifiers
Sometimes we choose identifiers ourselves when writing a program (such as Lincoln)
Sometimes we are using another programmer's code, so we use the identifiers that they chose (such as println)
Often we use special identifiers called reserved words that already have a predefined meaning in the language
A reserved word cannot be used in any other way
© 2006 Pearson Education 68
Reserved Words
The Java reserved words:
abstractassertbooleanbreakbytecasecatchcharclassconstcontinuedefaultdodouble
elseenumextendsfalsefinalfinallyfloatforgotoifimplementsimportinstanceofint
interfacelongnativenewnullpackageprivateprotectedpublicreturnshortstaticstrictfp
superswitchsynchronizedthisthrowthrowstransienttruetryvoidvolatilewhile
© 2006 Pearson Education 69
White Space
Spaces, blank lines, and tabs are called white space
White space is used to separate words and symbols in a program
Extra white space is ignored
A valid Java program can be formatted in many ways
Programs should be formatted to enhance readability, using consistent indentation
See Lincoln2.java (page 33)
See Lincoln3.java (page 34)
© 2006 Pearson Education 70
Language Levels
There are four programming language levels:• machine language• assembly language• high-level language• fourth-generation language
Each type of CPU has its own specific machine language
The other levels were created to make it easier for a human being to read and write programs
© 2006 Pearson Education
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 0 - 71
Programming Languages
Four primary levels of programming languages:• Machine Languages
Machine language instructions are binary coded and very low level Examples are ARM, MIPS
• Assembly Languages Assembly language allows symbolic programming. Requires an
assembler to translate assembly programs into machine programs Examples are Emu8086 and PAL-III
• High-level Languages High-level language provides a very high conceptual model of
computing. Requires a compiler to translate high-level programs into assembly programs
Examples are C and Java• Fourth-generation Languages
Build around database systems and mostly used in the commercial sector
Examples are Oracle Express 4GL and SAS
© 2006 Pearson Education 72
Programming Languages
A program must be translated into machine language before it can be executed on a particular type of CPU
This can be accomplished in several ways
A compiler is a software tool which translates source code into a specific target language
Often, that target language is the machine language for a particular CPU type
The Java approach is somewhat different
© 2006 Pearson Education 73
Java Translation
The Java compiler translates Java source code into a special representation called bytecode
Java bytecode is not the machine language for any traditional CPU
Another software tool, called an interpreter, translates bytecode into machine language and executes it
Therefore the Java compiler is not tied to any particular machine
Java is considered to be architecture-neutral
© 2006 Pearson Education 74
Java Translation
Java sourcecode
Machinecode
Javabytecode
Javainterpreter
Bytecodecompiler
Javacompiler
© 2006 Pearson Education 75
Java Translation
We now know the translation process, but why not just write the code in bytecode or machine code?
Example: Java source code Bytecode for same Java source code
Machine code would be all 0s and 1s!• Above machine code too long to fit here, but below example tells the CPU to load a value into register
8, taken from the memory cell found 68 cells after the location found in register 3?!?
Source: http://en.wikibooks.org/wiki/Java_Programming/Byte_Code
© 2006 Pearson Education 76
Development Environments
There are many environments for developing Java software:
• Sun Java Development Kit (JDK)• Sun NetBeans• Borland JBuilder• MetroWerks CodeWarrior• Microsoft Visual J++• IBM Eclipse• Monash BlueJ
Though the details of these environments differ, the basic compilation and execution process is essentially the same
© 2006 Pearson Education 77
Syntax and Semantics
The syntax rules of a language define how we can put together symbols, reserved words, and identifiers to make a valid program
The semantics of a program statement define what that statement means (its purpose or role in a program)
A program that is syntactically correct is not necessarily logically (semantically) correct
A program will always do what we tell it to do, not what we meant to tell it to do
© 2006 Pearson Education 78
Errors
A program can have three types of errors
The compiler will find syntax errors and other basic problems (compile-time errors)
• If compile-time errors exist, an executable version of the program is not created
A problem can occur during program execution, such as trying to divide by zero, which causes a program to terminate abnormally (run-time errors)
A program may run, but produce incorrect results, perhaps using an incorrect formula (logical errors)
© 2006 Pearson Education 79
Basic Program Development
errors
errors
Edit andsave program
Compile program
Execute program andevaluate results
© 2006 Pearson Education 80
Introduction to Graphics
The last one or two sections of each chapter of the textbook focus on graphical issues
Most computer programs have graphical components
A picture or drawing must be digitized for storage on a computer
A picture consists of pixels, and each pixel is stored separately
© 2006 Pearson Education 81
Representing Color
A black and white picture can be stored using one bit per pixel (0 = white and 1 = black)
A colored picture requires more information; there are several techniques for representing colors
For example, every color can be represented as a mixture of the three additive primary colors Red, Green, and Blue
In Java, each color is represented by three numbers between 0 and 255 that collectively are called an RGB value
With this in mind, how can we store images digitally? How would this also allow for the storage of video?
© 2006 Pearson Education 82
Coordinate Systems
Each pixel can be identified using a two-dimensional coordinate system
When referring to a pixel in a Java program, we use a coordinate system with the origin in the top-left corner
Y
X(0, 0)
(112, 40)
112
40
© 2006 Pearson Education 83
Summary
Chapter 1 has focused on:
• components of a computer• how those components interact• how computers store and manipulate information• computer networks• the Internet and the World Wide Web• programming and programming languages• graphic systems