©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 1 CS 125 Introduction to Computers and Object- Oriented Programming
©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
©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
©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
Computer Science is a relatively new field First programmable electronic computer, ENIAC, was built around 1945 Technology has changed dramatically –First computers built using vacuum tubes –Transistors soon replaced vacuum tubes –Integrated circuits allowed computers to get small and inexpensive Early computers were isolated –Networks allow computers to talk to each other
©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
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 7 Information Storage The devices used to store information in computers have two possible states –0 or OFF –1 or ON 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
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 8 Software 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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 9 Software Development Process Describe what the program needs to do Analyze the problem and determine how to solve it Write the program Test the program Maintain the program
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 10 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
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 11 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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 12 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
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 13 What you'll learn in this course Basic Computer Science concepts Problem solving –object-oriented approach How to program (software development) –Java programming language
Object-Oriented Programming One way to think of a program is as a sequence of operations on data. –a program is a collection of procedures that are executed in a particular order For large programs, this approach can be hard to manage An object-oriented program consists of a group of objects which interact with each other –provides modularity –allows for reuse –models the real world
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 15 Objects An object is a thing, (tangible or intangible). –Account –Vehicle –Employee Objects can have –Properties –Behavior
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 16 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
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 17 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
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 18 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 :
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 19 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)
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 20 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
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 21 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
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 22 Sending a Message deposit Message deposit with the argument 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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 23 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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 24 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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 25 SV098 : BankAccountSV211 : BankAccountSV129 : BankAccount Data Values in Object Diagrams current balance 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 minimum balance
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 26 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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 27 A Sample Inheritance Here are the superclass Account and its subclasses Savings and Checking. Account Checking Savings
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 28 Inheritance Hierarchy An example of inheritance hierarchy among different types of students. Student Graduate Undergrad Commuting Law Resident Masters Doctoral