Chapter 1 An Overview of Computers and Programming

  • Slides: 36
Download presentation
Chapter 1: An Overview of Computers and Programming Languages Java Programming: From Problem Analysis

Chapter 1: An Overview of Computers and Programming Languages Java Programming: From Problem Analysis to Program Design, Second Edition Java Programming: From Problem Analysis to Program Design,

Chapter Objectives s Learn about different types of computers. s Explore the hardware and

Chapter Objectives s Learn about different types of computers. s Explore the hardware and software components of a computer system. s Learn about the language of a computer. s Learn about the evolution of programming languages. s Examine high-level programming languages. s Discover what a compiler is and what it does. Java Programming: From Problem Analysis to Program Design, Second Edition 2

Chapter Objectives s Examine a Java program. s Examine how a Java program is

Chapter Objectives s Examine a Java program. s Examine how a Java program is processed. s Become aware of the Internet and World Wide Web. s Learn what an algorithm is and explore problemsolving techniques. s Become aware of structured and object-oriented programming design methodologies. Java Programming: From Problem Analysis to Program Design, Second Edition 3

Introduction s Computers have greatly affected our daily lives— helping us complete many tasks.

Introduction s Computers have greatly affected our daily lives— helping us complete many tasks. s Computer programs (software) are designed specifically for each task. s Software is created with programming languages. s Java is an example of a programming language. Java Programming: From Problem Analysis to Program Design, Second Edition 4

An Overview of the History of Computers s 1950 s: Very large devices available

An Overview of the History of Computers s 1950 s: Very large devices available to a select few. s 1960 s: Large corporations owned computers. s 1970 s: Computers got smaller and cheaper. s 1990 s: Computers got cheaper and faster and were found in most homes. Java Programming: From Problem Analysis to Program Design, Second Edition 5

Elements of a Computer System A computer has two components: s Hardware s Software

Elements of a Computer System A computer has two components: s Hardware s Software Java Programming: From Problem Analysis to Program Design, Second Edition 6

Hardware Components of a Computer s Central processing unit (CPU) s Main memory Java

Hardware Components of a Computer s Central processing unit (CPU) s Main memory Java Programming: From Problem Analysis to Program Design, Second Edition 7

Central Processing Unit s Control unit (CU) s Arithmetic logic unit (ALU) s Program

Central Processing Unit s Control unit (CU) s Arithmetic logic unit (ALU) s Program counter (PC) s Instruction register (IR) Java Programming: From Problem Analysis to Program Design, Second Edition 8

Hardware Components of a Computer Java Programming: From Problem Analysis to Program Design, Second

Hardware Components of a Computer Java Programming: From Problem Analysis to Program Design, Second Edition 9

Main Memory s Ordered sequence of cells (memory cells). s Directly connected to CPU.

Main Memory s Ordered sequence of cells (memory cells). s Directly connected to CPU. s All programs must be brought into main memory before execution. s When power is turned off, everything in main memory is lost. Java Programming: From Problem Analysis to Program Design, Second Edition 10

Main Memory with 100 Storage Cells Java Programming: From Problem Analysis to Program Design,

Main Memory with 100 Storage Cells Java Programming: From Problem Analysis to Program Design, Second Edition 11

Secondary Storage s Provides permanent storage for information. s Examples of secondary storage: s

Secondary Storage s Provides permanent storage for information. s Examples of secondary storage: s Hard disks s Floppy disks s Zip disks s CD-ROMs s Tapes Java Programming: From Problem Analysis to Program Design, Second Edition 12

Input Devices s Devices that feed data and computer programs into computers. s Examples:

Input Devices s Devices that feed data and computer programs into computers. s Examples: s Keyboard s Mouse s Secondary storage Java Programming: From Problem Analysis to Program Design, Second Edition 13

Output Devices s Devices that the computer uses to display results. s Examples: s

Output Devices s Devices that the computer uses to display results. s Examples: s Printer s Monitor s Secondary storage Java Programming: From Problem Analysis to Program Design, Second Edition 14

Software s Software consists of programs written to perform specific tasks. s Two types

Software s Software consists of programs written to perform specific tasks. s Two types of programs: s System programs s Application programs Java Programming: From Problem Analysis to Program Design, Second Edition 15

System Programs s System programs control the computer. s The operating system is first

System Programs s System programs control the computer. s The operating system is first to load when you turn on a computer. Java Programming: From Problem Analysis to Program Design, Second Edition 16

Operating System (OS) s The OS monitors the overall activity of the computer and

Operating System (OS) s The OS monitors the overall activity of the computer and provides services. s Example services: s Memory management s Input/output s Activities s Storage management Java Programming: From Problem Analysis to Program Design, Second Edition 17

Application Programs s Written using programming languages. s Perform a specific task. s Run

Application Programs s Written using programming languages. s Perform a specific task. s Run by the OS. s Example programs: s Word processors s Spreadsheets s Games Java Programming: From Problem Analysis to Program Design, Second Edition 18

Language of a Computer s Machine language is the most basic language of a

Language of a Computer s Machine language is the most basic language of a computer. s A sequence of 0 s and 1 s. s Every computer directly understands its own machine language. s A bit is a binary digit, 0 or 1. s A byte is a sequence of eight bits. Java Programming: From Problem Analysis to Program Design, Second Edition 19

Language of a Computer Java Programming: From Problem Analysis to Program Design, Second Edition

