Académique Documents
Professionnel Documents
Culture Documents
Chapter 1
Computer Systems
1/73
Basic Computer Processing
A computer system is made up of hardware
and software.
Hardware: Chips, keyboards, disks, etc.
Software: Programs and the data those
programs use.
Key Components of a Computer System
central processing unit (CPU)
input/output (I/O) devices
main memory
secondary memory devices
2/73
Memory
Programs and data are held in storage devices called
memory, which fall into two categories:
Main Memory
The storage device (e.g., chips on the mother board)
3/73
Software Categories
5/73
More: What this means to us
You will dowload the J2SE Standard Edition
and Development Kit JDK 5.0 () from Sun
Microsystems.
You will also download Netbeans and install
it.
See separate link for tutorial on this.
6/73
Analog versus Digital Signals
Analog information and/or signals are continuous,
varying in direct proportion to the source of the
information – like the amplitude of a wave may vary
with volume. It’s period may vary with frequency…
7/73
An Analog Signal
versus a Digital Signal
analog digital
8/73
Binary Numbers
A digital computer stores information as
numbers, but those numbers are not stored
as decimal numbers.
All information in a computer is stored and
managed as binary values.
The binary number system has only two digits,
0 and 1.
A single binary digit is called a bit.
9/73
Converting Binary Numbers
to Decimal Numbers
Starting with the rightmost bit in a binary number,
each position represents a power of 2, with the
rightmost bit position representing 20 which is decimal
1, the next bit position representing 21 which is 2 and
the next representing 22 which is 4, etc.
Binary 1011 is 1* 23 or 8 + 0 * 22 or 0 + 1 * 21 or 2 +
1 * 20 or 1 which adds up to 11 decimal (base 10).
Binary 11001001 is 201 decimal.
CAN YOU DO THIS????
In general, n bits can represent 2n unique items.
Computers typically manipulate sequences of 8 bits
with each sequence of 8 bits referred to as a byte.
10/73
Hardware Components
We use the term computer architecture to describe how
the hardware components of a computer are put together.
A program and its data reside in main memory while the
program runs.
The Central Processing Units (CPU) reads one program
instruction from main memory and executes it.
(Called ‘fetch – execute’ cycle)
12/73
Input/Output Devices
For our purposes, the primary I/O devices will be the
keyboard and the monitor.
Output on a monitor is achieved by breaking the
screen picture into small pieces called picture
elements (pixels).
The pixels are represented in the computer as
numbers (as is everything else) and each pixel has a
specific ‘screen address.’
A typical monitor can display a number of ‘screen
resolutions’ such as 640x480, 800x720, 1280 x 1024
and others…
These numbers represent the number of pixels used
to display the screen information.
13/73
Main Memory and Secondary
Memory
Main memory is made up of a series of consecutive
memory locations called addresses.
Associated with each memory location is a unique
address.
On many computers, each memory location consists of
8 bits, or one byte of information.
18/73
Central Processing Unit
The ‘processor’ interprets and executes your
program’s instructions one at a time – sequentially.
Consists of the arithmetic and logic unit, the control
unit, and the registers (usually in the ALU and Control
Units)
Control unit dissects the instruction and directs the
ALU to perform the calculations / comparisons using
the registers.
In CPU there are additional registers:
Instruction register; program counter, more
19/73
CPU - more
The notion of a stored-program computer – a
von Neumann machine – stored both program
instructions and data together in main memory.
Fetch-decode-execute cycle
Fetch instruction from primary memory (RAM)
Decode instruction (to see what it is to be done)
Execute the instruction using registers
Repeat
20/73
CPU - more
CPU on a chip called a microprocessor
Circuit board also contains communications
sockets, etc. for connection with video
displays, etc.
Main circuit board also contains the system
clock which pulses.
Instructions are in synch with these pulses
Some take a single pulse; others, more.
Often called clock speed.
21/73
Networks
A network is two or more computers
connected together so they can exchange
information.
Each computer of a network has its own
network address.
One technique to improve network speed is to
divide large messages into segments, called
packets.
Packets have fixed formats and other
constraints…
Then send the individual packets across the
network intermixed with pieces of other
messages sent by other users. 22/73
Local Area Networks and
Wide Area Networks
A local-area network (LAN) is designed to span
short distances and connect a relatively small
number of computers.
Within a building or small area
You may connect to the LAN here in this classroom
and see these slides/ take notes on them, etc.
A wide-area network (WAN) connects two or more
LANs, often across long distances.
LANs connected by a WAN are often owned by
different companies or organizations, and might even
be located in different countries.
Generally, one computer takes care of
communications.
23/73
The Internet
The Internet is a network of networks.
Grew out of U.S Governmentt ARPA (and ARPAnet)
In 2000, number of computers connected to Internet = 10
million.
A protocol is a set of rules that governs how two things
communicate.
The software that controls the movement of messages
across the Internet must conform to a set of protocols called
TCP/IP for Transmission Control Protocol/Internet
Protocol.
IP defines how information is formatted and transferred
TCP software handles the transmission and reconstituting
of messages, error control, etc. (contention, …)
Every computer connected to the Internet has an IP address
that uniquely identifies it among all other computers on the
Internet. 24/73
IP Address vs Internet Address
An IP address is of the form 204.192.116.2.
Fortunately, Internet allows each computer to be given a
unique name - often referred to as its Internet Address.
The first part of an Internet Address is the local name of a
specific computer.
The rest of the name is the domain name.
Ours is: osprey.unf.edu.
Osprey is local name
unf.edu is the domain name.
Can have ‘subdomains’ within domain for departments, etc.
26/73
The World Wide Web
The World Wide Web (also known as WWW or the
Web) makes the exchange of information easy.
Web software provides a common interface through
which many different types of information can be
accessed with a mouse click.
Web: based on concepts of hypertext & hypermedia.
Hypertext – based on links to support jumping as needed.
To manage large amounts of information. Basically
used to originally link ‘documents.’
Hypermedia incorporates graphics, sound, animations,
and video.
27/73
Hypertext and Browsers
Web Server: computer dedicated to providing
access to Web documents.
Browsers load / interpret documents provided
by a Web server.
Many documents are formatted using the
HyperText Markup Language (HTML).
Links to Java programs can be embedded in
html documents and executed through Web
browsers.
28/73
Uniform Resource Locators
Information on the Web is found by identifying a
Uniform Resource Locator (URL)
A URL uniquely specifies documents and other
information for a browser to obtain and display.
An example URL is http://www.unf.edu
URL:
First piece of URL is a protocol (HyperText Transfer
Protocol – HTTP in this example) which determines
the way the browser should communicate.
The second piece is the Internet address of the
machine on which the document is stored.
A typical third piece of information is the file name of
the file you wish to view.
Default third piece: index.html
29/73
Another Sample URL
http://www.unf.edu/campus
In this URL, the protocol is http (HyperText Transfer Protocol).
Machine referenced is www (web server found at unf.edu)
Information is stored in a ‘file’ named campus.
www.unf.edu/~broggio refers to an index.html file stored in a
directory, broggio, within some UNF web server
The Internet vs the World Wide Web
The Internet makes it possible to communicate
via computers around the world.
Internet IS a network; Communications…
The Web makes that communication a
straightforward and enjoyable activity via software.
The Web can be used on a LAN or even a single machine that is not
connected to any network.
Information service based on a set of software applications 30/73
The Internet
A global network connecting millions of computers.
More than 100 countries are linked into exchanges of
data, news and opinions.
Unlike online services, which are centrally controlled, the
Internet is decentralized by design. Each Internet
computer, called a host, is independent. Its operators
can choose which Internet services to use and which
local services to make available to the global Internet
community. Remarkably, this anarchy by design works
exceedingly well.
There are a variety of ways to access the Internet. Most
online services, such as America Online, offer access to
some Internet services. It is also possible to gain access
through a commercial Internet Service Provider (ISP).
The Internet is not synonymous with World Wide Web.
31/73
World Wide Web
A system of Internet servers that support specially
formatted documents.
The documents are formatted in a markup language
called HTML (HyperText Markup Language) that
supports links to other documents, as well as graphics,
audio, and video files.
This means you can jump from one document to another
simply by clicking on hot spots. Not all Internet servers
are part of the World Wide Web.
There are several applications called Web browsers that
make it easy to access the World Wide Web; Two of the
most popular being Netscape Navigator and Microsoft's
Internet Explorer.
World Wide Web is not synonymous with the Internet.32/73
Programming
The rest of this course explores the process
of creating programs using Java.
All of the software we have discussed
including the Internet and Web protocols are
programs that some programmer has written.
Next section discusses the purpose of
programming in general and introduces the
Java Programming Language.
33/73
Problem Solving – Know this!
The purpose of writing a program is to solve a
problem. Problem solving consists of multiple steps:
1. Understanding the problem (requirements)
2. Breaking the problem into manageable pieces.
(Specifying the requirements) (capturing, modeling…)
3. Designing a solution. (various kinds / levels)
4. Considering alternatives to solution and refining solution.
5. Implementing the solution. (Programming)
6. Testing the solution and fixing any problems that exist.
7. Deployment and
8. Maintenance
34/73
How do these Steps Apply to You?
By the time you complete a degree in Computer and
Information Sciences you will have experienced all of
these problem solving steps and practiced them often.
Here, emphasis is on learning programming and much
of the other work is done for you.
But be aware: the most common mistakes are:
1. Not fully studying and understanding the
problem;
2. Designing a solution.
In learning how to program, we MUST understand
where actual programming ‘fits’ in solving a problem!
35/73
The Java Programming Language
A programming language defines a set of rules:
That determine exactly how a programmer can
combine words and symbols of the language into
programming statements.
Called syntax.
Programming statements are the instructions that are
carried out when the program is executed.
Java is an object-oriented programming language.
Java is one of the fastest growing programming
technologies of all time.
36/73
Reasons Why Java is Popular
Java is the first programming language to deliberately
embrace the concept of writing programs that can be
executed on the Web.
Moreso, Java is a useful general purpose programming
language.
The Java language is accompanied by a library of extra
software that we can use when developing programs.
The library provides the ability to create graphics,
communicate over networks, and interact with
databases.
The set of supporting libraries is huge and versatile.
37/73
A Java Program
See Lincoln.java on page 30.
/* Lewis/Loftus 6/11/2003
40/73
The println() Method
The two lines of code in the main() method invoke another
method called println() (pronounced print line).
Our program must invoke, or call, a method at the point
where we want the method to execute.
The println() method prints the specified characters that
were sent to it within double quotes.
The characters to be printed are represented as a
character string, enclosed in double quote characters
(“The string you want to print.”).
The code for the println() method definition is in a library
in the object System.out.
We just need to call the println() method and pass it the
String you want to display.
We do not know (or care) how println actually works. We
merely send it the data to be printed within quotes.
41/73
Another Look at Lincoln.java
See Lincoln.java on page 30.
/* Lewis/Loftus 6/11/2003
public class Lincoln // The class name is the same as the file name, but
{ // without the .java extension.
// Prints a presidential quote.
public static void main (String[] args) // This line is the method ‘header’
{ // The method body starts with the left bracket.
// The println() method is found in the System class in a Java library
System.out.println(“A quote by Abraham Lincoln:“);
//********************************************************************
// Lincoln.java Author: Lewis/Loftus
//
// Demonstrates the basic structure of a Java application.
//********************************************************************
}
Reserved Words
The Java reserved words – these words cannot be used for
any other purpose, such as naming a class or method.
50/73
Rules for Naming Identifiers
An identifier (created by us) can be
composed letters, digits, the underscore
character ( _ ), and the dollar sign ($), but it
cannot begin with a digit.
Java is case sensitive, which means that two
identifier names that differ only in the case of
their letters are considered to be different
identifiers.
Total, Total, ToTaL, and TOTAL are all different
identifiers.
e.g. x = 4;
51/73
Conventions for Naming Identifiers
Use a consistent case format:
52/73
Choosing Identifier Names
Identifier names should be descriptive but not
verbose.
Avoid meaningless names such as a or x.
Unless the name is actually descriptive, such as
using x and y to represent (x, y) coordinates.
Avoid using unnecessarily long names.
A “name” in Java is sometimes a series of
identifiers separate by the dot (period) character.
The name System.out is the ‘name’ of an object
through which we invoke the println method.
(println is a method inside the object.)
53/73
White Space
White space consists of blanks, tabs, and newline
characters.
White space is used to separate the words and
symbols used in Java programs.
A programmer can use white space to emphasize parts
of the program and to make the program easier to
read.
Except when it’s used to separate words, the
computer ignores white space.
Allows programmers flexibility in formatting a program.
Discuss
The guidelines in Appendix F discuss the appropriate
use of white space.
54/73
Programming Languages
Programming languages are often
categorized into the following four
classifications:
1. Machine Languages
2. Assembly Languages
3. High-Level Languages
4. Fourth-Generation Languages
In order for a program to run on a computer,
it must ultimately be expressed in that
computer’s machine language.
55/73
From Machine Language
to Assembly Language
Each machine language instruction can accomplish only one
simple task.
For example, copy a value into a register or compare two
values or add two numbers together….
Machine language code is expressed as a series of binary
digits and is extremely difficult for humans to read and write.
Enter: Assembly Language
These are symbolic versions of machine language
statements using mnemonics, short English-like words that
represent commands or data.
E.g. Instead of:
01011010100000000101000000000100 (32 bits)
5A805004 in hex may be rewritten in Assembler language as
A 8,4(5,0) or, A 8,X Add what’s ‘at’ X to register 8
LR 4,5 (load register 4 from register 5)
56/73
From Low-level Languages
to High-level Languages
Both assembly language and machine language
are considered low-level languages.
Generally, each assembly language instruction
corresponds to an equivalent machine language
instruction.
Today most programmers use a high-level language
to write software.
A high-level language is expressed in English-like
phrases, approaching natural language.
A single high-level language programming statement
can accomplish the equivalent of many – perhaps
hundreds – of machine language instructions.
Examples: Java, C, C++, COBOL, Pascal, C#
57/73
Fourth-Generation Languages
Some programming languages operate at an
even higher level.
They might include automatic report generation
or interaction with a database.
These languages are called fourth-generation
languages, or simply 4GLs, because they
followed first three generations of computer
programming: machine, assembly, and HLL.
Examples: RPG, SQL, Forth, etc…
58/73
Compilers and Interpreters
Initially, you will use an editor as you type a program into a
computer and store it in a file.
We will be using the editor built into the NetBeans IDE.
After editing and saving your program, you attempt to translate
it from this high-level code Java code (source language
statements) into a form that can be executed, that is
ultimately into machine language.
The translation (we call it ‘compilation’) may result in
errors errors
61/73
A Compiler
A compiler is a program that translates code from one language to
an equivalent code in another language. (either to assembler
language or to ultimate machine language, which can be executed)
The original code is called source-code.
The language to which it is translated is the target language.
For many traditional compilers, the source code is translated
directly into a particular machine language.
In that case, the translation process occurs once and
the resulting executable program can be saved and
then run whenever needed.
In other cases, assembler code is produced from the compiler
and then the assembler is called to translate this lower level
language code into machine language.
62/73
An Interpreter
An interpreter is similar to a compiler but has
important differences…
An interpreter interleaves the translation and execution
activities.
A small part of the source code, such as one
statement, is translated and executed.
Then another part is translated and executed, etc.
63/73
Java Uses Both a
Compiler and Interpreter
The Java compiler translates Java source
code into something called: Java ‘bytecode.’
Bytecode is a representation of the program in
a low-level code similar (but not the same as)
machine language code.
The Java interpreter then reads a short
segment of Java bytecode, translates that
segment into machine language and
executes it.
This process is repeated as program executes.
64/73
The Advantage of Java Bytecode
The difference between Java bytecode and true
machine language code is that Java bytecode is not
tied to any particular processor type. Machine
Independent!
Most compilers generate machine code (or
assembler code) that can only be executed on a
particular machine / machine series….
This makes Java “architecture neutral” Thus this
feature makes Java easily portable from one machine
to another.
All you need is a Java interpreter or bytecode
compiler for each processor type on which the
bytecode is to be executed.
65/73
Integrated Development
Environments (IDEs)
IDEs combine an editor, compiler, and other
(Java) support tools into a single program.
NetBeans contains a number of super nice
features including the ability to step through a
program, set ‘breakpoints,’ and many more.
There are many IDEs including Borland’s
JBuilder and IBM’s Eclipse, JGrasp
(developed by Auburn), the medEditor, and
many more…
66/73
NetBeans 5.5 or 6.0
Refer to my web page and show links.
Project 0 is there.
We will submit programs via Blackboard’s
Digital Drop Box.
Follow instructions very carefully in project 0.
67/73
More on: Syntax and Semantics
Each programming language has its own unique
syntax.
The syntax consstitutes the rules of a language
that dictate exactly how the vocabulary elements of
the language can be combined to form statements.
(Just like grammar rules in English.)
During compilation, all syntax rules are checked.
If a program is not syntactically correct, the compiler
gives error messages and won’t produce the bytecode
file (that is, the .class file).
Syntax errors must be eliminated before the bytecodes
are produced that allows us to try to ‘execute’ the
program. 68/73
Semantics (meaning)
The semantics of a statement in a
programming language define what will happen
when that statement is executed.
Programming languages are generally
unambiguous, which means that there is one
and only one interpretation for each statement.
The same exact English sentence can have
multiple valid meanings.
A computer language cannot allow such
ambiguities to exist.
69/73
Errors
You will encounter three kinds of errors as
you develop programs:
1. Compile-time errors
2. Runtime errors
3. Logical errors
70/73
Compile-time and Run-time Errors
An error identified by the compiler is called a
compile-time error. (These are syntax errors)
If a compile-time error occurs, an executable version of
the program is not created.
Use your editor to correct the error, then recompile
your program.
A runtime error causes the program to terminate
abnormally during execution.
An example is an attempt to divide by zero.
In Java, many runtime errors are represented as
exceptions that can be caught and dealt with on the
chapter dealing with Exceptions.
In this instance, your program will ‘bomb.’
71/73
Logical Errors
When your program has a logical error, it will
compile and execute, but produces incorrect
results. (These are runtime errors too!)
A logical error occurs when a value is
calculated incorrectly.
A programmer must test the program
thoroughly, comparing the expected results to
those that actually occur.
e.g., z=a+b; instead of z=a*b;
The process of finding and correcting defects in a
program is called debugging.
72/73