COMP 14: Intro. to Intro. to ProgrammingWhat we’ll talk about today...ComputersComputers are made of 2 thingsHardwareOur view of the hardwareCPUMemoryThis class is about SoftwareComputer LanguagesCompilers and InterpretersJava is compiled and interpretedSo what is programming?ImplementationSimple Java ProgramSlide 16Slide 17Slide 18Slide 19Slide 20Slide 21Java Reserved WordsSlide 23Java IdentifiersSlide 25Identifier guidelinesCommentsSlide 28AlgorithmsHomeworkCOMP 14: Intro. to Intro. to ProgrammingMay 23, 2000Nick VallidisWhat we’ll talk about today...Brief overview of computersHardware and SoftwareWhat is programming?JavaAlgorithmsComputersBasically “information processors”–Take info, do something to it, spit it out againDigital–Store the information as numbers (“digits”)Use the binary number systemComputers are made of 2 thingsHardware–The part you can see and touch–CPU, monitor, mouse, keyboardSoftware–Information to tell the computer HOW to process information–OS, compiler, word processor, games, etc.HardwareCPU: Pentium (II/III), Alpha, AthlonMemory: RAM, floppy disk, hard drive, CDInput Devices: keyboard, mouse, data tabletOutput Devices: monitor, printerOur view of the hardwareMonitorKeyboardMainMemoryCentralProcessingUnitFloppy DiskHard DiskSecondary MemoryCPU“Central Processing Unit”Continuously does fetch-decode-executefetchRetrieve an instruction from main memoryRetrieve an instruction from main memorydecodeDetermine what theDetermine what theinstruction isinstruction isexecuteCarry out theCarry out theinstructioninstructionMemoryAn address is the name of a specific location in memoryMain Memory–run programs from here–fast, volatileSecondary Memory–slow–permanentThis class is about SoftwareOperating System (OS)–Understands the hardware–Simplifies your interaction with the hardware–Controls starting/stopping applicationsApplications–any software that isn’t the OS–what you will learn to writeComputer LanguagesMachine Language–the form the CPU understands–strings of 1’s and 0’sAssembly Language–people-friendly version of machine languageHigh-level languages–Java, C++, FORTRAN, COBOL, BASICCompilers and InterpretersBoth are ways to turn high-level languages into something the computer can executeCompilers turn a source code file into an executableInterpreters let you type the program into it and run it directlyJava is compiled and interpretedJava sourcecodeMachinecodeJavabytecodeJavainterpreterBytecodecompilerJavacompilerSo what is programming?Programming IS problem solvingTakes multiple steps:–understand what the problem is–find a solution (algorithm) for the problem–determine if the solution is correct–implement the solution–test the solution implementationImplementationNot any more important than other steps, but probably the one you know the least aboutWe are using JavaSimple Java Programpublic class Simple{public static void main(String[] args){System.out.println(“Hello!”);}}Simple Java Programpublic class Simple{public static void main(String[] args){System.out.println(“Hello!”);}}All programs have to be part of a classSimple Java Programpublic class Simple{public static void main(String[] args){System.out.println(“Hello!”);}}Tells the computer where to start running the programSimple Java Programpublic class Simple{public static void main(String[] args){System.out.println(“Hello!”);}}Braces indicate where different sections of the program begin and endSimple Java Programpublic class Simple{public static void main(String[] args){System.out.println(“Hello!”);}}This tells the computer to print out “Hello!” (without quotes)Simple Java Programpublic class Simple{public static void main(String[] args){System.out.println(“Hello!”);}}This indicates the end of a statement (one “step” in the program)Simple Java Programpublic class Simple{public static void main(String[] args){System.out.println(“Hello!”);}}These are reserved words in Java. This means that Java uses them for a special purposeJava Reserved WordsabstractbooleanbreakbytebyvaluecasecastcatchcharclassconstcontinuedefaultdodoubleelseextendsfalsefinalfinallyfloatforfuturegenericgotoifimplementsimportinnerinstanceofintinterfacelongnativenewnulloperatorouterpackageprivateprotectedpublicrestreturnshortstaticsuperswitchsynchronizedthisthrowthrowstransienttruetryvarvoidvolatilewhileSimple Java Programpublic class Simple{public static void main(String[] args){System.out.println(“Hello!”);}}These are identifiers. These are words chosen by a programmer as names for things.Java IdentifiersCan include letters, digits, $, and _Must not start with a digitThey are case sensitiveSimple Java Programpublic class Simple{public static void main(String[] args){System.out.println(“Hello!”);}}Red identifiers were chosen by the author of this programBlue identifiers were chosen by another programmer.Identifier guidelinesYou want to choose descriptive identifiers–things like a, b, dm, tu are bad–things like lastValue, $cost are goodIf multiple words, start each new word with a capital letterCommentsYou can insert comments in the code that are completely ignored by the compilertwo styles:–/* everything in here is a comment */–// everything to the end of line is a commentI was very bad and didn’t comment the program I showed before. Let’s fix that...Simple Java Program/* a very simple Java program */public class Simple{// prints a message to the userpublic static void main(String[] args){System.out.println(“Hello!”);}}AlgorithmsA step-by-step description of a solution to a problemIn some sense the computer is stupid and needs very explicit instructionsHomeworkRead Ch. 1 (there are more specific instructions on the web page, but it’s ok if you just read the whole thing)Write an algorithm for making a peanut butter and jelly
View Full Document