Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1 Object Orientation: Objects and Classes.

Similar presentations


Presentation on theme: "Chapter 1 Object Orientation: Objects and Classes."— Presentation transcript:

1 Chapter 1 Object Orientation: Objects and Classes

2 Objects and Classes When you create a program using an object-oriented language, you are: –Creating a model of the problem –The model is built up from objects in the problem domain –Those objects must be represented in your program

3 Object vs. Class Let’s ask some questions about a student: –What color is his hair? –How tall is he? –What is his QCA?

4 Object vs. Class In order to answer these questions we need to know what student we are talking about. –This particular student is an instance of a student. In this example, the student is a class and the instance of the student is an object.

5 Object vs. Class A class is a generic example; a blue print if you will. An object is one particular instance of a class. It is sometimes said that you instantiate an object from a class

6 JAVA Conventions Names of Classes start with a Capital Letters. Names of objects start with lower case letters. This case convention is fairly well followed throughout the Java programming community.

7 BlueJ Let’s look at an example in BlueJ Shapes Sample from the Example folder Shapes Sample from the Example folder

8 Calling Methods When we right clicked on a object on the workbench in BlueJ, we got a popup menu with a bunch of function names listed. In Java, these functions are called methods When we chose one of these methods for the object to perform, we called or invoked the method When the method requires information from the programmer, the method is said to have a parameter

9 Method Signatures A method signature provides information about the method. –It tells us the name of the method –Whether or not the method requires a parameter –What type of information is returned from the method

10 Data Types The values a parameter can take Examples –int – whole numbers –String – a section of text Pitfall – forgetting the double quotes around a string. You’ll get a message like “Error: undefined variable”

11 Multiple Instances Object-oriented programming (OOP) allows for creating more than one object from the same class. The internal state of the object allows the computer to tell the different objects apart.

12 State All of the attributes that define an object is referred to as the object’s state Java refers to the individual attributes as fields

13 What is an object? All objects of the same class have the same fields (and methods). The values stored in those fields are different. The class indicates what fields and methods each object will have.

14 Object Interaction Objects can create other objects and invoke those objects methods Most Java programs have objects that will do just this Question: How do we do this?

15 Source Code Like most programming languages, Java is written using plain text files or source code files The source code tells the program how objects are created and how the objects will interact After a source code file is written, it must be compiled so that the Java Virtual Machine (JVM) can interpret it

16 Return Values Some methods not only take parameters, but give something back to you. These methods are said to have a return value You can tell this in the signature –String getName() This methods returns a String –void moveRight() This method returns void (nothing)

17 Homework 1.2, 1.5, 1.6, 1.9, 1.11, 1.18, 1.26

18 Quiz Explain the difference between an object and a class.


Download ppt "Chapter 1 Object Orientation: Objects and Classes."

Similar presentations


Ads by Google