background image

Chapter 1:  Computer Systems

Chapter 1:  Computer Systems

Presentation slides for

Presentation slides for

Java Software Solutions

Java Software Solutions

Foundations of Program Design

Foundations of Program Design

Second Edition

Second Edition

by John Lewis and William Loftus

by John Lewis and William Loftus

Java Software Solutions is published by Addison-Wesley

Java Software Solutions is published by Addison-Wesley

Presentation slides are copyright 2000 by John Lewis and William Loftus. All rights reserved.

Presentation slides are copyright 2000 by John Lewis and William Loftus. All rights reserved.

Instructors using the textbook may use and modify these slides for pedagogical purposes.

Instructors using the textbook may use and modify these slides for pedagogical purposes.

background image

2

Focus of the Course

Focus of the Course

Object-Oriented Software Development

Object-Oriented Software Development

problem solving

problem solving

program design and implementation

program design and implementation

object-oriented concepts

object-oriented concepts

objects

objects

classes

classes

interfaces

interfaces

inheritance

inheritance

polymorphism

polymorphism

graphics and Graphical User Interfaces

graphics and Graphical User Interfaces

the Java programming language

the Java programming language

background image

3

Computer Systems

Computer Systems

We first need to explore the fundamentals of 

We first need to explore the fundamentals of 

computer processing

computer processing

Chapter 1 focuses on:

Chapter 1 focuses on:

components of a computer

components of a computer

how those components interact

how those components interact

how computers store and manipulate information

how computers store and manipulate information

computer networks

computer networks

the Internet and the World-Wide Web

the Internet and the World-Wide Web

programming and programming languages

programming and programming languages

graphic systems

graphic systems

background image

4

Hardware and Software

Hardware and Software

Hardware

Hardware

the physical, tangible parts of a computer

the physical, tangible parts of a computer

keyboard, monitor, wires, chips, data

keyboard, monitor, wires, chips, data

Software

Software

programs and data

programs and data

program

program

 is a series of instructions

 is a series of instructions

A computer requires both hardware and 

A computer requires both hardware and 

software

software

Each is essentially useless without the other

Each is essentially useless without the other

background image

5

CPU and Main Memory

CPU and Main Memory

Central

Processing

Unit

Main

Memory

Chip that 

Chip that 

executes 

executes 

program 

program 

commands

commands

Intel Pentium III

Intel Pentium III

Sun Sparc 

Sun Sparc 

Processor

Processor

Primary storage 

Primary storage 

area for 

area for 

programs and 

programs and 

data that are in 

data that are in 

active use

active use

Synonymous with 

Synonymous with 

RAM

RAM

background image

6

Secondary Memory Devices

Secondary Memory Devices

Floppy Disk

Hard Disk

Main

Memory

Central

Processing

Unit

Secondary memory

Secondary memory

devices provide

devices provide

long-term storage

long-term storage

Information is moved

Information is moved

between main memory

between main memory

and secondary memory

and secondary memory

as needed

as needed

Hard disks

Hard disks

Floppy 

Floppy 

disks

disks

ZIP disks

ZIP disks

Writable 

Writable 

CDs

CDs

Tapes

Tapes

background image

7

Input / Output Devices

Input / Output Devices

Monitor

Keyboard

Main

Memory

Central

Processing

Unit

Floppy Disk

Hard Disk

I/O devices allow user

I/O devices allow user

interaction

interaction

Monitor screen

Monitor screen

Keyboard

Keyboard

Mouse

Mouse

Bar code scanner

Bar code scanner

Light pen

Light pen

Touch screen

Touch screen

background image

8

Software Categories

Software Categories

Operating System

Operating System

controls all machine activities

controls all machine activities

provides the user interface to the computer

provides the user interface to the computer

manages resources such as the CPU and memory

manages resources such as the CPU and memory

Windows 98, Windows NT, Unix, Linux, Mac OS

Windows 98, Windows NT, Unix, Linux, Mac OS

Application program

Application program

generic term for any other kind of software

generic term for any other kind of software

word processors, missile control systems, games

word processors, missile control systems, games

Most operating systems and application 

Most operating systems and application 

programs have a graphical user interface 

programs have a graphical user interface 

(GUI)

