10.java
10.java
•Class "Object":
the class at the very top of inheritance tree.
all Java classes inherit from Object (common ancestor).
---------
•public int hashCode() -> returns the hashcode number of the object.
---------
•protected Object clone() throws CloneNotSupportedException
-> creates and returns the exact copy(clone) of "this" object.
---------
•public final void notify() -> wakes up 1 thread waiting on the
object's monitor.
---------
•public final void notifyAll() -> wakes up all threads.
---------
•public final void wait(long timeout) throws InterruptedException
-> current thread wait for specified milliseconds, until another
thread notifies (invokes notify() and notifyAll()).
---------
•public final void wait(long timeout,int nanos) throws InterruptedException
-> current thread wait for specified millisecondsand nanoseconds, until
another thread notifies (invokes notify() and notifyAll()).
---------
•public final void wait() throws InterruptedException
-> current thread wait, until another thread notifies (invokes notify() and
notifyAll()).
---------
•protected void finalize() throws Throwable -> invoked by the garbage
collector before object is being garbage
collected.
---------
•public String toString()
-> returns the string representation of "this" object.
--------------------------------------------------
public String toString()
{
return name+" "+age+" "+employeeID+" "+salary;
}
--------------------------------------------------
-in MAIN method:
System.out.println(employee1);
System.out.println(employee1.toString);
---------
•public boolean equals(Object obj) -> compares given object with "this"
object.
(Object: name of the obj class)
1-----------------------------------------------------
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null || getClass() != obj.getClass())
{
return false;
}
}
-------------------------------------------------------
-->checked object references, classes and if it is null
2-------------------------------------------------------
public boolean equals(Object obj)
{
if (obj instanceof Employee)
{
return employeeID == ((Employee)obj.employeeID);
}
--------------------------------------------------------
--> if the object is an instance of the class, then
compare the unique attribute(ID) of both objects.
-----------------------------------------------------------------------------------
---------
•Final Methods:
>cannot be overridden
>useful for security purposes
--------------------------------------------------------------
public final boolean validatePassword(String name, String pwd)
{
...
}
--------------------------------------------------------------
•Final Classes:
>cannot be extended (don't have subclasses)
--------------------------------------------------------------
public final class CLASSNAME
{
...
}
--------------------------------------------------------------