1Chapter 1 Chapter 1 --IntroductionIntroductionCh 1GoalsCh 1GoalsTo understand the To understand the activity of programmingactivity of programmingTo learn about the To learn about the architecturearchitectureof computersof computersTo learn about To learn about machine codemachine codeand and high level high level programming languagesprogramming languagesTo become familiar with your computingTo become familiar with your computingenvironmentenvironmentand yourand yourcompilercompilerTo To compile and runcompile and runyour first Java programyour first Java programTo To recognize syntax and logic errorsrecognize syntax and logic errors1.1 What is Programming?1.1 What is Programming?Computers are programmed to perform Computers are programmed to perform tasks tasks Different tasks = different programsDifferent tasks = different programsProgram Program Sequence of basic operations executed in Sequence of basic operations executed in succession succession Contains instruction sequences for all tasks it Contains instruction sequences for all tasks it can execute can execute How do we produce this program?How do we produce this program?1.2 Anatomy of a Computer1.2 Anatomy of a ComputerA computer is a machine that can do A computer is a machine that can do certain taskscertain tasksStores dataStores dataInteracts with devicesInteracts with devicesExecutes programsExecutes programsCPUCPUCentral Processing Unit (CPU) Central Processing Unit (CPU) --Heart of the Heart of the computercomputerMade of a chip (AMD, Intel, etc), millions of transistorsMade of a chip (AMD, Intel, etc), millions of transistorsExecutes instructions given by a programExecutes instructions given by a program1.2 Anatomy of a Computer1.2 Anatomy of a ComputerStorage Storage ––where data is keptwhere data is kept3 types 3 types ––primary, secondary, removableprimary, secondary, removable21.2 Anatomy of a Computer1.2 Anatomy of a ComputerComputers communicate through a Computers communicate through a networknetworkPeripheral devicesPeripheral devicesallow interaction with allow interaction with humanshumansSpeakers, screen, printer, scannerSpeakers, screen, printer, scannerRAM, Disks, peripherals connected to CPU RAM, Disks, peripherals connected to CPU via the via the busbusWhere is a program stored when it is not Where is a program stored when it is not currently running? currently running? Which part of the computer carries out Which part of the computer carries out arithmetic operations, such as addition arithmetic operations, such as addition and multiplication? and multiplication? 1.3 Translating Human1.3 Translating Human--Readable Readable Programs to Machine CodePrograms to Machine CodeThere are actually multiple levels upon which There are actually multiple levels upon which a program can be writtena program can be writtenMachine InstructionsMachine InstructionsAssembly Assembly High Level LanguageHigh Level LanguageMachine CodeMachine CodeThe most basic level of instructionsThe most basic level of instructionsEverything is represented with numbers (read Everything is represented with numbers (read in binary)in binary)Looks like this:Looks like this:00010101 00101000 (binary)00010101 00101000 (binary)21 40 (decimal)21 40 (decimal)This is the only language the CPU knowsThis is the only language the CPU knowsWhatWhat’’s the problem?s the problem?CPUs perform very primitive operations onlyCPUs perform very primitive operations onlyAdd, subtract, load from memoryAdd, subtract, load from memoryLeads to coding of several hundred lines to Leads to coding of several hundred lines to perform one simple operationperform one simple operationNot IntuitiveNot IntuitiveCan you look at 1000 numbers and tell what the Can you look at 1000 numbers and tell what the program is doing?program is doing?Each CPU uses a different set of instructionsEach CPU uses a different set of instructionsEach CPU translates different digits to mean Each CPU translates different digits to mean different thingsdifferent things3AssemblyAssemblyA slight step up from machineA slight step up from machineUses words and numbersUses words and numbersload 40load 40Still needs as many instructions as machine Still needs as many instructions as machine language, but is language, but is slightlyslightlyeasier to read.easier to read.High LevelHigh LevelHigh level is much more expressiveHigh level is much more expressiveOne statement is converted into several One statement is converted into several machine code instructionsmachine code instructionsThe conversion is done by the The conversion is done by the compilercompilerVery complicated and sophisticated, not the Very complicated and sophisticated, not the focus of this coursefocus of this course1.4 The Java Programming Language1.4 The Java Programming LanguageSimple Simple Safe Safe ––more secure, easier to catch more secure, easier to catch errorserrorsPlatformPlatform--independent ("write once, run independent ("write once, run anywhere") anywhere") ––operating system and operating system and architecturearchitectureRich library (packages)Rich library (packages)Designed for the Internet Designed for the Internet Java Virtual MachineJava Virtual MachineUnique to JavaUnique to JavaInstead of compiling for a particular Instead of compiling for a particular processor, Java compiles to a virtual processor, Java compiles to a virtual processor that is the same for every processor that is the same for every computercomputerLesson: The code is the same no matter Lesson: The code is the same no matter what computer you are on, so you donwhat computer you are on, so you don’’t t have to make a Mac version and a PC have to make a Mac version and a PC version, etc.version, etc.FlawsFlawsFully objectFully object--oriented nature can be oriented nature can be confusing to beginning programmersconfusing to beginning programmersMany revisions made Many revisions made ––make sure you make sure you update if you work from home to Java 5.0 update if you work from home to Java 5.0 (1.5)(1.5)Rich libraries Rich libraries So much to learnSo much to learn1.5 Becoming Familiar w/ your 1.5 Becoming Familiar w/ your ComputerComputerVery important to familiarize yourself with your Very important to familiarize yourself with your computercomputerUnderstand how to
View Full Document