1 / 36

CHAPTER 1

CHAPTER 1. INTRODUCTION. 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

yvonne
Download Presentation

CHAPTER 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CHAPTER 1 INTRODUCTION

  2. 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

  3. PREREQUISITES • Computer savvy (file management, text editing) • Problem solving skills • Time management • High school math (Geometry, Algebra II) • No prior programming background required

  4. 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

  5. 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

  6. What is a computer? • Central processing unit • Memory • Peripherals • Executes very simple instructions • Executes instructions very rapidly • General purpose device • Programs describe specific actions

  7. Self Check 1. 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.

  8. 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.

  9. Central Processing Unit

  10. CPU and what it does • A single chip consisting of millions of transistors • performs program control • arithmetic operations • data movement

  11. A Memory Module with Memory Chips Figure 2: A Memory Module with Memory Chips

  12. A Hard Disk Figure 3: A Hard Disk

  13. A Motherboard Figure 4: A Motherboard

  14. Schematic Diagram of a Computer Figure 5: Schematic Diagram of a Computer

  15. The ENIAC Figure 6: The ENIAC

  16. Self Check 4. 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.

  17. Programming Languages • Machine/Virtual Machine21 40 16 100 163 240 • Assembleriload intRatebipush 100if_icmpgt intError • High-level languageif (intRate > 100) . . .

  18. 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 . . .

  19. The Java Programming Language • Simple • Safe • Platform-independent ("write once, run anywhere") • Rich library • Designed for the internet

  20. Applets on a Web Page Figure 7: Applets on a Web Page

  21. Java Versions

  22. 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.

  23. 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 -- vacabulary • boxes • points of interest (ENIAC) • p. 29 exercises R1.1 – R1.3 to be collected tomorrow with the self check exercises.

  24. Becoming Familiar with your Computer • Login • Locate the Java compiler • Understand files and folders • Write a simple program (later) • Save your work

  25. A ConsoleWindow

  26. An Integrated Development Environment Figure 9:An Integrated Development Environment

  27. 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

  28. 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!

  29. A Simple Program • public class ClassName • public static void main(String[] args) • // comment • Method call Figure 13:Calling a Method System Class System.out Object println Method

  30. 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");

  31. 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);

  32. Errors • Syntax errorsSystem.ouch.print("...");System.out.print("Hello); • Detected by the compiler • Logic errorsSystem.out.print("Helop"); • Detected (hopefully) through testing

  33. Self Check 10. 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.

  34. From Source Code to Running Program

  35. The Edit-Compile-Test Loop

  36. 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

More Related