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

Answer:

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 in the environment (in the editor, put the cursor over a class name and push F1). If you downloaded Java from Sun Microsystems, you might have downloaded the documentation for it, also. Otherwise, use Google or other search engine and search for Java String.

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

public will be explained in greater detail in another chapter.

QUESTION 9:

Is the following code correct?

String first = "Red " ;
String last  = "Rose" ;
String name  = first.concat( last );

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