java.lang包学习--Object

在API中看一下对这个包描述

Package java.lang Description

Provides classes that are fundamental to the design of the Java programming language. The most important classes are Object, which is the root of the class hierarchy, and Class, instances of which represent classes at run time.

Frequently it is necessary to represent a value of primitive type as if it were an object. The wrapper classes Boolean, Character, Integer, Long, Float, and Double serve this purpose. An object of type Double, for example, contains a field whose type is double, representing that value in such a way that a reference to it can be stored in a variable of reference type. These classes also provide a number of methods for converting among primitive values, as well as supporting such standard methods as equals and hashCode. The Void class is a non-instantiable class that holds a reference to a Classobject represening the primitive type void.

The class Math provides commonly used mathematical functions such as sine, cosine, and square root. The classes String and StringBuffersimilarly provide commonly used operations on character strings.

Classes ClassLoader, Process, Runtime, SecurityManager, and Systemprovide "system operations" that manage the dynamic loading of classes, creation of external processes, host environment inquiries such as the time of day, and enforcement of security policies.

Class Throwable encompasses objects that may be thrown by the throw statement (§14.16). Subclasses of Throwable represent errors and exceptions.

这个包是一个基础包重要的是里面提供了所有类的父类object.该包是我们编程是必须的包

2.Object类

public class Object

Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.

这是该类的解释,简单的3句却表明了它的地位。

3.Object类提供的默认构造函数和方法

3.1默认构造函数

比较简单的构造函数

public Object()

3.2方法

Method Summary
protected  Object clone()
          Creates and returns a copy of this object.
boolean equals(Object obj)
          Indicates whether some other object is "equal to" this one.
protected void finalize()
          Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
Class<? extends Object> getClass()
          Returns the runtime class of an object.
int hashCode()
          Returns a hash code value for the object.
void notify()
          Wakes up a single thread that is waiting on this object's monitor.
void notifyAll()
          Wakes up all threads that are waiting on this object's monitor.
String toString()
          Returns a string representation of the object.
void wait()
          Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.
void wait(long timeout)
          Causes current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed.
void wait(long timeout, int nanos)           Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

在这些方法中,主要的包括euqals(),toString(),hashCode(),这些都需要进行覆盖才能得到有意义的应用

 

 

 

posted @ 2012-09-14 19:25  qqhegg  阅读(363)  评论(0编辑  收藏  举报