Presentation is loading. Please wait.

Presentation is loading. Please wait.

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 1 CS 125 Introduction to Computers and Object- Oriented Programming.

Similar presentations


Presentation on theme: "©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 1 CS 125 Introduction to Computers and Object- Oriented Programming."— Presentation transcript:

1 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 1 CS 125 Introduction to Computers and Object- Oriented Programming

2 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 2 What is computer science? … the study of the theoretical foundations of information and computation and their implementation and application in computer systems From Wikipedia

3 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 3 Computer Science has many subfields Computer architecture Algorithms Programming languages and compilers Databases Operating systems Networking Computer security Software engineering Artificial intelligence Computer graphics Theory of computation

4 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 4 Fields that depend on computer science Scientific computing Bioinformatics Cryptography Simulation Weather modeling

5 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 5 What you'll learn in this course Basic Computer Science concepts Problem solving –object-oriented approach How to program –Java programming language

6 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 6 Computer Architecture CPU Output Devices Output Devices Commu- nication Devices Commu- nication Devices Input Devices Input Devices RAM Storage Devices Storage Devices

7 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 7 Computer Hardware The CPU (central processing unit) is the heart of the computer RAM (memory) stores both programs and data External storage devices (disks) provide permanent storage for programs and data

8 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 8 Central Processing Unit Consists of –Arithmetic Logic Unit which does the actual work –Registers for temporary storage of data and results –Instruction register to store the current instruction –program counter which stores location of next instruction Instructions are low-level operations like –transfering data between memory and registers –arithmetic operations –comparisons

9 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 9 Memory Memory consists of a large number of bits whose value can be either 0 or 1 Memory is divided into words (32 bits commonly) which can be addressed individually All information needs to be stored in binary format –base 2 numbers for integers –base 2 scientific notation for real numbers –integer code for characters –instructions that make up executable programs are binary words

10 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 10 What is Programming Computer hardware, by itself, isn't very useful. Software is what we use to make the computer do what we want it to. A program is a sequence of instructions that will be executed by a computer. –The operating system is a special program that manages our interactions with the computer.

11 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 11 What is Programming To write a program, you need to learn a language that can be converted into a form that the computer can understand –Early languages were designed to make this conversion easy –Modern languages are designed for the convenience of the programmer Java is a high-level object-oriented language

12 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 12 Programming Languages Machine Language Machine language instructions (very low level) are sequences of 0s and 1s. Assembly Languages Assembly language is a mnemonic representation of machine language. An assembler translates assembly language into machine language. High-level Languages High-level languages provide a very high conceptual model of computing. A compiler translates high-level programs into machine language instructions.

13 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 13 Types of Languages Procedural languages approach programming as a sequence of operations on data Functional languages (LISP) consider a program to be a series of functions that map the input data to some desired output Object-oriented languages model the world as a collection of objects –every object has properties (data) that represent its state –objects have behavior (operations) associated with them

14 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 14 Objects An object is a thing, (tangible or intangible). –Account –Vehicle –Employee Objects can have –Properties –Behavior

15 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 15 Classes To create an object inside the computer program, we must first provide a definition or template for that particular kind of object –how it behaves –what properties it has We call this definition a class Every object is an instance of some class. –Multiple objects can be created from a single class

16 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 16 Data and Methods Properties of an object are represented by data values Behavior of objects is implemented by the methods in a class –Send a message to an object by calling one of its methods Two types of data and methods –Class methods and data are shared by all objects –Instance data and methods are associated with a particular object

17 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 17 Classes and Objects A class is a template that defines what properties and behavior a particular type of object has –Class diagram An object is an instance of a class –You can have many instances of a class –Object diagram :

18 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 18 Unified Modeling Language A language for graphically describing classes, objects and programs We'll use a subset of this language in this class. –Object diagrams –Class diagrams State-of-memory diagrams use UML as well Tools on onyx –violet (a Java program) –dia (a Linux tool)

19 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 19 Graphical Representation of a Class The notation we used here is based on the industry standard notation called UML, which stands for Unified Modeling Language. We use a rectangle to represent a class with its name appearing inside the rectangle. Example: Account Motorcycle

20 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 20 Graphical Representation of an Object We use a rectangle to represent an object and place the underlined name of the object inside the rectangle. Examples: SV198 : This notation indicates the class which the object is an instance. SV198 : BankAccount

21 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 21 Sending a Message deposit 250.00 Message deposit with the argument 250.00 is sent to a BankAccount object SV198. SV198 : BankAccount To instruct an object to perform a task, we send a message to it. The class an object belongs to must possess a matching method to be able to handle the received message. A value we pass to an object when sending a message is called an argument.

22 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 22 Sending a Message and Getting an Answer current balance getCurrentBalance() Ask for the current balance of this particular account. SV198 : BankAccount The current balance of SV198 is returned.

23 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 23 Class and Instance Data Values An object is comprised of data values and methods. An instance data value is used to maintain information specific to individual instances. For example, each BankAccount object maintains its balance. A class data value is used to maintain information shared by all instances or aggregate information about all instances. For example, minimum balance is the information shared by all Account objects, whereas the average balance of all BankAccount objects is an aggregate information.

24 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 24 SV098 : BankAccountSV211 : BankAccountSV129 : BankAccount Data Values in Object Diagrams current balance 908.55 1304.98 354.00 All BankAccount objects possess the same instance data value current balance. The actual dollar amounts are, of course, different. Object Diagram with Class Data Value SV129 : BankAccount current balance 908.55 minimum balance 100.00

25 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 25 Inheritance Inheritance is a mechanism in OOP to design two or more entities that are different but share many common features. –Features common to all classes are defined in the superclass. –The classes that inherit common features from the superclass are called subclasses. We also call the superclass an ancestor and the subclass a descendant.

26 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 26 A Sample Inheritance Here are the superclass Account and its subclasses Savings and Checking. Account Checking Savings

27 ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 27 Inheritance Hierarchy An example of inheritance hierarchy among different types of students. Student Graduate Undergrad Commuting Law Resident Masters Doctoral


Download ppt "©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 1 CS 125 Introduction to Computers and Object- Oriented Programming."

Similar presentations


Ads by Google