Presentation is loading. Please wait.

Presentation is loading. Please wait.

©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 1 Chapter 1 Introduction.

Similar presentations


Presentation on theme: "©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 1 Chapter 1 Introduction."— Presentation transcript:

1 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 1 Chapter 1 Introduction

2 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 2 Welcome to CS46A www.horstmann.com/sjsu Green Sheet Register for Companion Lab Send email to add First homework due September 7

3 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 3 Course Goals Introduction to computer science Programming concepts Problem solving Object-oriented programming Introduction to Java (but not a Java course) Foundation for CS majors

4 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 4 Prerequisites Computer savvy (file management, text editing) Problem solving skills Time management High school math (algebra, trigonometry) No prior programming background required

5 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 5 What is a computer? Central processing unit Memory Peripherals Executes very simple instructions Executes instructions very rapidly General purpose device Programs describe specific actions

6 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 6 Figure 1 Central Processing Unit

7 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 7 Figure 2 CPU Chip Detail

8 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 8 Figure 3 RAM Chips

9 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 9 Figure 4 A Hard Disk

10 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 10 Figure 5 A High-Capacity Floppy Disk and Its Drive

11 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 11 Figure 6 A CD-ROM Drive

12 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 12 Figure 7 Tape Backup Drives and Data Tape

13 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 13 Figure 8 A Personal Computer

14 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 14 Figure 9 A Motherboard

15 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 15 Figure 10 Schematic Diagram of a Personal Computer

16 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 16 Programming Languages Machine/Virtual Machine 21 40 16 100 163 240 Assembler iload intRate bipush 100 if_icmpgt intError High-level language if (intRate > 100)...

17 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 17 The Java Programming Language Simple Safe Platform-independent ("write once, run anywhere") Rich library Designed for the internet

18 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 18 Figure 12 An Applet on a Web Page

19 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 19 Becoming Familiar with your Computer Login Locate the Java compiler Understand files and folders Write a simple program (later) Save your work

20 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 20 Figure 13 A Startup Screen with Icons

21 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 21 Figure 14 A Directory Hierarchy

22 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 22 Figure 15 Screen Layout of an Integrated Java Environment

23 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 23 A simple program public class ClassName public static void main(String[] args) object.methodName(parameters) System class System.out object println method

24 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 24 Program Hello.java public class Hello { public static void main(String[] args) { System.out.println("Hello, World!"); }

25 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 25 Compiling and Running Type program into text editor Save Open command shell Compile into byte codes javac Hello.java Execute byte codes java Hello

26 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 26 Figure 16 From Source Code to Running Program

27 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 27 Edi t– Compil e– Debug Loop Figure 17

28 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 28 Errors Syntax errors System.ouch.print("..."); System.out.print("Hello); Detected by the compiler Logic errors System.out.print("Hell"); Detected (hopefully) through testing

29 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 29 Objects and Classes Object: entity that you can manipulate in your programs (by invoking methods) Each object belongs to a class Class: Set of objects with the same behavior Class determines legal methods "Hello".println() // Error "Hello".length() // OK

30 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 30 A Class has 4 Purposes: A class specifies which methods you can apply to its objects A class is a factory for objects ( new ) A class is a holding place for static methods and objects ( main, System.out ) A class defines implementation details: object fields and code for methods

31 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 31 Rectangle class Construct a rectangle: new Rectangle(5, 10, 20, 30) new Rectangle() Object variables: Rectangle cerealBox = new Rectangle(5, 10, 20, 30); Rectangle crispyCrunchy; Sharing objects: crispyCrunchy = cerealBox;

32 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 32 Figure 18 Rectangular Shapes

33 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 33 Figure 19 Rectangle Objects

34 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 34 Objec t Refers to an An Object Variable That Figure 20

35 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 35 An Uninitialized Object Variable Figure 21

36 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 36 Figure 22 Two Object Variables That Refer to the Same Object

37 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 37 Rectangle class 2 Print a rectangle System.out.println(cerealBox); Translate a rectangle cerealBox.translate(15, 25) Import statement: import java.awt.Rectangle;

38 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 38 Program MoveRectangle.java import java.awt.Rectangle; public class MoveRectangle { public static void main(String[] args) { Rectangle cerealBox = new Rectangle(5, 10, 20, 30); cerealBox.translate(15, 25); System.out.println(cerealBox); }

39 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 39 Algorithms 1 Example: You put $10,000 into a bank account that earns 5% interest per year. Interest is compounded annually. How many years does it take for the account balance to be double the original?

40 ©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 40 Algorithms 2 Unambiguous Executable Terminating If you can't find an algorithm, the computer can't solve your problem


Download ppt "©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 1: Introduction 1 Chapter 1 Introduction."

Similar presentations


Ads by Google