201-Part1 - CSE 201 Elementary Computer Programming CSE 201...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 201 Elementary Computer Programming CSE 201 Elementary Computer Programming 1 Computer Basics Computer system: hardware + software Hardware: the physical components Software: the instructions that tell the hardware what to do CSE 201 Elementary Computer Programming 2 Common Hardware Components Standard Hardware Organization Processor (CPU) Central Processing Unit Interprets and executes the instructions Memory Memory (main & auxiliary) main & auxiliary holds data and instructions Input device(s) mouse, keyboard, etc. Output Devices (such as video display or printer) Input Devices (such as mouse and keyboard) Processor (CPU) Output device(s) video display, printer, etc. CPU and memory are physically housed together 3 CSE 201 Elementary Computer Programming Running a Program Program--a set of instructions for a computer to follow Program-- Program Data (input for the program) Computer Output CSE 201 Elementary Computer Programming 4 Programming Languages Needed to write software High-level languages (e.g., Java) relatively easy for people to write and understand not directly understood by computers Low-level languages (machine language) directly understood by computer computer-dependent CSE 201 Elementary Computer Programming 5 The Compiler A program written in a high-level language (know as the source code) cannot be executed directly by the computer A compiler is a program that translates source code into machine code that does the same thing (known as the object code) CSE 201 Elementary Computer Programming 6 Java Program Translation and Execution Input to Java Program Java Source Code Java Compiler Java Byte-Code Byte- Java Virtual Machine Output of Java Program CSE 201 Elementary Computer Programming 7 Java Translation/Execution cont. Java byte-code is portable (hardwareindependent) The Java Virtual Machine (JVM) executes Java byte-code on a real machine The java compiler is called javac The JVM emulator is called java CSE 201 Elementary Computer Programming 8 Algorithmic Thinking Algorithm - a set of instructions (steps) for solving a problem. must be precise must be complete can be written in an arbitrary notation (e.g., natural language, programming language, diagram, mix, etc.) Algorithmic thinking is fundamental to computer science and programming CSE 201 Elementary Computer Programming 9 Example of an Algorithm Algorithm that determines the total cost of a list of items: 1. Write the number 0 on the blackboard. 2. Do the following for each item on the list: a. Add the cost of the item to the number on the blackboard. b. Replace the old number on the board by this sum. 3. Announce that the answer is the number written on the board. CSE 201 Elementary Computer Programming 10 First Java Program public class FirstProgram { public static void main(String args) { System.out.println("Hello out there."); System.out.println("How's it going?"); System.out.println( System.out.println( "Hope you are having a good day."); System.out.println("Good-bye."); System.out.println("Good} } CSE 201 Elementary Computer Programming 11 Language Syntax Syntax of a language is a set of (grammar) rules that describe the correct way to write sentences (programs) in the language. Programming languages have a very precise syntax: If you break the rules, you'll get one (or more) errors. CSE 201 Elementary Computer Programming 12 Structure of a Java Program // import needed libraries public class ProgramName { public static void main(String args) { // statements go here to describe // actions to be taken by the program } } CSE 201 Elementary Computer Programming 13 A Java Statement System.out.println("some message here"); Outputs the message in quotes to the screen (without the quotes) CSE 201 Elementary Computer Programming 14 What Does FirstProgram Do? Take a look at the program and see if you can figure out what the program does. It outputs the following: CSE 201 Elementary Computer Programming 15 Programming Errors Syntax errors--violation of language's syntax rules, e.g., misspelling a word, forgetting a ;, etc. Caught by the compiler! Runtime errors--execution errors, e.g., division by zero. Logical errors--the program compiles and runs without runtime errors, but it does not do what it is supposed to. CSE 201 Elementary Computer Programming 16 ...
View Full Document

This note was uploaded on 11/17/2009 for the course CSE 201 taught by Professor All during the Spring '09 term at Ohio State.

Ask a homework question - tutors are online