(GUI)

background image

9

Analog vs. Digital

Analog vs. Digital

There are two basic ways to store and manage 

There are two basic ways to store and manage 

data:

data:

Analog

Analog

continuous, in direct proportion to the data represented

continuous, in direct proportion to the data represented

music on a record album - a needle rides on ridges in the 

music on a record album - a needle rides on ridges in the 

grooves that are directly proportional to the voltage sent 

grooves that are directly proportional to the voltage sent 

to the speaker

to the speaker

Digital

Digital

the information is broken down into pieces, and each 

the information is broken down into pieces, and each 

piece is represented separately

piece is represented separately

music on a compact disc - the disc stores numbers 

music on a compact disc - the disc stores numbers 

representing specific voltage levels sampled at various 

representing specific voltage levels sampled at various 

points

points

background image

10

Digital Information

Digital Information

Computers store all information digitally:

Computers store all information digitally:

numbers

numbers

text

text

graphics and images

graphics and images

audio

audio

video

video

program instructions

program instructions

In some way, all information is 

In some way, all information is 

digitized

digitized

 - 

 - 

broken down into pieces and represented as 

broken down into pieces and represented as 

numbers

numbers

background image

11

Representing Text Digitally

Representing Text Digitally

For example, every character is stored as a 

For example, every character is stored as a 

number, including spaces, digits, and 

number, including spaces, digits, and 

punctuation

punctuation

Corresponding upper and lower case letters 

Corresponding upper and lower case letters 

are separate characters

are separate characters

H i ,   H e a t h e r .

H i ,   H e a t h e r .

72   105   44   32   72   101   97   116   104   101   114   46

72   105   44   32   72   101   97   116   104   101   114   46

background image

12

Binary Numbers

Binary Numbers

Once information is digitized, it is represented 

Once information is digitized, it is represented 

and stored in memory using the 

and stored in memory using the 

binary number 

binary number 

system

system

A single binary digit (0 or 1) is called a 

A single binary digit (0 or 1) is called a 

bit

bit

Devices that store and move information are 

Devices that store and move information are 

cheaper and more reliable if they only have to 

cheaper and more reliable if they only have to 

represent two states

represent two states

A single bit can represent two possible states, like 

A single bit can represent two possible states, like 

a light bulb that is either on (1) or off (0)

a light bulb that is either on (1) or off (0)

Combinations of bits are used to store values

Combinations of bits are used to store values

background image

 

 

13

Bit Combinations

Bit Combinations

1 bit

1 bit

0

0

1

1

2 bits

2 bits

00

00

01

01

10

10

11

11

3 bits

3 bits

000

000

001

001

010

010

011

011

100

100

101

101

110

110

111

111

4 bits

4 bits

0000

0000

0001

0001

0010

0010

0011

0011

0100

0100

0101

0101

0110

0110

0111

0111

1000

1000

1001

1001

1010

1010

1011

1011

1100

1100

1101

1101

1110

1110

1111

1111

Each additional bit doubles the number of possible combinations

Each additional bit doubles the number of possible combinations

background image

 

 

14

Bit Combinations

Bit Combinations

Each combination can represent a particular item

Each combination can represent a particular item

There are 2

There are 2

N

N

 combinations of N bits

 combinations of N bits

Therefore, N bits are needed to represent 2

Therefore, N bits are needed to represent 2

N

N

 

 

unique items

unique items

2

2

1

1

 

 

 =  2 items

 =  2 items

2

2

2

2

 

 

 =  4 items

 =  4 items

2

2

3

3

  =  8 items

  =  8 items

2

2

4

4

  =  16 items

  =  16 items

2

2

5

5

  =  32 items

  =  32 items

1 bit ?

1 bit ?

2 bits ?

2 bits ?

3 bits ?

3 bits ?

4 bits ?

4 bits ?

5 bits ?

5 bits ?

How many

How many

items can be

items can be

represented by

represented by

background image

 

 

15

A Computer Specification

A Computer Specification

Consider the following specification for a 

Consider the following specification for a 

personal computer: 

personal computer: 

600 MHz Pentium III Processor

600 MHz Pentium III Processor

256 MB RAM

256 MB RAM

16 GB Hard Disk

16 GB Hard Disk

