(Review:) How can you determine what an object of a particular class can do?

A good answer might be:

The variables and methods of a class will be documented somewhere.


Class String

With a Java development environment such as such as Borland JBuilder or Symantec Café the documentation is on-line (in the editor, put the cursor over a class name and push F1). If you got Java from Sun Microsystems, look on your hard disk, in someplace like C:\jdk1.3\docs\index.html. Here is a short version of the documentation for String.

    // Constructors
    public String(); 
    public String(String  value); 

    // Methods
    public char charAt(int  index);
    public String concat(String  str); 
    public boolean endsWith(String  suffix); 
    public boolean equals(Object  anObject); 
    public boolean equalsIgnoreCase(String  anotherString); 
    public int indexOf(int  ch); 
    public int indexOf(String  str); 
                       
    public int length(); 
    public boolean startsWith(String  prefix); 
    public String substring(int  beginIndex, int endIndex); 
    public String toLowerCase(); 
    public String toUpperCase(); 
    public String trim(); 

The documentation first lists constructors. Then it describes the methods. For example,

public String concat(String  str); 
--+--- --+---  --+--  ----+----
  |      |       |        |
  |      |       |        |
  |      |       |        +---- says that there must be a 
  |      |       |              String reference parameter
  |      |       |
  |      |       +----- the name of the method
  |      |
  |      +----- the method returns a reference 
  |             to a new String object
  |
  +----- anywhere you have a String object, 
         you can use this method

QUESTION 9:

Is the following code correct?

String first = "Dempster " ;
String last  = "Dumpster" ;
String name  = first.concat( last );

You don't have to know what this does (yet); look at the documentation and see if all the types are correct.