INF 523Q Chapter 1: Computer Systems. 2 Focus of the Course b Object-Oriented Software Development problem solvingproblem solving program design and implementationprogram.
Post on 21-Dec-2015
214 Views
Preview:
Transcript
2
Focus of the CourseFocus of the Course
Object-Oriented Software DevelopmentObject-Oriented Software Development
• problem solvingproblem solving
• program design and implementationprogram design and implementation
• object-oriented conceptsobject-oriented concepts– objectsobjects
– classesclasses
– interfacesinterfaces
– inheritanceinheritance
– polymorphismpolymorphism
• the Java programming languagethe Java programming language
3
ComputerComputer SystemsSystems
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
A computer requires both hardware and softwareA computer requires both hardware and software Each is essentially useless without the otherEach is essentially useless without the other
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
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
6
Input / Output DevicesInput / Output Devices
Monitor
Keyboard
MainMemory
CentralProcessing
Unit
Floppy Disk
Hard Disk
I/O devices allow userI/O devices allow userinteractioninteraction
Monitor screenMonitor screenKeyboardKeyboardMouseMouseBar code scannerBar code scannerLight penLight penTouch screenTouch screen
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
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
10
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
11
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
12
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
13
A Sample Java Program: A Sample Java Program: Lincoln.javaLincoln.java
//*********************************************************** // Lincoln.java Author: Lewis and Loftus
// // Demonstrates the basic structure of a Java application. //*********************************************************** public class Lincoln { //----------------------------------------------------------------- // Prints a presidential quote. //----------------------------------------------------------------- public static void main (String[] args) { System.out.println ("A quote by Abraham Lincoln:");
System.out.println ("Whatever you are, be a good one."); } }
14
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
15
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
16
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 */
17
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
18
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
19
Reserved WordsReserved Words
The Java reserved words:The Java reserved words:
abstractbooleanbreakbytebyvaluecasecastcatchcharclassconstcontinue
defaultdodoubleelseextendsfalsefinalfinallyfloatforfuturegeneric
gotoifimplementsimportinnerinstanceofintinterfacelongnativenewnull
operatorouterpackageprivateprotectedpublicrestreturnshortstaticsuperswitch
synchronizedthisthrowthrowstransienttruetryvarvoidvolatilewhile
20
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
21
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
22
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
23
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
24
Java Translation and ExecutionJava Translation and Execution
Java sourcecode
Machinecode
Javabytecode
Javainterpreter
Bytecodecompiler
Javacompiler
25
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
26
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
27
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) )
top related