24x speed CD ROM Drive 

24x speed CD ROM Drive 

17” Multimedia Video Display with 1280 x 1024 

17” Multimedia Video Display with 1280 x 1024 

resolution

resolution

56 KB Modem

56 KB Modem

What does it all mean?

What does it all mean?

background image

 

 

16

Memory

Memory

Main memory is 

Main memory is 

divided into many 

divided into many 

memory locations 

memory locations 

(or 

(or 

cells

cells

)

)

9278

9278

9279

9279

9280

9280

9281

9281

9282

9282

9283

9283

9284

9284

9285

9285

9286

9286

Each memory cell 

Each memory cell 

has a numeric 

has a numeric 

address

address

, which 

, which 

uniquely identifies 

uniquely identifies 

it

it

background image

 

 

17

Storing Information

Storing Information

9278

9278

9279

9279

9280

9280

9281

9281

9282

9282

9283

9283

9284

9284

9285

9285

9286

9286

Large values are

Large values are

stored in consecutive

stored in consecutive

memory locations

memory locations

10011010

10011010

Each memory cell 

Each memory cell 

stores a set number 

stores a set number 

of bits (usually 8 

of bits (usually 8 

bits, or one 

bits, or one 

byte

byte

)

)

background image

 

 

18

Storage Capacity

Storage Capacity

Every memory device has a 

Every memory device has a 

storage capacity

storage capacity

indicating the number of bytes it can hold

indicating the number of bytes it can hold

Capacities are expressed in various units:

Capacities are expressed in various units:

KB

KB

2

2

10

10

  =  1024

  =  1024

MB

MB

2

2

20

20

  (over 1 million)

  (over 1 million)

GB

GB

2

2

30

30

  (over 1 billion)

  (over 1 billion)

TB

TB

2

2

40

40

  (over 1 trillion)

  (over 1 trillion)

Unit

Unit

Symbol

Symbol

Number of Bytes

Number of Bytes

kilobyte

kilobyte

megabyte

megabyte

gigabyte

gigabyte

terabyte

terabyte

background image

 

 

19

Memory

Memory

Main memory is 

Main memory is 

volatile

volatile

  -  stored information 

  -  stored information 

is lost if the electric power is removed

is lost if the electric power is removed

Secondary memory devices are 

Secondary memory devices are 

nonvolatile

nonvolatile

Main memory and disks are 

Main memory and disks are 

direct access

direct access

 

 

devices - information can be reached directly

devices - information can be reached directly

The terms direct access and 

The terms direct access and 

random access

random access

 

 

are often used interchangeably

are often used interchangeably

A magnetic tape is a 

A magnetic tape is a 

sequential access

sequential access

 device 

 device 

since its data is arranged in a linear order  -  

since its data is arranged in a linear order  -  

you must get by the intervening data in order 

you must get by the intervening data in order 

to access other information

to access other information

background image

 

 

20

RAM vs. ROM

RAM vs. ROM

RAM

RAM

  -  Random Access Memory (direct access)

  -  Random Access Memory (direct access)

ROM

ROM

  -  Read-Only Memory

  -  Read-Only Memory

The terms RAM and main memory are basically 

The terms RAM and main memory are basically 

interchangeable

interchangeable

ROM could be a set of memory chips, or a 

ROM could be a set of memory chips, or a 

separate device, such as a CD ROM

separate device, such as a CD ROM

Both RAM and ROM are random (direct) access 

Both RAM and ROM are random (direct) access 

devices!

devices!

RAM should probably be called Read-Write 

RAM should probably be called Read-Write 

Memory

Memory

background image

21

The Central Processing Unit

The Central Processing Unit

A CPU is also called a 

A CPU is also called a 

microprocessor

microprocessor

 

 

It continuously follows the 

It continuously follows the 

fetch-decode-execute 

fetch-decode-execute 

cycle:

cycle:

fetch

Retrieve an instruction from main memory

Retrieve an instruction from main memory

decode

Determine what the

Determine what the

instruction is

instruction is

execute

Carry out the

Carry out the

instruction

instruction

background image

 

 

22

The Central Processing Unit 

The Central Processing Unit 

(CPU)

(CPU)

The CPU contains:

