Chapter 5 Notes


Site hosted by Angelfire.com: Build your free website today!

Class - a blueprint for an object

Each object has data values and actions associated with it
- data values are private instance variables
- - only available inside te class(scope)
- - every instance of an object is assigned a complete set of unique private instance variables

When an object is instantiated, memory allocations for all private instance variables are issued

Methods are task-oriented events that can be activated through the object

Two types of methods:

voidvalue-returning
does not return a valuereturns a value

Characteristics of an Object:

behaviorstateidentity
actions taht an object can performvalues stored by an objectuniquememory allocations for each object
defined by the methodsdefined by the private instance variablescreated when the objectis instantiated(-new line)

Client & Server interactions


- client sends messages to the server, to invoke the methods
- server performs and reacts according to the client's request(or message)


Object


- an entity that can be manipulated by invoking methods
- like "black box" witha a public interface (methods you call) and hidden implementation (the code and data neded to make the methods work)
- encapsulation - process of hiding implementation details
- object variable: to remember an object you store its memory location in an object variable--container that stores the location of an object
- memory is referenced by pointers
- object variable refers to object, does not contain object


Parameters


- two types of parameters
- - actual - insterted values
- - formal - description of the type of value to be inserted

- both parameters must match in . . .
- - type
- - quantity
- - position

Rectangle class is a class from Java library files
java.out.Rectangle("Abstract Windowing ToolKit")
- each rectangle is defined by the coordinates of the upper-lefthand corner, its width, its height
1 - DECLARE - Rectangle cerealBox; //declares an object variable of type Rectangle
2 - CREATE - cerealBox=new Rectangle(5,10,20,30);
3- PRINT - System.out.println(cerealBox); //same as cerealBox.toString
*/ OUTPUT
java.awt.Rectangle[x=5,y=10,width=20, height=30]
*/

System.out.println(new Rectangle(10,12,50,40);
- this will display teh state of the newly created object, but not store its location in a n object variable.

System.out.println("Jeff".length());
- a string is an object, so the methods can be invoked

4 - Rectangle r;
5 - r=cerealBox
- assign the same reference and is now locating at the same object
6 - r.translate(50,100);
7 - System.out.println(cerealBox);


Constructor


- contain teh instructions on initializing an object
- constructor name is the same as the class name
- only called when teh object is created


Overloading


- methods with teh same name but different parameter list
- compiler decides which constructor to use based on parameter type, quantity and arrangement


Designing a class


1- understand how objects need to behave
2- list method names
3- determine parameters and return type
4- create all constructors
5- implement all methods


Commenting a Class


- standard form of documentation
API(application programing interface)
1- comments start with: /**
2- describe the method's purpose in one sentence. start w/capital lettter and end w/ period
3- for each methoed parameter: @param paramterName short description
4- for every return statement: @retun description of returning value

Iplimenting a class


Order:
- 1 constructors
- 2 methods
- 3 instance fields

Implicit Parameter: this - represents the calling object
Ex. this.radius or this.getArea()

Calling One Constructor from Another
Ex. this("No Name",0.0);



~~~~Home~~~~