Lecture Summary for 211 on 7/07/03 -- O'Hare

 

Review Questions

  1. Give three reasons why software engineers would want to write static methods, other than the main method.
    Answer: To avoid code duplication, for modularity, and to facilitate code reuse.

  2. What does method invocation mean?
    Answer: It means to call a method.

  3. How do you invoke a method with return type void?
    Answer: Place the method name with any arguments in parentheses on a line by itself.

  4. What does the header of a method contain?
    Answer: It contains the visibility (public or private), whether the method is static, the return type, the name of the method, and any parameters.

  5. What is the difference between a method argument and a method parameter?
    Answer: An argument is specified at method invocation, but a parameter is specified in the header of the method at definition.

  6. How do you specify the return value of a non-void method in the method definition?
    Answer: You put the return type in the header.

  7. How do you invoke a non-void method?
    Answer: Use the method call in an expression. The return value is used in the expression.

  8. Write a Java application that inputs a list of items consisting of name, gender, and salary. Output the name of the woman with the largest salary.

  9. True or False. A maximum of 20 objects can be created from a given class.
    Answer: False. Objects can be created as long as you have enough memory, usually at least thousands.

  10. What does UML mean?
    Answer: Unified Modeling Language

  11. What are the three sections of a UML class diagram?
    Answer: Class name, instance variables, methods.

 

The DecimalFormat Object

 

UML

 

The Kid1 Example

 

Accessing Members of an Object

 

The Kid2 Example

 

Constructors

 

Public vs. Private Members

 

Overloaded Methods

 

Public vs. Private Members

  Instance Vars Access Mode Advantages Disadvantages
Method 1 public Direct Easy Not Safe
Method 2 private Using Methods* Safe Complicated

*Methods to manipulate instance variables are of two types:

  1. Accessor methods provide read only access to instance variables.

  2. Mutator methods can modify instance variables. Data validation or error checking can be performed.

 

The Student Example

 

The LasVegas Project

 

The Die Example

 

The Trace3 Examples