The CPU contains:

Arithmetic / Logic Unit

Registers

Control Unit

Small 

Small 

storage 

storage 

areas

areas

Performs 

Performs 

calculations and 

calculations and 

decisions

decisions

Coordinates 

Coordinates 

processing 

processing 

steps

steps

background image

 

 

23

The Central Processing Unit

The Central Processing Unit

The speed of a CPU is controlled by the 

The speed of a CPU is controlled by the 

system clock

system clock

The system clock generates an electronic 

The system clock generates an electronic 

pulse at regular intervals

pulse at regular intervals

The pulses coordinate the activities of the 

The pulses coordinate the activities of the 

CPU

CPU

The speed is measured in 

The speed is measured in 

megahertz

megahertz

 (MHz)

 (MHz)

background image

 

 

24

Monitor

Monitor

The size of a monitor (17") is measured 

The size of a monitor (17") is measured 

diagonally, like a television screen

diagonally, like a television screen

Most monitors these days have 

Most monitors these days have 

multimedia

multimedia

 

 

capabilities:  text, graphics, video, etc.

capabilities:  text, graphics, video, etc.

A monitor has a certain maximum 

A monitor has a certain maximum 

resolution

resolution

 , 

 , 

indicating the number of picture elements, 

indicating the number of picture elements, 

called 

called 

pixels

pixels

, that it can display (such as 1280 

, that it can display (such as 1280 

by 1024)

by 1024)

High resolution (more pixels) produces 

High resolution (more pixels) produces 

sharper pictures

sharper pictures

background image

 

 

25

Modem

Modem

Data transfer devices

Data transfer devices

 allow information to be 

 allow information to be 

sent and received between computers

sent and received between computers

Many computers include a 

Many computers include a 

modem

modem

, which 

, which 

allows information to be moved across a 

allows information to be moved across a 

telephone line

telephone line

A data transfer device has a maximum 

A data transfer device has a maximum 

data 

data 

transfer rate

transfer rate

A modem, for instance, may have a data 

A modem, for instance, may have a data 

transfer rate of 56,000 

transfer rate of 56,000 

bits per second

bits per second

 (bps)

 (bps)

background image

 

 

26

Networks

Networks

network

network

 is two or more computers that are 

 is two or more computers that are 

connected so that data and resources can be 

connected so that data and resources can be 

shared

shared

Most computers are connected to some kind 

Most computers are connected to some kind 

of network

of network

Each computer has its own 

Each computer has its own 

network address

network address

which uniquely identifies it among the others

which uniquely identifies it among the others

file server

file server

 is a network computer dedicated 

 is a network computer dedicated 

to storing programs and data that are shared 

to storing programs and data that are shared 

among network users

among network users

background image

27

Network Connections

Network Connections

Each computer in a network could be directly 

Each computer in a network could be directly 

connected to each other computer in the 

connected to each other computer in the 

network

network

These are called

These are called

 point-to-point 

 point-to-point 

connections

connections

This technique is not feasible for

This technique is not feasible for

more than a few close machines

more than a few close machines

Adding a computer requires

Adding a computer requires

a new communication line

a new communication line

for each computer already

for each computer already

in the network

in the network

background image

 

 

28

Network Connections

Network Connections

Most modern networks share a single communication 

Most modern networks share a single communication 

line

line

Adding a new computer to the network is relatively easy

Adding a new computer to the network is relatively easy

Network traffic must take

Network traffic must take

turns using the line, which

turns using the line, which

introduces delays

introduces delays

Often information is broken

Often information is broken

down in parts, called 

down in parts, called 

packets

packets

,

,

which are sent to the receiving

which are sent to the receiving

machine then reassembled

machine then reassembled

background image

 

 

29

Local-Area Networks

Local-Area Networks

LAN

LAN

Local-Area Network

Local-Area Network

(LAN) covers a small

(LAN) covers a small

distance and a small

distance and a small

number of computers

number of computers

A LAN often connects the machines

A LAN often connects the machines

in a single room or building

in a single room or building

background image

 

 

30

Wide-Area Networks

Wide-Area Networks

LAN

LAN

Wide-Area Network

Wide-Area Network

 (WAN)

 (WAN)

connects two or more LANs,

connects two or more LANs,

often over long distances

often over long distances

A LAN is usually owned

A LAN is usually owned

by one organization, but

by one organization, but

a WAN often connects

a WAN often connects

different groups in

different groups in

different countries

different countries

LAN

LAN

background image

 

 

31

The Internet

The Internet

The 

The 

Internet

Internet

 is a WAN which spans the entire planet

 is a WAN which spans the entire planet

The word Internet comes from the term 

The word Internet comes from the term 

internetworking

internetworking

, which implies communication 

, which implies communication 

among networks

among networks

It started as a United States government project, 

It started as a United States government project, 

sponsored by the Advanced Research Projects Agency 

sponsored by the Advanced Research Projects Agency 

(ARPA), and was originally called the ARPANET

(ARPA), and was originally called the ARPANET

The Internet grew quickly throughout the 1980s and 

The Internet grew quickly throughout the 1980s and 

90s

90s

Less than 600 computers were connected to the 

Less than 600 computers were connected to the 

Internet in 1983;  now there are over 10 million

Internet in 1983;  now there are over 10 million

background image

 

 

32

TCP/IP

TCP/IP

A protocol is a set of rules that determine how things 

A protocol is a set of rules that determine how things 

communicate with each other

communicate with each other

The software which manages Internet communication 

The software which manages Internet communication 

follows a suite of protocols called 

follows a suite of protocols called 

TCP/IP

TCP/IP

The 

The 

Internet Protocol

Internet Protocol

 (IP) determines the format of 

 (IP) determines the format of 

the information as it is transferred

the information as it is transferred

The 

The 

Transmission Control Protocol

Transmission Control Protocol

 (TCP) dictates 

 (TCP) dictates 

how messages are reassembled and handles lost 

how messages are reassembled and handles lost 

information

information

background image

 

 

33

IP and Internet Addresses

IP and Internet Addresses

Each computer on the Internet has a unique 

Each computer on the Internet has a unique 

IP 

IP 

address

address

, such as: 

, such as: 

204.192.116.2

204.192.116.2

Most computers also have a unique Internet name, 

Most computers also have a unique Internet name, 

which is also referred to as an 

which is also referred to as an 

Internet address

Internet address

:

:

renoir.villanova.edu

renoir.villanova.edu

kant.breakaway.com

kant.breakaway.com

The first part indicates a particular computer 

The first part indicates a particular computer 

(

(

renoir

renoir

)

)

The rest is the 

The rest is the 

domain name

domain name

, indicating the 

, indicating the 

organization (

organization (

villanova.edu

villanova.edu

)

)

background image

 

 

34

Domain Names

Domain Names

The last section (the suffix) of each domain name 

The last section (the suffix) of each domain name 

usually indicates the type of organization:

usually indicates the type of organization:

edu

edu

com

com

org

org

net

net

-  educational institution

-  educational institution

-  commercial business

-  commercial business

-  non-profit organization

-  non-profit organization

-  network-based organization

-  network-based organization

Sometimes the suffix

Sometimes the suffix

indicates the country:

indicates the country:

New suffix categories

New suffix categories

are being considered

are being considered

uk

uk

au

au

ca

ca

se

se

-  United Kingdom

-  United Kingdom

-  Australia

-  Australia

-  Canada

-  Canada

-  Sweden

-  Sweden

background image

 

 

35

Domain Names

Domain Names

A domain name can have several parts

A domain name can have several parts

Unique domain names mean that multiple 

Unique domain names mean that multiple 

sites can have individual computers with the 

sites can have individual computers with the 

same local name

same local name

When used, an Internet address is translated 

When used, an Internet address is translated 

to an IP address by software called the 

to an IP address by software called the 

Domain Name System

Domain Name System

 (DNS)

 (DNS)

There is 

There is 

no

no

 one-to-one correspondence 

 one-to-one correspondence 

between the sections of an IP address and the 

between the sections of an IP address and the 

sections of an Internet address

sections of an Internet address

background image

 

 

36

The World-Wide Web

The World-Wide Web

The 

The 

World-Wide Web

World-Wide Web

 allows many different types 

 allows many different types 

of information to be accessed using a common 

of information to be accessed using a common 

interface

interface

browser

browser

 is a program which accesses and 

 is a program which accesses and 

presents information

presents information

text, graphics, sound, audio, video, executable programs

text, graphics, sound, audio, video, executable programs

A Web document usually contains 

A Web document usually contains 

links

links

 to other 

 to other 

Web documents, creating a 

Web documents, creating a 

hypermedia

hypermedia

 

 

environment

environment

The term Web comes from the fact that 

The term Web comes from the fact that 

information is not organized in a linear fashion

information is not organized in a linear fashion

background image

 

 

37

The World-Wide Web

The World-Wide Web

Web documents are often defined using the 

Web documents are often defined using the 

HyperText Markup Language

HyperText Markup Language

 (HTML)

 (HTML)

Information on the Web is found using a 

Information on the Web is found using a 

Uniform Resource Locator

Uniform Resource Locator

 (URL):

 (URL):

http://www.lycos.com

http://www.lycos.com

http://www.villanova.edu/webinfo/domains.html

http://www.villanova.edu/webinfo/domains.html

ftp://java.sun.com/applets/animation.zip

ftp://java.sun.com/applets/animation.zip

A URL indicates a protocol (http), a domain, 

A URL indicates a protocol (http), a domain, 

and possibly specific documents

and possibly specific documents

background image

38

Problem Solving

Problem Solving

The purpose of writing a program is to solve 

The purpose of writing a program is to solve 

a problem

a problem

The general steps in problem solving are:

The general steps in problem solving are:

Understand the problem

Understand the problem

Dissect the problem into manageable pieces

Dissect the problem into manageable pieces

Design a solution

Design a solution

Consider alternatives to the solution and refine it

Consider alternatives to the solution and refine it

Implement the solution

Implement the solution

Test the solution and fix any problems that exist

Test the solution and fix any problems that exist

background image

39

Problem Solving

Problem Solving

Many software projects fail because the developer 

Many software projects fail because the developer 

didn't really understand the problem to be solved

didn't really understand the problem to be solved

We must avoid assumptions and clarify 

We must avoid assumptions and clarify 

ambiguities

ambiguities

As problems and their solutions become larger, 

As problems and their solutions become larger, 

we must organize our development into 

we must organize our development into 

manageable pieces

manageable pieces

This technique is fundamental to software 

This technique is fundamental to software 

development

development

We will dissect our solutions into pieces called 

We will dissect our solutions into pieces called 

classes and objects, taking an 

classes and objects, taking an 

object-oriented 

object-oriented 

approach

approach

background image

40

The Java Programming 

The Java Programming 

Language

Language

programming language

programming language

 specifies the words 

 specifies the words 

and symbols that we can use to write a program

and symbols that we can use to write a program

A programming language employs a set of rules 

A programming language employs a set of rules 

that dictate how the words and symbols can be 

that dictate how the words and symbols can be 

put together to form valid 

put together to form valid 

program statements

program statements

Java was created by Sun Microsystems, Inc.

Java was created by Sun Microsystems, Inc.

It was introduced in 1995 and has become quite 

It was introduced in 1995 and has become quite 

popular

popular

It is an object-oriented language

It is an object-oriented language

background image

41

Java Program Structure

Java Program Structure

In the Java programming language:

In the Java programming language:

A program is made up of one or more 

A program is made up of one or more 

classes

classes

A class contains one or more 

A class contains one or more 

methods

methods

A method contains program 

A method contains program 

statements

statements

These terms will be explored in detail 

These terms will be explored in detail 

throughout the course

throughout the course

A Java application always contains a method 

A Java application always contains a method 

called 

called 

main

main

See 

See 

Lincoln.java

Lincoln.java

  

  

(page 26)

(page 26)

background image

 

 

42

Java Program Structure

Java Program Structure

public class MyProgram

{

}

//  comments about the class

class header

class header

class body

class body

Comments can be added almost anywhere

Comments can be added almost anywhere

background image

 

 

43

Java Program Structure

Java Program Structure

public class MyProgram

{

}

public static void main (String[] args)

{

}

//  comments about the class

//  comments about the method

method header

method header

method body

method body

background image

 

 

44

Comments

Comments

Comments in a program are also called 

Comments in a program are also called 

inline 

inline 

documentation

documentation

They should be included to explain the purpose 

They should be included to explain the purpose 

of the program and describe processing steps

of the program and describe processing steps

They do not affect how a program works

They do not affect how a program works

Java comments can take two forms:

Java comments can take two forms:

// this comment runs to the end of the line

/*  this comment runs to the terminating
    symbol, even across line breaks        */

background image

 

 

45

Identifiers

Identifiers

Identifiers

Identifiers

 are the words a programmer uses 

 are the words a programmer uses 

in a program

in a program

An identifier can be made up of letters, 

An identifier can be made up of letters, 

digits, the underscore character (_), and the 

digits, the underscore character (_), and the 

dollar sign

dollar sign

They cannot begin with a digit

They cannot begin with a digit

Java is 

Java is 

case sensitive

case sensitive

, therefore

, therefore

 Total 

 Total 

and

and

 

 

total 

total 

are different identifiers

are different identifiers

background image

46

Identifiers

Identifiers

Sometimes we choose identifiers ourselves when 

Sometimes we choose identifiers ourselves when 

writing a program (such as 

writing a program (such as 

Lincoln

Lincoln

)

)

Sometimes we are using another programmer's 

Sometimes we are using another programmer's 

code, so we use the identifiers that they chose 

code, so we use the identifiers that they chose 

(such as 

(such as 

println

println

)

)

Often we use special identifiers called 

Often we use special identifiers called 

reserved 

reserved 

words

words

 that already have a predefined meaning in 

 that already have a predefined meaning in 

the language

the language

A reserved word cannot be used in any other way

A reserved word cannot be used in any other way

background image

 

 

47

Reserved Words

Reserved Words

The Java reserved words:

The Java reserved words:

abstract
boolean
break
byte
byvalue
case
cast
catch
char
class
const
continue

default
do
double
else
extends
false
final
finally
float
for
future
generic

goto
if
implements
import
inner
instanceof
int
interface
long
native
new
null

operator
outer
package
private
protected
public
rest
return
short
static
super
switch

synchronized
this
throw
throws
transient
true
try
var
void
volatile
while

background image

 

 

48

White Space

White Space

Spaces, blank lines, and tabs are collectively 

Spaces, blank lines, and tabs are collectively 

called 

called 

white space

white space

White space is used to separate words and 

White space is used to separate words and 

symbols in a program

symbols in a program

Extra white space is ignored

Extra white space is ignored

A valid Java program can be formatted many 

A valid Java program can be formatted many 

different ways

different ways

Programs should be formatted to enhance 

Programs should be formatted to enhance 

readability, using consistent indentation

readability, using consistent indentation

See

See

 

 

Lincoln2.java 

Lincoln2.java 

and

and

 

 

Lincoln3.java

Lincoln3.java

background image

 

 

49

Programming Language Levels

Programming Language Levels

There are four programming language 

There are four programming language 

levels:

levels:

machine language

machine language

assembly language

assembly language

high-level language

high-level language

fourth-generation language

fourth-generation language

Each type of CPU has its own specific 

Each type of CPU has its own specific 

machine language

machine language

The other levels were created to make it 

The other levels were created to make it 

easier for a human being to write programs

easier for a human being to write programs

background image

 

 

50

Programming Languages

Programming Languages

A program must be translated into machine 

A program must be translated into machine 

language before it can be executed on a 

language before it can be executed on a 

particular type of CPU

particular type of CPU

This can be accomplished in several ways

This can be accomplished in several ways

compiler

compiler

 is a software tool which translates 

 is a software tool which translates 

source code

source code

 into a specific target language

 into a specific target language

Often, that target language is the machine 

Often, that target language is the machine 

language for a particular CPU type

language for a particular CPU type

The Java approach is somewhat different

The Java approach is somewhat different

background image

 

 

51

Java Translation and Execution

Java Translation and Execution

The Java compiler translates Java source code 

The Java compiler translates Java source code 

into a special representation called 

into a special representation called 

bytecode

bytecode

Java bytecode is not the machine language for 

Java bytecode is not the machine language for 

any traditional CPU

any traditional CPU

Another software tool, called an 

Another software tool, called an 

interpreter

interpreter

translates bytecode into machine language and 

translates bytecode into machine language and 

executes it

executes it

Therefore the Java compiler is not tied to any 

Therefore the Java compiler is not tied to any 

particular machine

particular machine

Java is considered to be 

Java is considered to be 

architecture-neutral

architecture-neutral

background image

 

 

52

Java Translation and Execution

Java Translation and Execution

Java source

code

Machine

code

Java

bytecode

Java

interpreter

Bytecode

compiler

Java

compiler

background image

53

Development Environments

Development Environments

There are many development environments 

There are many development environments 

which develop Java software:

which develop Java software:

Sun Java Software Development Kit (SDK)

Sun Java Software Development Kit (SDK)

Borland JBuilder

Borland JBuilder

MetroWork CodeWarrior

MetroWork CodeWarrior

Microsoft Visual J++

Microsoft Visual J++

Symantec Café

Symantec Café

Though the details of these environments 

Though the details of these environments 

differ, the basic compilation and execution 

differ, the basic compilation and execution 

process is essentially the same

process is essentially the same

background image

 

 

54

Syntax and Semantics

Syntax and Semantics

The 

The 

syntax rules

syntax rules

 of a language define how we 

 of a language define how we 

can put symbols, reserved words, and 

can put symbols, reserved words, and 

identifiers together to make a valid program

identifiers together to make a valid program

The 

The 

semantics

semantics

 of a program statement define 

 of a program statement define 

what that statement means (its purpose or 

what that statement means (its purpose or 

role in a program)

role in a program)

A program that is syntactically correct is not 

A program that is syntactically correct is not 

necessarily logically (semantically) correct

necessarily logically (semantically) correct

A program will always do what we tell it to 

A program will always do what we tell it to 

do, not what we 

do, not what we 

meant

meant

 to tell it to do

 to tell it to do

background image

 

 

55

Errors

Errors

A program can have three types of errors

A program can have three types of errors

The compiler will find problems with syntax 

The compiler will find problems with syntax 

and other basic issues (

and other basic issues (

compile-time errors

compile-time errors

)

)

If compile-time errors exist, an executable version 

If compile-time errors exist, an executable version 

of the program is not created

of the program is not created

A problem can occur during program 

A problem can occur during program 

execution, such as trying to divide by zero, 

execution, such as trying to divide by zero, 

which causes a program to terminate 

which causes a program to terminate 

abnormally (

abnormally (

run-time errors

run-time errors

)

)

A program may run, but produce incorrect 

A program may run, but produce incorrect 

results (

results (

logical errors

logical errors

background image

56

Introduction to Graphics

Introduction to Graphics

The last one or two sections of each chapter 

The last one or two sections of each chapter 

of the textbook focus on graphical issues

of the textbook focus on graphical issues

Most computer programs have graphical 

Most computer programs have graphical 

components

components

A picture or drawing must be digitized for 

A picture or drawing must be digitized for 

storage on a computer

storage on a computer

A picture is broken down into pixels, and 

A picture is broken down into pixels, and 

each pixel is stored separately

each pixel is stored separately

background image

57

Representing Color

Representing Color

A black and white picture can be stored using 

A black and white picture can be stored using 

one bit per pixel (0 = white and 1 = black)

one bit per pixel (0 = white and 1 = black)

A color picture requires more information, and 

A color picture requires more information, and 

there are several techniques for representing a 

there are several techniques for representing a 

particular color

particular color

For example, every color can be represented as a 

For example, every color can be represented as a 

mixture of the three primary colors Red, Green, 

mixture of the three primary colors Red, Green, 

and Blue

and Blue

In Java, each color is represented by three 

In Java, each color is represented by three 

numbers between 0 and 255 that are collectively 

numbers between 0 and 255 that are collectively 

called an 

called an 

RGB value

RGB value

background image

58

Coordinate Systems

Coordinate Systems

Each pixel can be identified using a two-

Each pixel can be identified using a two-

dimensional coordinate system

dimensional coordinate system

When referring to a pixel in a Java program, 

When referring to a pixel in a Java program, 

we use a coordinate system with the origin in 

we use a coordinate system with the origin in 

the upper left corner

the upper left corner

Y

X

(0, 0)

(112, 40)

112

40


Document Outline