Class String

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

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 a current JDK distribution, you might have downloaded the documentation for it, also. Otherwise, use Google or other search engine. To find documentation for class String 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 ); 
    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 the method requires 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.