[G1 Android Development] mohsinkhan47:
OK. This is going to be my first lesson. Please notice that i want everyone to download bluej from bluej.org. This is recommended. Please test it out and practice the codes listed below. Learn everything about bluej to make your life and my life easier. I have added gpdraw.jar. Please add this file to your bluej library in perferneces. The codes below might not work so please add them. Some of my pictures didn't load so please download the document file below.

all copyright belong to their rightful owner

UPLOAD GPDRAW.JAR AND A BETTER VERSION OF MY LESSON HERE IS THE files

gpdraw.jar

http://www.mediafire.com/?2zkezwwyzyj

Lesson A1

http://www.mediafire.com/?2wyj2nh2mwm

_________________________________________________________________

A1 – Introduction to Object-Oriented Programming (OOP)

1.	Object-oriented programming (OOP) attempts to make programs more closely model the way people think about and deal with the world. In OOP, a program consists of a collection of interacting objects. To write such a program you need to describe different types of objects: what they know, how they are created, and how they interact with other objects. Each object in a program represents an item that has a job to do.

2.	The world in which we live is filled with objects. For example, an object we are all familiar with is a drawing tool such as a pencil or pen. A drawing tool is an object, which can be described in terms of its attributes and behaviors. Attributes are aspects of an object that describe it, while behaviors are things that the object can do. The attributes of a pencil are its drawing color, width of the line it draws, its location on the drawing surface, etc. Anything that describes an object is called an attribute. Its behaviors consist of drawing a circle, drawing a line in a forward or backward direction, changing its drawing direction, etc. Anything that an object does is called a behavior. Another aspect of an object has to do with creation, which determines the initial state of an object.

3.	In order to use an object within a program, we need to provide a definition for the object. This definition is called a class. The class describes how the object behaves, what kind of information it contains, and how to create objects of that type. A class can be thought of as a mold, template, or blueprint that the computer uses to create objects.

4.	When building a house, a construction crew uses a blueprint to define the aspects of the house. The blueprint gives the specifications on how many bedrooms there are, how to position the electrical wiring, the size of the garage, etc. However, even two houses built from the same blueprint may have different paint colors and will have different physical locations. Clients who are buying a house may make slight modifications to these blueprints. For example, they may want a bigger garage or a smaller porch. We can see the houses built from the blueprint as objects since they are all similar in structure, but each house has its own unique attributes. In the world of programming, we can view the blueprint just like a class, i.e. a tool for creating our objects.

B.	Methods

1.	While a program is running, we create objects from class definitions to accomplish tasks. A task can range from drawing in a paint program, to adding numbers, to depositing money in a bank account. To instruct an object to perform a task, we send a message to it.

2.	In Java, we refer to these messages as methods.

3.	An object can only receive a message that it understands, which means that the message must be defined within its class.

4. Suppose we take the DrawingTool class (provided by this curriculum in the package gpdraw.jar) and create an object myPencil. In OOP terminology, we say the object myPencil is an instance of the DrawingTool class. An object can only be an instance of one class. We can visually represent an object with an object diagram, as shown in Figure 1.1.

5.	These are some of the behaviors that the DrawingTool class provides:

•	forward

•	turnLeft

•	getColor

6.	To draw a line of a specified length, we call the method forward along with passing the distance to move the pencil. A value we pass to an object’s method is called an argument. A diagram of calling a method is shown below in Figure 1.2.

7.	If we need to change the direction myPencil is facing, we can call the turnLeft method. This will bring a ninety-degree turn to the left. Two left turns can give us a complete reversal of direction, and three left turns essentially gives us a right turn. Notice that we do not need to send any arguments with the turnLeft method. A left turn is simply a left turn and does not need any additional information from the user. A diagram calling turnLeft is shown below in Figure 1.3.

8.	The diagrams shown in Figures 1.2 and 1.3 illustrate situations in which an object carries out a request by the user but does not respond to the sender. Figure 1.2 requires arguments from the user because the user must specify how far to move, whereas Figure 1.3 operates without any specific details. However, in many situations we need an object to respond by returning a value to the sender. For example, suppose we want to know the current color that is being used for drawing. We can use the getColor method to return the value. The getColor method is illustrated returning a value to the sender in Figure 1.4 below.