chapter 1 introduction. chapter goals to understand the activity of programming to understand the...

36
CHAPTER 1 INTRODUCTION

Upload: elinor-willis

Post on 03-Jan-2016

226 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

CHAPTER 1

INTRODUCTION

Page 2: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

CHAPTER GOALS To understand the activity of

programming

To learn about the architecture of computers

To learn about machine code and high level programming languages

To become familiar with your computing environment and your compiler

To compile and run your first Java program

To recognize syntax and logic errors

Page 3: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

PREREQUISITES

Computer savvy (file management, text editing)

· Problem solving skills · Time management · High school math (Geometry, Algebra

II) · No prior programming background

required

Page 4: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

What do computers do?

Help with organizing and writing term papers

Help balance checkbooks Keep track of students' grades They are even good game machines

Page 5: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

How do computers do it?

Computers must be programmed to perform tasks. Different tasks require different programs.

A computer program executes a sequence of very basic operations in rapid succession

Page 6: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

What is a computer?

· Central processing unit · Memory · Peripherals · Executes very simple instructions

· Executes instructions very rapidly

· General purpose device · Programs describe specific actions

Page 7: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

Self Check1. What is required to play a music CD

on a computer? Ans: A program that reads the data on the CD and sends output to the speakers and the screen.

2. Why is a CD player less flexible than a computer? Ans: A CD player can do one thing–play music CDs. It cannot execute programs.

Page 8: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

Self Check Cont…

3. Can a computer program develop the initiative to execute tasks in a better way than its programmers envisioned?

Ans: No–the program simply executes the instruction sequences that the programmers have prepared in advance.

Page 9: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

Central Processing Unit

Page 10: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

CPU and what it does

A single chip consisting of millions of transistors

performs program control arithmetic operations data movement

Page 11: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

A Memory Module with Memory Chips

Figure 2: A Memory Module with Memory Chips

Page 12: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

A Hard Disk

Figure 3: A Hard Disk

Page 13: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

A Motherboard

Figure 4: A Motherboard

Page 14: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

Schematic Diagram of a Computer

Figure 5: Schematic Diagram of a Computer

Page 15: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

The ENIAC

Figure 6: The ENIAC

Page 16: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

Self Check4. Where is a program stored when it is

not currently running? Ans: In secondary storage, typically a hard disk.

5. Which part of the computer carries out arithmetic operations, such as addition and multiplication?Ans: The central processing unit.

Page 17: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

Programming Languages

· Machine/Virtual Machine21 40 16 100 163 240

· Assembleriload intRatebipush 100if_icmpgt intError

· High-level languageif (intRate > 100) . . .

Page 18: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

Compilers

Language specific Sophisticated programs that

translate logical statements such as ifs into sequences of computations, tests and jumps

find memory locations for variables and more . . .

Page 19: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

The Java Programming Language

· Simple · Safe · Platform-independent ("write once, run anywhere")

· Rich library · Designed for the internet

Page 20: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

Applets on a Web Page

Figure 7: Applets on a Web Page

Page 21: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

Version Year Important New Features

1.0 1996  

1.1 1997 Inner classes

1.2 1998 Swing, Collections

1.3 2000 Performance enhancements

1.4 2002 Assertions, XML

5 2004 Generic classes, enhanced for loop, auto-boxing, enumerations

6 2006 Library improvements

Java Versions

Page 22: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

Self Check

5. What are the two most important benefits of the Java language? Ans: Safety and portability.

6. How long does it take to learn the entire Java library? Ans: No one person can learn the entire library–it is too large.

Page 23: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

HOMEWORK! Complete the computer room

agreement form and have it signed by parent/guardian

Be sure you have a computer password

Read and take notes section 1-1 through 1-6 and complete the self-check exercises. italicized words -- vocabulary boxes points of interest (ENIAC) p. 29 exercises R1.1 – R1.3 to be

collected tomorrow with the self check exercises.

Page 24: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

Becoming Familiar with your Computer

Login Locate the Java compiler Understand files and folders Write a simple program (later) Save your work

Page 25: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

A Console Window

Page 26: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

An Integrated Development Environment

Figure 9:An Integrated Development Environment

Page 27: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

A simple program· public class ClassName · public static void main(String[] args)

· // comment· Method call object.methodName(parameters)

· System class · System.out object · println method

Page 28: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

File Hello.java

1 public class Hello

2 {

3 public static void main(String[] args)

4 {

5 // display a greeting in the console window

6 System.out.println("Hello, World!");

7 }

8 }

Output: Hello, World!

Page 29: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

A Simple Program

Figure 13:Calling a Method

System ClassSystem.out Objectprintln Method

• public class ClassName • public static void main(String[] args) • // comment• Method call

Page 30: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

Self Check 7. How would you modify the HelloTester program

to print the words "Hello," and "World!" on two lines? Ans:

8. Would the program continue to work if you omitted the line starting with //? Ans: Yes–the line starting with // is a comment, intended for human readers. The compiler ignores comments.

System.out.println("Hello,");System.out.println("World");

Page 31: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

Self Check cont…

9. What does the following set of statements print?

Ans: The printout is My lucky number is12.

(It would be a good idea to add a space after the is. )

System.out.print("My lucky number is");System.out.println(3 + 4 + 5);

Page 32: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

Errors· Syntax errorsSystem.ouch.print("...");System.out.print("Hello);

· Detected by the compiler · Logic errorsSystem.out.print("Helop");

· Detected (hopefully) through testing

Page 33: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

Self Check10. Suppose you omit the // characters

from the HelloTester.java program but not the remainder of the comment. Will you get a compile-time error or a run-time error?Ans: A compile-time error. The compiler will not know what to do with the word display.

11. How can you find logic errors in a program?Ans: You need to run the program and observe its behavior.

Page 34: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

From Source Code to Running Program

Page 35: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

The Edit-Compile-Test Loop

Page 36: CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture

CLASSWORK/HOMEWORK! R1.11 Use the Hello.java program to

create different syntax errors. Record these errors. Then use the program to create a logic error. Describe the error you created.

Do Exercises p 30 – 31 P1.1, P1.2, P1.4 - P1.7

At home Read sections 1.7 through 1.8 taking notes (pp 23-27)

On p 29 do review exercises R1.4 – 1.6, R1.10, and R1.12 to hand in.

Project 1.1