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

An overview of computers and programming languages

Nov 28, 2014

Download

Documents

Ahmad Idrees

 
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: An overview of computers and programming languages

Chapter 1:An Overview of Computers and Programming

Languages

Java Programming:

From Problem Analysis to Program Design,

Second Edition

Page 2: An overview of computers and programming languages

Chapter Objectives

Learn about different types of computers.

Explore the hardware and software components of a computer system.

Learn about the language of a computer.

Learn about the evolution of programming languages.

Examine high-level programming languages.

Discover what a compiler is and what it does.

2

Page 3: An overview of computers and programming languages

Chapter Objectives

Examine a Java program.

Examine how a Java program is processed.

Become aware of the Internet and World Wide Web.

Learn what an algorithm is and explore problem-solving techniques.

Become aware of structured and object-oriented programming design methodologies.

3

Page 4: An overview of computers and programming languages

Introduction

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

Computer programs (software) are designed specifically for each task.

Software is created with programming languages.

Java is an example of a programming language.

4

Page 5: An overview of computers and programming languages

An Overview of the History of Computers

1950s: Very large devices available to a select few.

1960s: Large corporations owned computers.

1970s: Computers got smaller and cheaper.

1990s: Computers got cheaper and faster and were found in most homes.

5

Page 6: An overview of computers and programming languages

Elements of a Computer System

A computer has two components:

Hardware

Software

6

Page 7: An overview of computers and programming languages

Hardware Components of a Computer

Central processing unit (CPU)

Main memory

7

Page 8: An overview of computers and programming languages

Central Processing Unit

Control unit (CU)

Arithmetic logic unit (ALU)

Program counter (PC)

Instruction register (IR)

8

Page 9: An overview of computers and programming languages

9

Hardware Components of a Computer

Page 10: An overview of computers and programming languages

Main Memory

Ordered sequence of cells (memory cells).

Directly connected to CPU.

All programs must be brought into main memory before execution.

When power is turned off, everything in main memory is lost.

10

Page 11: An overview of computers and programming languages

Main Memory with 100 Storage Cells

11

Page 12: An overview of computers and programming languages

Secondary Storage

Provides permanent storage for information.

Examples of secondary storage:

Hard disks

Floppy disks

Zip disks

CD-ROMs

Tapes

12

Page 13: An overview of computers and programming languages

Input Devices

Devices that feed data and computer programs into computers.

Examples:

Keyboard

Mouse

Secondary storage

13

Page 14: An overview of computers and programming languages

Output Devices

Devices that the computer uses to display results.

Examples:

Printer

Monitor

Secondary storage

14

Page 15: An overview of computers and programming languages

Software

Software consists of programs written to perform specific tasks.

Two types of programs:

System programs

Application programs

15

Page 16: An overview of computers and programming languages

System Programs

System programs control the computer.

The operating system is first to load when you turn on a computer.

16

Page 17: An overview of computers and programming languages

Operating System (OS)

The OS monitors the overall activity of the computer and provides services.

Example services:

Memory management

Input/output

Activities

Storage management

17

Page 18: An overview of computers and programming languages

Application Programs

Written using programming languages.

Perform a specific task.

Run by the OS.

Example programs: Word processors

Spreadsheets

Games

18

Page 19: An overview of computers and programming languages

Language of a Computer

Machine language is the most basic language of a computer.

A sequence of 0s and 1s.

Every computer directly understands its own machine language.

A bit is a binary digit, 0 or 1.

A byte is a sequence of eight bits.

19

Page 20: An overview of computers and programming languages

Language of a Computer

20

Page 21: An overview of computers and programming languages

Evolution of Programming Languages

Early computers programmed in machine language.

Assembly languages were developed to make programmer’s job easier.

In assembly language, an instruction is an easy-to-remember form called a mnemonic.

Assembler: Translates assembly language instructions into machine language.

21

Page 22: An overview of computers and programming languages

Instructions in Assembly and Machine Languages

22

Page 23: An overview of computers and programming languages

Evolution of Programming Languages

High-level languages make programming easier.

Closer to spoken languages.

Examples:

Basic

FORTRAN

COBOL

C/C++

Java

23

Page 24: An overview of computers and programming languages

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.

24

Page 25: An overview of computers and programming languages

Evolution of Programming Languages

Compiler: A program that translates a program written in a high-level language into the equivalent machine language.

(In the case of Java, this machine language is the bytecode.)

Java Virtual Machine (JVM): A hypothetical computer developed to make Java programs machine independent.

25

Page 26: An overview of computers and programming languages

A Java Program

public class ASimpleJavaProgram { 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 = 57 + 8 = 15

26

Page 27: An overview of computers and programming languages

Processing a Java Program

Two types of Java programs are applications and applets.

Source program: Written in a high-level language.

Loader: Transfers the compiled code (bytecode) into main memory.

Interpreter: Reads and translates each bytecode instruction into machine language and then executes it.

27

Page 28: An overview of computers and programming languages

Processing a Java Program

28

Page 29: An overview of computers and programming languages

Problem-Analysis-Coding-Execution Cycle

Algorithm: A step-by-step, problem-solving process in which a solution is arrived at in a finite amount of time.

29

Page 30: An overview of computers and programming languages

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.

30

Page 31: An overview of computers and programming languages

Problem-Analysis-Coding-Execution Cycle

31

Page 32: An overview of computers and programming languages

Programming Methodologies

Two basic approaches to programming design:

Structured design

Object-oriented design

32

Page 33: An overview of computers and programming languages

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.

33

Page 34: An overview of computers and programming languages

Object-Oriented Design (OOD)

In OOD, a program is a collection of interacting objects.

An object consists of data and operations.

Steps in OOD:

1. Identify objects.

2. Form the basis of the solution.

3. Determine how these objects interact.

34

Page 35: An overview of computers and programming languages

Chapter Summary

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

Computers understand machine language; it is easiest for programmers to write in high-level languages.

A compiler translates high-level language into machine language.

The Java steps required to execute a program are edit, compile, load, and execute.

35

Page 36: An overview of computers and programming languages

Chapter Summary

An algorithm is a step-by-step, problem-solving process in which a solution is arrived at in a finite amount of time.

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.

The two basic approaches to programming design are structured design and object-oriented design.

36