Language of a Computer Java Programming: From Problem Analysis to Program Design, Second Edition 20

Evolution of Programming Languages s Early computers programmed in machine language. s Assembly languages

Evolution of Programming Languages s Early computers programmed in machine language. s Assembly languages were developed to make programmer’s job easier. s In assembly language, an instruction is an easy-toremember form called a mnemonic. s Assembler: Translates assembly language instructions into machine language. Java Programming: From Problem Analysis to Program Design, Second Edition 21

Instructions in Assembly and Machine Languages Java Programming: From Problem Analysis to Program Design,

Instructions in Assembly and Machine Languages Java Programming: From Problem Analysis to Program Design, Second Edition 22

Evolution of Programming Languages s High-level languages make programming easier. s Closer to spoken

Evolution of Programming Languages s High-level languages make programming easier. s Closer to spoken languages. s Examples: s s s Basic FORTRAN COBOL C/C++ Java Programming: From Problem Analysis to Program Design, Second Edition 23

Evolution of Programming Languages To run a Java program: 1. Java instructions need to

Evolution of Programming Languages To run a Java program: 1. Java instructions need to be translated into an intermediate language called bytecode. 2. The bytecode is interpreted into a particular machine language. Java Programming: From Problem Analysis to Program Design, Second Edition 24

Evolution of Programming Languages s Compiler: A program that translates a program written in

Evolution of Programming Languages s Compiler: A program that translates a program written in a high-level language into the equivalent machine language. s (In the case of Java, this machine language is the bytecode. ) s Java Virtual Machine (JVM): A hypothetical computer developed to make Java programs machine independent. Java Programming: From Problem Analysis to Program Design, Second Edition 25

A Java Program public class ASimple. Java. Program { public static void main(String[] args)

A Java Program public class ASimple. Java. Program { public static void main(String[] args) { System. out. println("My first Java program. "); System. out. println("The sum of 2 and 3 = " + 5); System. out. println("7 + 8 = " + (7 + 8)); } } Sample Run: My first Java program. The sum of 2 and 3 = 5 7 + 8 = 15 Java Programming: From Problem Analysis to Program Design, Second Edition 26

Processing a Java Program s Two types of Java programs are applications and applets.

Processing a Java Program s Two types of Java programs are applications and applets. s Source program: Written in a high-level language. s Loader: Transfers the compiled code (bytecode) into main memory. s Interpreter: Reads and translates each bytecode instruction into machine language and then executes it. Java Programming: From Problem Analysis to Program Design, Second Edition 27

Processing a Java Programming: From Problem Analysis to Program Design, Second Edition 28

Processing a Java Programming: From Problem Analysis to Program Design, Second Edition 28

Problem-Analysis-Coding. Execution Cycle s Algorithm: A step-by-step, problem-solving process in which a solution is

Problem-Analysis-Coding. Execution Cycle s Algorithm: A step-by-step, problem-solving process in which a solution is arrived at in a finite amount of time. Java Programming: From Problem Analysis to Program Design, Second Edition 29

Problem-Solving Process 1. Analyze the problem: Outline solution requirements and design an algorithm. 2.

Problem-Solving Process 1. Analyze the problem: Outline solution requirements and design an algorithm. 2. Implement the algorithm in a programming language (Java) and verify that the algorithm works. 3. Maintain the program: Use and modify if the problem domain changes. Java Programming: From Problem Analysis to Program Design, Second Edition 30

Problem-Analysis-Coding-Execution Cycle Java Programming: From Problem Analysis to Program Design, Second Edition 31

Problem-Analysis-Coding-Execution Cycle Java Programming: From Problem Analysis to Program Design, Second Edition 31

Programming Methodologies Two basic approaches to programming design: s Structured design s Object-oriented design

Programming Methodologies Two basic approaches to programming design: s Structured design s Object-oriented design Java Programming: From Problem Analysis to Program Design, Second Edition 32

Structured Design 1. A problem is divided into smaller sub-problems. 2. Each sub-problem is

Structured Design 1. A problem is divided into smaller sub-problems. 2. Each sub-problem is solved. 3. The solutions of all sub-problems are combined to solve the problem. Java Programming: From Problem Analysis to Program Design, Second Edition 33

Object-Oriented Design (OOD) s In OOD, a program is a collection of interacting objects.

Object-Oriented Design (OOD) s In OOD, a program is a collection of interacting objects. s An object consists of data and operations. s Steps in OOD: 1. Identify objects. 2. Form the basis of the solution. 3. Determine how these objects interact. Java Programming: From Problem Analysis to Program Design, Second Edition 34

Chapter Summary s A computer system is made up of hardware and software components.

Chapter Summary s A computer system is made up of hardware and software components. s Computers understand machine language; it is easiest for programmers to write in high-level languages. s A compiler translates high-level language into machine language. s The Java steps required to execute a program are edit, compile, load, and execute. Java Programming: From Problem Analysis to Program Design, Second Edition 35

Chapter Summary s An algorithm is a step-by-step, problem-solving process in which a solution

Chapter Summary s An algorithm is a step-by-step, problem-solving process in which a solution is arrived at in a finite amount of time. s The three steps of the problem-solving process are analyze the problem and design an algorithm, implement the algorithm in a programming language, and maintain the program. s The two basic approaches to programming design are structured design and object-oriented design. Java Programming: From Problem Analysis to Program Design, Second Edition 36