Applet Life Cycle
Download
Report
Transcript Applet Life Cycle
Objects
Adapted from: "Introduction to
Programming"
Dr. Donald Bell, Cal Poly, 1999
(updated April, 2010)
Classes & Objects
Person
Car
String
a person class (an object from
class might be called aJolie)
a car class (object will have
characteristics and behaviors
of a specific car)
"hello" "Wendy Le" (objects)
Using Objects and Classes
Objects receive messages (which cause
methods to run)
Most statements using objects have the
following structure
The above statement means
object dot method
for example: thisPerson.setAge(24);
the object whose name is thisPerson
is sent the message setAge()
along with the "value" 24
This sets the person's age at 24 years old
Working with Objects/Classes
Most of Java involves working with
objects or classes
In a Java statement involving objects or
classes you must be able to identify
the object or class name
the message (method)
the argument (if any)
Sending Messages
myCar.setWeight(3500);
carWeight = myCar.getWeight();
System.out.println(carWeight);
System.out.println("Van Long");
System.out.println(custName);
System.out.println("Customer Name: " + custName);
Sending Messages to Objects - 2
System.out.println(custName.toUpperCase());
System.out.println("Sam Smith".toLowerCase());
System.out.println("Customer Name: " +
custName.toLowerCase());
custResponse = custAnswer.charAt(0);
custResponse = custAnswer.toUpperCase().charAt(0);
// note method working on results of another method
Review the Previous Examples
For each of the examples of Java
statements on the previous slides make
sure you can identify
the object and/or class name (or literal
object e.g., text)
the message(s) sent to the object or class
the argument (if any)
Naming Exercise
view Mouth.java class code
problem: mouths speak audibly, not write
text
e-mail from Mark Lutton
replace "Mouth" with some other class
name that could output text
replace say with some other class method
that is appropriate for the new object
Exercise: Java Object, Method
Documentation
Look at Sun's documentation for the
Java NumberFormat class
Click on the METHOD link near upper left
Identify the messages that can be sent to
NumberFormat objects
Identify arguments that these messages
can send to NumberFormat objects
Click the All Classes link near the upper
right to see a list of all classes in Java