Standard+Classes

Standard Classes to Know

Topics: 1. The Object class - as a superclass, methods - toString, equals, hashcode 2. The String class - string objects, constructing, concatenation, comparisons, methods - substring, indexOf 3. Wrapper classes - Integer, Double - The **wrapper class** takes an **existing object** or a **primitive type** and wraps it in an **object**. It then provides a **new set of methods** for that type. - The **Interger wrapping class** wraps a value of type int in an object. **AP Exam interger methods:**
 * Every class in java extends the Object class.
 * Methods include toString, equals, and hashCode
 * **Integer(int value)** //contructs an Integer object from an int//
 * **int compareTo(Object other)**
 * **int intValue** returns the value of this Integer as an int. (**Unboxing**)
 * **boolean equals(Object obj)** returns true if and only if this Integer has the same int value as obj.
 * **String toString** returns a string representing the value of this Integer.
 * wrapping and unwrapping example:

Integer intObj = new Integet(7); **wraps** //int d = intObj.intValue;// **unwraps**

- The methods for the **Double class** are analogous to those for the **Integer class**. - Remember that Integer and Double objects are **immutable**.
 * -** The **Double wrapping class** wraps a value of type double in an object.

4. The Math class - methods - abs, pow, sqrt, random 5. Random numbers - reals, integer - **Random reals** produces a random real number in the range 0.0 to 1.0, where 0.0 is included and 1.0 is not. This range can be scaled and shifted. - **Random Integers** in any range can be produced by casting to int, making a scaling factor, and then creating a shifting value using Math.random.
 * **public static abs(int a), Math.abs**: returns absolute value, can be used for doubles as well
 * **public static pow(double a, double b), Math.pow**: returns exponents, a to the b power
 * **public static sqrt(double a), Math.sqrt**: returns the sqrt of number
 * **public static random, Math.random**: returns a positive number between 0.0 and 1.0, inclusive