Gregory M. Kapfhammer
Details in the Textbook
Past: Using and modifying Java classes
Future: Writing our own Java classes!
Why do we need to create our own classes?
An object has state, defined by values of attributes
An object has behavior, defined by the operations
See Listings 4.1 and 4.2 in the textbook
We can define two classes: Die and RollingDice. Why?
Draw a picture to explain how you understand this code
Why was the program designed in this fashion?
Questions about this program's behavior?
Find all of the following parts of Die and RollingDice!
An object should be "self-governing"
It should be difficult to "reach in" to instance data
Why is this an important issue to enforce?
Let's review Figure 4.5 on page 169!
Visibility modifiers: public and private
See Figure 4.6 to understand the impact of visibility!
Classify methods as either accessors or mutators
Refer to Listings 4.3 and 4.4 in the textbook
Review the source code of
What is the purpose of a return statement?
Please find at least two return statements in the code
Type of the return is the same as type of the returned variable
Please find the parameter list for one of the methods
Characteristics of each entry in the parameter list?
Wait! Let's find the formal and actual parameters
What is the purpose of formal and actual parameters?
Methods can also define local data. Can you find any?
Do you fully understand this working example?
A constructor is invoked when an object is created
The name of the constructor is the same as the class
The constructor returns the type of the class itself
The return type of the constructor is not explicitly stated
Why not require explicit statement of this return type?
The default constructor already exists!
But, it makes an object without assigning values
Please think about the initial state of your objects!
Can you find a constructor in the provided source code?
Created in the same way as other objects
You still interact with them by calling methods
Organize the drawing of distinct visual objects in methods
Refer to the (past and future) lab assignment(s) and Sections 4.6 - 4.9 for more details!
Three kinds of objects: components, events, listeners
The focus is on event-driven programming
What kinds of GUI components are available?
Section 4.8: you can add buttons!
Section 4.9: you can create text fields!