Nobody can override the behaviors of any of the String methods, so you can rest assured that the String objects you are counting on to be immutable will, in fact be immutable.

What does the JVM do to make Java more efficient when handling String literals for a program?

The JVM sets aside a special area of memory called the "String constant pool". When the compiler encounters a String literal, it checks the pool to see if an identical String already exists. If a match is found, the reference to the new literal is directed to the existing String, and no new String literal object is created.

What does the String method "charat()" do?

Returns the character located at the String's specified index.

What index do Strings start at?

zero, Strings are zero-based.

What does the String method "concat()" do?

Returns a String with the value of the String "passed" in to the method appended to the end of the String used to "invoke" the method.

What overloaded operators perform functions similar to the "concat()" method?

The overloaded "+" and "+=" operators.
Note: the "+=" operator is an assignment operator

What does the String method "equalsIgnoreCase()" do?

Returns a "boolean" value(true or false) depending on whether the value of the String in the "argument" is the same as the value of the String used to "invoke" the method.

What does the String method "length()" do?

Returns the length of the String used to "invoke" the method.

What is the difference between "length" of an array and "length" of a String?

Strings have a method named "length()", arrays have an attribute named "length"

What does the String method "replace(char old, char new)" do?

Returns a String whose value is that of the String used to "invoke" the method, updated so that any occurrence of the "char" in the first argument is replaced by the "char" in the second argument.

What do the String methods "substring(int begin)" and "substring(int begin, int end) do?

Return a part (or substring) of the String used to invoke the method. The first argument represents the starting location(zero-based) of the substring. If the call has one argument, the substring will include the characters to the end of the original String. If the call has two arguments, the substring returned will end with the character located in the "nth" position of the original String.
Note: the ending argument is not zero-based.

What does the String method "toLowerCase()" do?

Returns a String whose value is the String used to "invoke" the method, but with any uppercase characters converted to lowercase.

What does the String method "toString()" do?

Returns the value of the String used to "invoke" the method. This is a seemingly "do nothing" method - but all obejcts in Java must have a "toString()" method.

What does the String method "toUpperCase()" do?

Returns a String whose value is the String used to "invoke" the method, but with any lowercase characters converted to uppercase.

What does the String method "trim()" do?

Returns a String whose value is the String used to "invoke" the method but with leading or trailing blank spaces removed.

When should the StringBuffer class be used?

When you have to make a lot of modifications to strings of characters. A common use if file I/O when large, ever-changing streams of input are being handled by the program.

Are objects of type StringBuffer immutable?

No, objects of type StringBuffer can be modified over and over again without leaving behind a great effluence of discarded String objects.

What do all of the StringBuffer methods operate on?

They operate on the value of the StringBuffer object invoking the method.

What does the StringBuffer method "append(String s)" do?

Returns a StringBuffer object with the argument's value appended to the value of the object that "invoked" the method.

What kind of arguments can the StringBuffer method "append(String s)" take?

Many different arguments, boolean, char, double float, int, long, and others, but the most likely to be used on the exam is a String argument.

What does the StringBuffer method "insert( int offset, String s)" do?

Returns a StringBuffer object and updates the value of the StringBuffer object that invoked the method call by inserting the second argument into the original StringBuffer starting at the "offset" location represented by the first argument (the offset is zero-based).
Note: other types of data can be passed in through the second argument(boolean, char, double, float, int, long, etc.)

What does the StringBuffer method "reverse()" do?

Returns a StringBuffer object and updates the value of the StringBuffer object that invoked the method call by reversing the characters in the StringBuffer.

What does the StringBuffer method "toString()" do?

Returns the value of the StringBuffer object that "invoked" the method call as a String.

What is the general form of a statement with chained methods and how are they evaluated?

result = method1().method2().method3();

It is evaluated from left to right.

What classes are imported automatically?

All classes in the java.lang package so there is no reason to write an "import" statement for them.

The java.lang package defines object wrappers for what types?

All primitive types. The class names are Boolean, Byte, Character, Double, Float, Integer, Long, Short, and Void as well as Object, the class from which all other Java classes inherit.

What package contains the Math class?

the Math class

What two mathematical constants does the Math class define approximations and what are their signatures?

pi and e:

public final static double Math.PI
public final static double Math.E

Why don't you need to create an instance to use the methods in the Math class?

They are all defined as "static".

Why can't you create an instance of the Math class?

Becuase its constructor is "private".

Why can't you extend the Math class?

It is marked as "final".

How are static methods accessed?

Through the class name.

What is the general form of the methods in the Math class?

result = Math.aStaticMathMethod();

What does the Math class method "abs()" do?

Returns the absolute value of the argument. It is overloaded to take an int, a long, a float or a double argument. In all but two cases, the returned value is nonnegative.

