|
|
The java.lang Package Certification - Main Classes
- the java.lang Package contains classes that are fundamental to the Java programming language
- it is always implicitly imported
- the most important classes are Object and Class
Object
- the Object class is at the root of the class heirarchy, all other classes inherit it's methods
- protected Object clone() throws CloneNotSupportedException
- returns an identical copy of an object. The object must implement the Cloneable interface
- public boolean equals(Object obj)
- returns true if obj is the same object as the referenced object
- protected void finalize() throws Throwable
- called by the garbage collector prior to collecting the object
- public final Class getClass()
- returns the runtime class of an object
- public int hashCode()
- returns a distinct integer representing a unique object; supports hash tables
- public final void notify()
- wakes up a single thread waiting on the object's monitor
- public final void notifyAll()
- wakes up all threads waiting on the object's monitor
- public String toString()
- returns a string representation of the object
- public final void wait() throws InterruptedException,
public final void wait(long timeout) throws InterruptedException,
public fianl void wait(long timeout, int nanos) throws InterruptedException
- causes the current thread to wait until another thread invokes notify() or notifyAll() for this object, or, the specified time elaspses
Class
- the Class class was introduced in JDK 1.2
- instances of the Class class represent classes and interfaces in a running Java application
- also represents arrays, primitive types and void, all of which are Class instances at runtime
- objects of the Class class are automatically created as classes are loaded by the JVM; they are known as class descriptors
- provides over 30 methods which can be used to obtain information on a running class
- some of the more useful methods are: getName(), toString(), getSuperclass(), isInterface(), newInstance()
Other classes
- Wrapper classes used to represent primitive types as Objects: Boolean, Byte, Short, Character, Integer, Float, Long and Double
- Math class provides commonly used mathematical functions ie cos, sine, tan
- String and StringBuffer classes provide commonly used operations on character strings
- System operation classes: ClassLoader, SecurityManager, Runtime, Process and System which manage the dynamic loading of classes, creation of external processes, security, and host inquiries ie time of day
- Package class is new to JDK 1.2. Provides methods for obtaining package version information stored in the manifest of jar files. Useful methods include: getPackage(), getAllPackages(), which provide package objects that are known to the class loader, and isCompatibleWith() which is used to determine wether a package is comparable to a particular version.
- all the Exception and Error classes, including Throwable
Interfaces
- Cloneable. Contains no methods. Used to differentiate between objects that are cloneable and non-cloneable.
- Comparable, new in JDK 1.2. Defines the compareTo() method. Objects implementing this interface can be compared and sorted.
- Runnable. Defines the run() method which is invoked when a thread is activated.
|