Java Reference Index

  1. Introduction
  2. Data Types
  3. Arrays
  4. Operators
  5. Program Control
  6. Classes
  7. Objects
  8. Interfaces
  9. Containers
  10. Class Structure
  11. Error Handling

    Program Types

  12. Applications
  13. Applets

    How To

  14. Type Conversions


  15. java.lang.reflect
  16. java.applet
  17. java.awt
  18. java.beans
  20. java.lang
  21. java.math
  23. java.rm
  26. java.text
  27. java.util
  28. java.servlet


  29. Object Class


  30. Terms
  31. Credits

Object Class

The Object class is the highest level superclass of Java. It contains the following methods that may be overridden in the subclass:

  • clone() - Used to make other objects of the same type. The object must be cloneable meaning it must implement the "Cloneable" interface and override the clone method. This method throws a CloneNotSupported Exception.
  • equals() - Used to compare two objects to see if they are the same object value.
  • finalize() - Used to clean up after a specific object. It is normally overridden by subclass objects to perform specific finilization functions before the object is destroyed.
  • toString() - A string representation of the object is returned.

The following methods are final and cannot be overridden:

  • getClass() - Gets the Class object runtime representation.
  • hashCode()
  • notify()
  • notifyAll()
  • wait() - There are three versions of this method.

Class class

There is a class named "Class". Using the getClass Object class method above will return the Class object which supports the following methods:

  • getName() - "returns a string representing the name of the class."
  • getMethods() - Used to return the methods of a class. The java.lang.reflect package is required to support the Method class. See the following example:
    import java.lang.reflect.*;
    import java.util.Random;
    class SeeMethods { 
      public static void main(String[] arguments) { 
        Random rd = new Random(); 
        Class className = rd.getClass(); 
        Method[] methods = className.getMethods(); 
        for (int i = 0; i < methods.length; i++) { 
          System.out.println(“Method: “ + methods[i]);