APCS Java Subset

ap.java.lang
Class Object

java.lang.Object
  extended byap.java.lang.Object

public class Object
extends java.lang.Object

The class Object as viewed from the perspective of the Advanced Placement Computer Science Java subset.

See the complete Object javadoc.

The root of the Java class hierarchy.


Constructor Summary
Object()
           
 
Method Summary
 boolean equals(Object other)
           Understanding how to implement equals is not part of the AP Java subset.
 int hashCode()
           Understanding how to implement hashCode is not part of the AP Java subset.
 String toString()
           According to the AP Java subset (A and AB) students are expected to understand that String concatenation using + invokes the toString() method on an object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Object

public Object()
Method Detail

equals

public boolean equals(Object other)
Understanding how to implement equals is not part of the AP Java subset. However, students are expected to understand the difference between a.equals(b) and a == b (A and AB).

Determines if this object is "equal" to another object.

In general, objects should be instances of the same class with the same guts to be considered equal. For example, the code below only prints same value since s and t are different strings though they have the same value: "hello".

 String s = new String("hello");
 String t = new String("hello");
 if (s.equals(t)) System.out.println("same value");
 if (s == t) System.out.println("same string");

 

Parameters:
other - is the other Object to which this one is compared
Returns:
true if this Object is equal to other

toString

public String toString()
According to the AP Java subset (A and AB) students are expected to understand that String concatenation using + invokes the toString() method on an object.

The toString() method is useful for printing an object and for returning a form of the object as a String in other contexts.

Returns:
a String form of the object (useful, e.g., for printing)

hashCode

public int hashCode()
Understanding how to implement hashCode is not part of the AP Java subset. However, according to the subset students should know that hashCode is a method of class Object (presumably for AB students only).

Note: when overriding equals be sure to override hashCode as well or hard-to-find bugs will occur if you put such an instance in a HashMap or HashSet.

Returns:
an int to be used in hashing, e.g., with java.util.HashMap

unofficial documentation for the APCS Java Subset