When does the Math class method "abs()" return a negative value?

If the argument is the minimum "int" or "long" value equal to the value of Integer.MIN_VALUE or Long.MIN_VALUE, respectively.

Returns a "double" that is greater than or equal to 0.0 and less than 1.0.

What is the signature of the Math class method "random()"?

public static double random()

What does the Math class method "round()" do?

Returns the integer closest to the argument. The algorithm is to add 0.5 to the argument and truncate to the nearest integer equivalent. This method is overloaded to handle a float or a double argument.

What are the signatures of the Math class method round()?

public static int round(float a)
public static long round(double a)

What does the Math class method "sin()" do?

Returns the sine of an angle. The argument is a "double" representing an angle in radians.

What is the signature of the Math class method "sin()"?

public static double sin(double a)

What does the Math class method "cos()" do?

Returns the cosine of an angle. the argument is a "double" representing an angle in radians.

What is the signature of the Math class method "cos()"?

public static double cos(double a)

What does the Math class method "tan()" do?

Returns the tangent of an angle. The argument is a "double" representing an angle in radians.

What is the signature of the Math class method "tan()"?

public static double tan(double a)

What does the Math class method "sqrt()" do?

Returns the square root of a "double".

What does the Math class method "sqrt()" return if the argument is a negative number?

NaN which is a bit pattern that denotes "not a number"

What is the signature of the Math class method "sqrt()"?

public static double sqrt(double a)

What does the Math class method "toDegrees()" do?

Takes an argument representing an angle in radians and returns the equivalent angle in degrees.

What is the signature of the Math class method "toDegrees()"?

public static double toDegrees(double a)

What does the Math class method "toRadians()" do?

Takes an argument representing an angle in degrees and returns the equivalent angle in radians.

What is the signature of the Math class method "toRadians()"?

public static double toRadians(double a)

List the numeric primitive types from narrowest to widest.

byte, short, int, long, float, double

Any numeric primitive can be implicitly cast to any numeric primitive that is ____ than itself.

wider

What two purposes do wrapper classes in the Java API serve?

1. To provide a mechanism to "wrap" primitive values in an object so that the primitives can be included in activities reserved for objects.
2. To provide an assortment of utility functions for primitives. Most of these functions are related to conversions.

All of the wrapper classes except Character provide two constructors. Describe these in general terms.

One takes a primitive of the type being constructed, and one takes a String representation of the type being constructed.

What do the constructors for the Boolean wrapper take?

Either a "boolean" value true or false, or a cas-sensitive String with the value "true" or "false".

Can a Boolean object be used as an expression in a "boolean" test?

No

What does the "valueOf()" method in a wrapper class do?

Gives another approach to creating wrapper objects. The first argument is a String representation of the appropriate type of primitive and when the method takes a second argument, it is "int radix" which indicates in what base the first argument is represented.

Describe the "xxxValue()" conversion utilities?

Used to convert the value of a wrapped numeric to a primitive and take no argument. Each of the six numeric wrapper classes has six methods, so that any numeric wrapper can be converted to any primitive type.

What happens when the String argument in a "valueOf()" method of a wrapper class is not properly formed?

a NumberFormatException is thrown

What does the "parseXxx()" method of a wrapper class return?

returns the named primitive

All the wrapper classe have what kind of "toString()" method?

a no-arg, nonstatic, instance version of "toString()" which returns a String with the value of the primitive wrapped in the object.

All of the numeric wrapper classes provide an overloaded, static "toString()" method. Describe this method.

It takes a primitive numeric of the appropriate type (Double.toString() takes a double) and returns a String with that primitive's value.

Describe the third "toString()" method that the Integer and Long wrapper classes have.

It is static, its first argument is the appropriate primitive, and its second argument is a radix. The radix argument tells the method to take the first argument which is radix 10 by default and convert it to the radix provided, then return the result as a String.

Describe the "toXxxString()" conversion methods.

The Integer and Long wrapper classes have these and they let you convert numbers in base 10 to other bases (Binary, Hex, Octal).
They return a String representation of the converted number.

What operator must you use to compare primitive variables?

the operator ==, it returns true if the two bit patterns are identical

What does "==" mean for reference variables?

It means that both reference variables are referring to the same object.

Can the "equals()" method be used on primitive variables?

No

When comparing reference variables with "==" what must be true or you will get a compiler error?

They must be in the same class hierarchy.

What operator should you use to determine if two String reference variables refer to the same String?

Use ==

What should you use if you want to determine if two objects are meaningfully equivalent?

Use the "equals()" method

When do all the wrapper class' "equals()" methods return true?

Only when both the primitive values and the wrapper's classes are the same.

Name two classes which are final?

The String and wrapper classes so you can't override any methods, including the "equals()" method.