computer hardware and software introduction

18
Computer Hardware and Software Introduction Mr. Smith AP Computer Science A

Upload: wilma

Post on 10-Feb-2016

65 views

Category:

Documents


4 download

DESCRIPTION

Computer Hardware and Software Introduction . Mr. Smith AP Computer Science A. History of Computers. Abacus – 1100 BC. Slide rule - 1617 Mechanical calculator - 1642 Automatic loom (punched cards) - 1804. Babbage’s computer – 1830s Boolean logic – 1850s. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Computer Hardware and Software Introduction

Computer Hardware and Software Introduction

Mr. SmithAP Computer Science

A

Page 2: Computer Hardware and Software Introduction
Page 3: Computer Hardware and Software Introduction

Abacus – 1100 BC

Slide rule - 1617Mechanical calculator - 1642

Automatic loom (punched cards) - 1804

Babbage’s computer – 1830sBabbage’s computer – 1830sBoolean logic – 1850sBoolean logic – 1850s

Hollerith’s electric tabulator - 1880Hollerith’s electric tabulator - 1880Analog computer – 1927Analog computer – 1927

EDVAC – 1946EDVAC – 1946ENIAC - 1947ENIAC - 1947

Transistor - 1947Transistor - 1947

Integrated circuit – late 1950sIntegrated circuit – late 1950sUNIVAC – 1951UNIVAC – 1951

Microprocessor – 1971Microprocessor – 1971Altair 8880 – 1975Altair 8880 – 1975

Apple II – 1977Apple II – 1977IBM PC – 1981IBM PC – 1981

World Wide Web – 1990sWorld Wide Web – 1990s

History of Computers

Page 4: Computer Hardware and Software Introduction

What is Programming?A computer must be programmed to perform a taskA computer is a machine that:

Stores data (numbers, words, and pictures) Interacts with devices (monitor, sound system,

printer) Executes programs

Typical operations are: Put a red dot onto this screen position Send letter Z to the printer Get a number from a specific location in memory Multiply two numbers If this value > 10, execute a certain instruction

A computer program tells the computer, in much detail, the sequence of steps to complete a task.

Page 5: Computer Hardware and Software Introduction

Anatomy of a ComputerCentral Processing Unit (CPU):

It is the Brain of your computer. It consists of a single chip (integrated circuit) or a small number of chips

A computer chip has plastic or metal housing, metal connectors, and inside wiring made mainly of silicon

A chip contains millions of transistors (the elements that enable electrical signals to control other electrical signals)

The main tasks of the CPU are: To locate and execute the program instructions To carry out arithmetic operations To fetch data from storage and input/output devices To send data back to devices

Page 6: Computer Hardware and Software Introduction

Anatomy of a ComputerStorage:

Primary – known as RAM or Memory Fast, but relatively expensive Made from memory chips Loses its data when power is turned off

Secondary – usually a hard disk Less expensive storage Keeps data when electricity is turned off CD-ROM Flash drive DVD

Page 7: Computer Hardware and Software Introduction

Anatomy of a ComputerOther things to know about your computer:

I/O Devices Enables you to interact with a computer Keyboard, mouse, monitors, printers

Motherboard Contains CPU, RAM, and connectors to peripheral

devices Bus

Set of electrical lines that connect the CPU, RAM, and connectors

Network Allows a computer to communicate with other

computers or devices not directly connected to this computer

Page 8: Computer Hardware and Software Introduction

Compiling a Simple Program

Printing to the console: public class TrivialProgram{

public static void main (String[] args){

System.out.print(“This prints a line. ”);System.out.println(“This stays on the same line.”);System.out.println(“This prints on a new line.”);

} }

This program will print the following to the console:This prints a line. This stays on the same line.This prints on a new line.

Object

Method Parameters(out is a static PrintStream object in System class)

Whenever you call this method in Java, you

need to specify these 3 items

Page 9: Computer Hardware and Software Introduction

System.out.println()public class System{

public static PrintStream out;}

public class PrintStream{ public void println(String s) { ……………………. } public void print(String s) { ……………………. }}

Page 10: Computer Hardware and Software Introduction

JavaConceptsCh1Homework

This assignment will give you practice printing to the console. You need to use System.out.print() and System.out.println() methods. We are also using static methods in this assignment.

In eclipse, create a new project named JavaConcepts. On the first screen, make sure that all the radio buttons are active on the top options. This project has no additional jar files you need to use.

Create a new package named javaconcepts in this project. Download the JavaConceptsCh1.java and JavaConceptsCh1Tester.java

