Lecture 1 Overview: Overview: b Course objectives and structure Course objectives and...
-
Upload
piers-benson -
Category
Documents
-
view
214 -
download
0
Transcript of Lecture 1 Overview: Overview: b Course objectives and structure Course objectives and...
Lecture 1Lecture 1
Overview:Overview:
Course objectives and structureCourse objectives and structure History of computingHistory of computing Hardware and softwareHardware and software Inroduction to the java programming languageInroduction to the java programming language
2
History of ComputingHistory of Computing
Two pivotal concepts:Two pivotal concepts: Mechanization of arithmeticMechanization of arithmetic
• abacus (China 2000-1000bc)abacus (China 2000-1000bc)
• Stonehenge (England 1900-1600bc)Stonehenge (England 1900-1600bc)
• sliderules, Napier bones (Scotland 16th century)sliderules, Napier bones (Scotland 16th century)
• Pascal, Leibniz (France, Germany 17th century)Pascal, Leibniz (France, Germany 17th century)
Automatic control of computationAutomatic control of computation• Jacquard’s automatic loomJacquard’s automatic loom
Design of first computer: Babbage’s “Analytical Engine” (England 1822)Design of first computer: Babbage’s “Analytical Engine” (England 1822)
ENIAC - first fully electronic computer (Eckert & Mauchley, USA 1946)ENIAC - first fully electronic computer (Eckert & Mauchley, USA 1946)
3
Hardware and SoftwareHardware and Software
HardwareHardware• the physical, tangible parts of a computerthe physical, tangible parts of a computer
• keyboard, monitor, wires, chips, datakeyboard, monitor, wires, chips, data
SoftwareSoftware• programs and dataprograms and data
• a a programprogram is a series of instructions is a series of instructions
4
CPU and Main MemoryCPU and Main Memory
CentralProcessing
Unit
MainMemory
Chip that executes Chip that executes program commandsprogram commands
Intel Pentium IIIIntel Pentium IIISun Sparc ProcessorSun Sparc Processor
Primary storage area Primary storage area for programs and data for programs and data
that are in active usethat are in active use
Synonymous with Synonymous with RAMRAM
5
Input / Output DevicesInput / Output Devices
Monitor
Keyboard
MainMemory
CentralProcessing
Unit
I/O devices allow userI/O devices allow userinteractioninteraction
Monitor screenMonitor screenKeyboardKeyboardMouseMouseBar code scannerBar code scannerLight penLight penTouch screenTouch screen
6
Secondary Memory DevicesSecondary Memory Devices
Floppy Disk
Hard DiskMain
Memory
CentralProcessing
Unit
Secondary memorySecondary memorydevices providedevices providelong-term storagelong-term storage
Information is movedInformation is movedbetween main memorybetween main memoryand secondary memoryand secondary memoryas neededas needed
Hard disksHard disksFloppy disksFloppy disksZIP disksZIP disksWritable CDsWritable CDsTapesTapes
7
Software CategoriesSoftware Categories
Operating SystemOperating System• controls all machine activitiescontrols all machine activities
• provides the user interface to the computerprovides the user interface to the computer
• manages resources such as the CPU and memorymanages resources such as the CPU and memory
• Windows 98, Windows NT, Unix, Linux, Mac OSWindows 98, Windows NT, Unix, Linux, Mac OS
Application programApplication program• generic term for any other kind of softwaregeneric term for any other kind of software
• word processors, missile control systems, gamesword processors, missile control systems, games
Most operating systems and application programs have a Most operating systems and application programs have a graphical user interface (GUI)graphical user interface (GUI)
8
Digital InformationDigital Information
Computers store all information digitally:Computers store all information digitally:• numbersnumbers
• texttext
• graphics and imagesgraphics and images
• audioaudio
• videovideo
• program instructionsprogram instructions
In some way, all information is In some way, all information is digitizeddigitized - broken down into - broken down into pieces and represented as numberspieces and represented as numbers
9
MemoryMemory
Main memory is divided Main memory is divided into many memory into many memory locations (or locations (or cellscells))
9278927892799279
92809280928192819282928292839283928492849285928592869286
Each memory cell has a Each memory cell has a numeric numeric addressaddress, which , which uniquely identifies ituniquely identifies it
10
Storing InformationStoring Information
9278927892799279
92809280928192819282928292839283928492849285928592869286
Large values areLarge values arestored in consecutivestored in consecutivememory locationsmemory locations
1001101010011010Each memory cell stores a Each memory cell stores a set number of bits (usually set number of bits (usually 8 bits, or one 8 bits, or one bytebyte))
11
The Central Processing UnitThe Central Processing Unit
A CPU is also called a A CPU is also called a microprocessormicroprocessor It continuously follows the It continuously follows the fetch-decode-execute cycle:fetch-decode-execute cycle:
fetch
Retrieve an instruction from main memoryRetrieve an instruction from main memory
decode
Determine what theDetermine what theinstruction isinstruction is
execute
Carry out theCarry out theinstructioninstruction
12
The Central Processing Unit The Central Processing Unit (CPU)(CPU) The CPU contains:The CPU contains:
Arithmetic / Logic Unit
Registers
Control Unit
Small storage Small storage areasareas
Performs calculations Performs calculations and decisionsand decisions
Coordinates Coordinates processing stepsprocessing steps
13
The Central Processing UnitThe Central Processing Unit
The speed of a CPU is controlled by the The speed of a CPU is controlled by the system clocksystem clock
The system clock generates an electronic pulse at regular The system clock generates an electronic pulse at regular intervalsintervals
The pulses coordinate the activities of the CPUThe pulses coordinate the activities of the CPU
The speed is measured in The speed is measured in megahertzmegahertz (MHz) (MHz)
14
Problem SolvingProblem Solving
The purpose of writing a program is to solve a problemThe purpose of writing a program is to solve a problem
The general steps in problem solving are:The general steps in problem solving are:
• Understand the problemUnderstand the problem
• Dissect the problem into manageable piecesDissect the problem into manageable pieces
• Design a solutionDesign a solution
• Consider alternatives to the solution and refine itConsider alternatives to the solution and refine it
• Implement the solutionImplement the solution
• Test the solution and fix any problems that existTest the solution and fix any problems that exist
15
Problem SolvingProblem Solving
Many software projects fail because the developer didn't Many software projects fail because the developer didn't really understand the problem to be solvedreally understand the problem to be solved
We must avoid assumptions and clarify ambiguitiesWe must avoid assumptions and clarify ambiguities
As problems and their solutions become larger, we must As problems and their solutions become larger, we must organize our development into manageable piecesorganize our development into manageable pieces
This technique is fundamental to software developmentThis technique is fundamental to software development We will dissect our solutions into pieces called classes and We will dissect our solutions into pieces called classes and
objects, taking an objects, taking an object-oriented approachobject-oriented approach
16
The Java Programming The Java Programming LanguageLanguage
A A programming languageprogramming language specifies the words and symbols specifies the words and symbols that we can use to write a programthat we can use to write a program
A programming language employs a set of rules that dictate A programming language employs a set of rules that dictate how the words and symbols can be put together to form how the words and symbols can be put together to form valid valid program statementsprogram statements
Java was created by Sun Microsystems, Inc.Java was created by Sun Microsystems, Inc. It was introduced in 1995 and has become quite popularIt was introduced in 1995 and has become quite popular It is an object-oriented languageIt is an object-oriented language
17
Java Program StructureJava 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 classesclasses
• A class contains one or more A class contains one or more methodsmethods
• A method contains program A method contains program statementsstatements
These terms will be explored in detail throughout the These terms will be explored in detail throughout the coursecourse
A Java application always contains a method called A Java application always contains a method called mainmain
See See Lincoln.javaLincoln.java (page 26)(page 26)
18
Java Program StructureJava Program Structure
public class MyProgram
{
}
// comments about the class
class headerclass header
class bodyclass body
Comments can be added almost anywhereComments can be added almost anywhere
19
Java Program StructureJava Program Structure
public class MyProgram
{
}
public static void main (String[] args)
{
}
// comments about the class
// comments about the method
method headermethod headermethod bodymethod body
20
CommentsComments
Comments in a program are also called Comments in a program are also called inline inline documentationdocumentation
They should be included to explain the purpose of the They should be included to explain the purpose of the program and describe processing stepsprogram and describe processing steps
They do not affect how a program worksThey 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 */
21
IdentifiersIdentifiers
IdentifiersIdentifiers are the words a programmer uses in a program are the words a programmer uses in a program
An identifier can be made up of letters, digits, the An identifier can be made up of letters, digits, the underscore character (_), and the dollar signunderscore character (_), and the dollar sign
They cannot begin with a digitThey cannot begin with a digit
Java is Java is case sensitivecase sensitive, therefore, therefore Total Total andand total total are are different identifiersdifferent identifiers
22
IdentifiersIdentifiers
Sometimes we choose identifiers ourselves when writing a Sometimes we choose identifiers ourselves when writing a program (such as program (such as LincolnLincoln))
Sometimes we are using another programmer's code, so we Sometimes we are using another programmer's code, so we use the identifiers that they chose (such as use the identifiers that they chose (such as printlnprintln))
Often we use special identifiers called Often we use special identifiers called reserved wordsreserved words that that already have a predefined meaning in the languagealready have a predefined meaning in the language
A reserved word cannot be used in any other wayA reserved word cannot be used in any other way
23
Reserved WordsReserved Words
The Java reserved words:The Java reserved words:
abstractbooleanbreakbytebyvaluecasecastcatchcharclassconstcontinue
defaultdodoubleelseextendsfalsefinalfinallyfloatforfuturegeneric
gotoifimplementsimportinnerinstanceofintinterfacelongnativenewnull
operatorouterpackageprivateprotectedpublicrestreturnshortstaticsuperswitch
synchronizedthisthrowthrowstransienttruetryvarvoidvolatilewhile
24
White SpaceWhite Space
Spaces, blank lines, and tabs are collectively called Spaces, blank lines, and tabs are collectively called white white spacespace
White space is used to separate words and symbols in a White space is used to separate words and symbols in a programprogram
Extra white space is ignoredExtra white space is ignored A valid Java program can be formatted many different A valid Java program can be formatted many different
waysways Programs should be formatted to enhance readability, Programs should be formatted to enhance readability,
using consistent indentationusing consistent indentation SeeSee Lincoln2.java Lincoln2.java andand Lincoln3.javaLincoln3.java
25
Programming Language LevelsProgramming Language Levels
There are four programming language levels:There are four programming language levels:• machine languagemachine language
• assembly languageassembly language
• high-level languagehigh-level language
• fourth-generation languagefourth-generation language
Each type of CPU has its own specific Each type of CPU has its own specific machine languagemachine language
The other levels were created to make it easier for a human The other levels were created to make it easier for a human being to write programsbeing to write programs
26
Programming LanguagesProgramming Languages
A program must be translated into machine language A program must be translated into machine language before it can be executed on a particular type of CPUbefore it can be executed on a particular type of CPU
This can be accomplished in several waysThis can be accomplished in several ways
A A compilercompiler is a software tool which translates is a software tool which translates source codesource code into a specific target languageinto a specific target language
Often, that target language is the machine language for a Often, that target language is the machine language for a particular CPU typeparticular CPU type
The Java approach is somewhat differentThe Java approach is somewhat different
27
Java Translation and ExecutionJava Translation and Execution
The Java compiler translates Java source code into a The Java compiler translates Java source code into a special representation called special representation called bytecodebytecode
Java bytecode is not the machine language for any Java bytecode is not the machine language for any traditional CPUtraditional CPU
Another software tool, called an Another software tool, called an interpreterinterpreter, translates , translates bytecode into machine language and executes itbytecode into machine language and executes it
Therefore the Java compiler is not tied to any particular Therefore the Java compiler is not tied to any particular machinemachine
Java is considered to be Java is considered to be architecture-neutralarchitecture-neutral
28
Java Translation and ExecutionJava Translation and Execution
Java sourcecode
Machinecode
Javabytecode
Javainterpreter
Bytecodecompiler
Javacompiler
29
Development EnvironmentsDevelopment Environments
There are many development environments which develop There are many development environments which develop Java software:Java software:• Sun Java Software Development Kit (SDK)Sun Java Software Development Kit (SDK)
• Borland JBuilderBorland JBuilder
• MetroWork CodeWarriorMetroWork CodeWarrior
• Microsoft Visual J++Microsoft Visual J++
• Symantec CaféSymantec Café
Though the details of these environments differ, the basic Though the details of these environments differ, the basic compilation and execution process is essentially the samecompilation and execution process is essentially the same
30
Syntax and SemanticsSyntax and Semantics
The The syntax rulessyntax rules of a language define how we can put of a language define how we can put symbols, reserved words, and identifiers together to make a symbols, reserved words, and identifiers together to make a valid programvalid program
The The semanticssemantics of a program statement define what that of a program statement define what that statement means (its purpose or role in a program)statement means (its purpose or role in a program)
A program that is syntactically correct is not necessarily A program that is syntactically correct is not necessarily logically (semantically) correctlogically (semantically) correct
A program will always do what we tell it to do, not what we A program will always do what we tell it to do, not what we meantmeant to tell it to do to tell it to do
31
ErrorsErrors
A program can have three types of errorsA program can have three types of errors
The compiler will find problems with syntax and other The compiler will find problems with syntax and other basic issues (basic issues (compile-time errorscompile-time errors))• If compile-time errors exist, an executable version of the program is If compile-time errors exist, an executable version of the program is
not creatednot created
A problem can occur during program execution, such as A problem can occur during program execution, such as trying to divide by zero, which causes a program to trying to divide by zero, which causes a program to terminate abnormally (terminate abnormally (run-time errorsrun-time errors))
A program may run, but produce incorrect results (A program may run, but produce incorrect results (logical logical errorserrors) )
32
Introduction to GraphicsIntroduction to Graphics
The last one or two sections of each chapter of the textbook The last one or two sections of each chapter of the textbook focus on graphical issuesfocus on graphical issues
Most computer programs have graphical componentsMost computer programs have graphical components
A picture or drawing must be digitized for storage on a A picture or drawing must be digitized for storage on a computercomputer
A picture is broken down into pixels, and each pixel is A picture is broken down into pixels, and each pixel is stored separatelystored separately
33
Coordinate SystemsCoordinate Systems
Each pixel can be identified using a two-dimensional Each pixel can be identified using a two-dimensional coordinate systemcoordinate system
When referring to a pixel in a Java program, we use a When referring to a pixel in a Java program, we use a coordinate system with the origin in the upper left cornercoordinate system with the origin in the upper left corner
Y
X(0, 0)
(112, 40)
112
40