Quick Reference to Java Classes and Methods

The following classes have been used in class. Methods shown are either methods that we have covered or helpful methods from that class. The verbiage describing the method behavior comes from the java API's (Application Program Interface) which can be found at java.sun.com/j2se/1.5.0/docs/api/.

System class

This class contains some system variables and some methods which are used for input and output. (NOTE: The print methods are technically NOT part of the system class, but rather are part of the out object's class. For comprehension, I am including them here, but with the name of the object, out.

Variables
static PrintStream err The "standard" output stream. (monitor)
static InputStream in The "standard" input stream. (keyboard)
static PrintStream out The standard output stream. (monitor)

Methods: Note: these are technically PrintStream methods (using the out object)
void out.print(String str) Prints a string.
void out.printf(String str, Object...args) A convenience method to write a formatted string to this output stream using the specified format string and arguments.
void out.println(String str) Print a String and then terminate the line.
void out.println() Terminate the current line by writing the line separator string.

Scanner Class

methods
Scanner(InputStream source) Constructs a new Scanner that produces values scanned from the specified input stream. (We have always used this with System.in as our source)
String next() Finds and returns the next complete token from this scanner.
String nextLine() Advances this scanner past the current line and returns the input that was skipped.
int nextInt() Scans the next token of the input as an int.
double nextDouble() Scans the next token of the input as a double.
Scanner useDelimiter(String str) Sets this scanner's delimiting pattern to a pattern constructed from the specified String.
boolean hasNext() Returns true if this scanner has another token in its input.
boolean hasNextInt() Returns true if the next token in this scanner's input can be interpreted as an int value in the default radix (base 10) using the nextInt() method.
boolean hasNextDouble() Returns true if the next token in this scanner's input can be interpreted as a double value using the nextDouble() method.
boolean hasNextLine() Returns true if there is another line in the input of this scanner.
NOTE: There are corresponding next and hasNext methods for all of the primitive types except for char.

Math Class

variable
static double Math.PI - The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.

Integer Class

variable
static integer MAX_VALUE - A constant holding the maximum value an int can have, 231-1.
static integer MIN_VALUE - A constant holding the minimum value an int can have, -231.

String Class

methods
int length() Returns the length of this string.
char charAt() Returns the char value at the specified index.
int compareTo(String other) Compares this String to the other String lexicographically. If the two are equal, the result is 0, if the calling String (this) is greater than the other String, the result is a positive integer. If the calling String (this) is less than the other String, the result is a negative integer.
boolean equals(String other) Compares this string to the other String.
boolean equalsIgnoreCase(String other) Compares this String to the other String, ignoring case considerations.