classes and put them in this new package. Pay careful attention to the comments for instructions and explanations.

Ex. R1.2, R1.4, R1.7, R1.12 (page 28) – create answersToReviewExercises() method to print your answers to the console.

Ex. P1.2 (page 29) – create facePrinter() method to print a face using text characters. Be creative.

Ex. P1.3 (page 29) – create ticTacToeBoard() method – must use looping to get full credit; this is an example of a fence post problem.

Page 11: Computer Hardware and Software Introduction

Java CommentsUsing comments in your Java programs:

Single line comments – use // Anything following // on the same line is a comment Robot.move(); // This makes the robot move

Multi-line comments – use /* and */ Anything after the /* and before the */ is a comment Comments can span lines /* The following while loop will calculate the interest payment for my house */

Javadoc comments – use /** and */ Anything after the /** and before the */ is a comment Comments can span lines /** This program is used to create a robot that can go

through a maze */

Page 12: Computer Hardware and Software Introduction

Java ErrorsErrors encountered within Java

programs: Compile-time errors

Violation of the rules of the programming language Compiler detects syntax/lexical errors Examples: Missing semi-colons, missing brackets,

and missing parentheses are examples of syntax errors. Misspelling a method name is an example of a lexical error caught at compile-time.

Logic errors Causes the program to take an action that the

programmer did not intend. Program runs without an error message.

Page 13: Computer Hardware and Software Introduction

Translating Programs to Machine Code

A Compiler translates high level language (Java program code) into machine code (also known as Java bytecode)

An Interpreter is similar to a compiler but translates and executes a single statement at a time.

An Editor is used to create or change a Java program The Editor and Compiler may be part of the same software

known as an Integrated Development Environment (IDE), such as eclipse. An IDE can also contain a Debugger.

A Java Virtual Machine (JVM) is written for every major operating system. It is like a simulated CPU that runs inside an operating system. The JVM reads the bytecode and executes the program.

The Operating system manages the computer resources

Page 14: Computer Hardware and Software Introduction

Java Compilation Process

How compilation works: You type a Java source program into an IDE such as

eclipse. The source code has the extension .java The Compiler reads the source program and if it finds

errors, it displays errors in the editor’s console. After errors are corrected, the compiler is able to

translate your source program into a class file (Java bytecode). This file has the extension .class

The Java Virtual Machine then does the following: Loads the instructions for the program (.class file) Starts the program Loads any other necessary library (jar) files JVM is the reason that we can run the program on

different operating systems.

Page 15: Computer Hardware and Software Introduction

Java Compilation Process

Editor Compiler JVM

Source file( .java file )

Classfiles

Libraryfiles

Runningprogram

This is the result of saving your program in eclipse with no errors

Bytecode file( .class file )

Jar files andSystem library files

( .jar file )

This is the result of

running your program in

eclipse

An Editor is used to create or modify

source code

A Compiler converts the

source file into a Bytecode file

Eclipse is an IDE which is both an

editor and compiler

Page 16: Computer Hardware and Software Introduction

Compiling a Simple Program

Displaying a message in a dialog box: import javax.swing.JOptionPane;

public class DialogBox{

public static void main (String[] args){JOptionPane.showMessageDialog(null, "Hello, World!");System.exit(0);}

}

This program will display a message box:Hello, World!

Press OK to acknowledge the message

Package Class

Class

This method brings up a confirmation dialog box that displays a message

and waits for user to confirm it.

MessageParentParameters

Check out Appendix C for list of Java Libraries

Exits the program. A non-zero status

indicates abnormal termination

Page 17: Computer Hardware and Software Introduction

Compiling a Simple Program

Using a dialog box to prompt for information:

public class DialogViewer {

public static void main (String[] args){String name = JOptionPane.showInputDialog("What is your name?");System.out.print(name);System.exit(0);}

}

will display a dialog box that asks:What is your name?

You would then enter your name and press Ok.

Whatever you entered would be assigned to the name variable

This method brings up an input dialog box which displays a prompt

and waits for user to enter data into it

PromptParameter

User input is assigned to this variable

Page 18: Computer Hardware and Software Introduction

PrintAddress classPrintAddress class: Prompt the user to enter the following information in six separate dialog boxes:1) first name2) last name3) street address4) city5) state6) zip

Then print this information to the console in the following format:John Doe110 Oak StreetWinston-Salem, NC 27101

At the end, display the following dialog message: Thank you for entering your name and address