Structured Problem-Solving Using the Computer IT 168 Aug 23, 2012 (Thursday)
Interesting story about … • Light, electrons, mechanical components • Hex edit • …
For Tuesday(Aug 28) • Read Gaddis, chapter 2, sections 1-6 • Download and complete the student questionnaire • Send the completed questionnaire to kwsuh@ilstu.edu from your ISU email address. Include your name, IT 168, and your lecture section by Tuesday • Any concerns/comments about the first lab?
Quiz • Next week • Ch1, Ch2.1-2.6, syllabus
Computer Systems: Hardware • Computer hardware components are the physical pieces of the computer. • The major hardware components of a computer are: – The central processing unit (CPU) – Main memory – Secondary storage devices – Input and Output devices 1-5
Computer Systems: Hardware 1-6
Computer Systems: Hardware Central Processing Unit CPU Arithmetic Logic Unit Instruction (input) Result (output) Control Unit 1-7
Computer Systems: Hardware Central Processing Unit – The CPU performs the fetch, decode, execute cycle in order to process program information. The CPU’s control unit fetches, from main memory, the next instruction in the sequence of program instructions. Fetch The instruction is encoded in the form of a number. The control unit decodes the instruction and generates an electronic signal. The signal is routed to the appropriate component Execute Decode of the computer (such as the ALU, a disk drive, or some other device). The signal causes the component to perform an operation. 1-8
Computer Systems: Hardware Main Memory • Commonly known as random-access memory (RAM) • RAM contains: – currently running programs – data used by those programs. • RAM is divided into units called bytes . • A byte consists of eight bits that may be either on or off. 1-9
Computer Systems: Hardware Main Memory • A bit is either on or off: – 1 = on – 0 = off • The bits form a pattern that represents a character or a number. • Each byte in memory is assigned a unique number known as an address . • RAM is volatile , which means that when the computer is turned off, the contents of RAM are erased. 1-10
Computer Systems: Hardware Main Memory Main memory can be visualized as a column or row of cells. 0x000 A section of memory is called a byte . 0x001 A byte is made up of 8 bits . 1 0 1 0 1 0 1 0 0x002 0x003 0x004 0x005 A section of two or four bytes is 0x006 often called a word . 0x007 [Q] 32-bit computer vs. 64-bit computer? 1-11
Computer Systems: Hardware Secondary Storage Devices • Secondary storage devices are capable of storing information for longer periods of time ( non-volatile ). • Common Secondary Storage devices: • Hard drive • CD ROM • Floppy drive • DVD RAM drive • CD RW drive • Compact Flash card 1-12
Computer Systems: Hardware Input Devices • Input is any data the computer collects from the outside world. • That data comes from devices known as input devices . • Common input devices: – Keyboard – Mouse – Scanner – Digital camera 1-13
Computer Systems: Hardware Output Devices • Output is any data the computer sends to the outside world. • That data is displayed on devices known as output devices . • Common output devices: – Monitors – Printers • Some devices such as disk drives perform input and output and are called I/O devices (input/output). 1-14
What can a computer do? • Simple arithmetic – Add, subtract, (multiply, divide) • Move data – From CPU to memory and vice-versa – From CPU to I/O device and vice-versa – Between registers inside CPU • Compare two numbers (and move data based on the result of the comparison) • ….
How do we do cool stuff?
Computer Systems: Software • Software refers to the programs that run on a computer. • There are two classifications of software: – Operating Systems and system software – Application Software 1-17
Programming Languages • A program is a set of instructions a computer follows in order to perform a task. • A programming language is a special language used to write computer programs. • A computer program is a set of instructions that enable the computer to solve a problem or perform a task. • Collectively, these instructions form an algorithm 1-18
Programming Languages • An algorithm is a set of well defined steps to completing a task. • The steps in an algorithm are performed sequentially. • A computer needs the algorithm to be written in machine language . • Machine language is written using binary numbers . • The binary numbering system (base 2) only has two digits (0 and 1). 1-19
Programming Languages • The binary numbers are encoded as a machine language . • Each CPU has its own machine language. – Motorola 68000 series processors – Intel x86 series processors – DEC Alpha processors, etc. • Example of a machine language instruction: 1011010000000101 1-20
Programming Languages • In the distant past, programmers wrote programs in machine language. • Programmers developed higher level programming languages to make things easier. • The first of these was assembler . • Assembler made things easier but was also processor dependent. 1-21
Programming Languages • High level programming languages followed that were not processor dependent. • Some common programming languages: – BASIC – COBOL – Pascal – C – C++ – Java 1-22
The Process 1. Understand the problem 2. Figure out the interface (input and output) 3. Make a plan 4. Check the plan 5. Translate the plan into Java (or other) 6. Fix compile-time errors 7. Run the program 8. Fix run-time errors 9. Make sure it works correctly
Errors • Syntax or compile-time • Run-time • Logic or intent
Making the Plan • Algorithms • Pseudocode – English – Formatted like computer program code – http://www.unf.edu/~broggio/cop2221/2221pseu.ht m
Terminology • Algorithm ≠ Pseudocode • Algorithms are often written in pseudocode, but your Java program is also a representation of an algorithm. • On the other hand, when I ask you to submit an algorithm, it MUST be written in pseudocode.
Precision/Detail • How precise and detailed does an algorithm have to be? • Just exactly how dumb is a computer?
Writing for an Audience • When you write a computer program, you have two audiences. • What are they?
Demo • Let’s look at an actual computer program in Java.
Structure of a Java Program
Some Details • File name and class name • Case sensitivity • Comments • Curly braces • Semicolons • Quotation marks
Output from Java
Chapter 2: Java Fundamentals Starting Out with Java: Early Objects Fourth Edition by Tony Gaddis
Chapter Topics Chapter 2 discusses the following main topics: – The Parts of a Java Program – The print and println Methods, and the Java API – Variables and Literals – Primitive Data Types – Arithmetic Operators – Combined Assignment Operators 2-34
Chapter Topics (2) – Conversion between Primitive Data Types – Creating named constants with final – The String class – Scope – Comments – Programming style – Reading keyboard input – Dialog boxes – The printf method 2-35
Parts of a Java Program • A Java source code file contains one or more Java classes. • If more than one class is in a source code file, only one of them may be public. • The public class and the filename of the source code file must match. ex: A class named Simple must be in a file named Simple.java • Each Java class can be separated into parts. 2-36
Parts of a Java Program • See example: Simple.java • To compile the example: – javac Simple.java • Notice the .java file extension is needed. • This will result in a file named Simple.class being created. • To run the example: – java Simple • Notice there is no file extension here. • The java command assumes the extension is .class . 2-37
Analyzing The Example This is a Java comment. // This is a simple Java program. It is ignored by the compiler. This is the class header public class Simple for the class Simple { This area is the body of the class Simple . All of the data and methods for this class will be between these curly braces. } 2-38
Analyzing The Example This is the method header // This is a simple Java program. for the main method. The main method is where a Java application begins. public class Simple { public static void main(String[] args) { This area is the body of the main method. All of the actions to be completed during } the main method will be between these curly braces. } 2-39
Analyzing The Example // This is a simple Java program. public class Simple { public static void main(String [] args) { System.out.println("Programming is great fun!"); } } This is the Java Statement that is executed when the program runs. 2-40
Recommend
More recommend