Core Java Interview Question
Core Java Interview Question
protected Object clone() - Used to create and return a copy of this object.
boolean equals(Object obj) - Used to indicate whether some other object is "equal to"
this one.
protected void finalize() - garbage collector calls this method on an object when it
determines that there are no more references to the object.
Class<?> getClass() - Used to get the runtime class of this Object.
int hashCode() - Used to get a hash code value for the object.
void notify() - Used to wake up a single thread that is waiting on this object's monitor.
void notifyAll() - Used to wake up all threads that are waiting on this object's monitor.
String toString() - Used to get a string representation of the object.
void wait() - marks the current thread to wait until another thread invokes the notify()
method or the notifyAll() method for this object
Why Strings are immutable and how to make your own immutable
class. Example of existing immutable class in java .
Class loader
The Java ClassLoader is a part of the Java Runtime
Environment that dynamically loads Java classes into the Java Virtual
Machine. The Java run time system does not need to know about files
and file systems because of classloaders.
Java classes aren’t loaded into memory all at once, but when required by
an application. At this point, the Java ClassLoader is called by
the JRE and these ClassLoaders load classes into memory dynamically.
Static Keyword
The static keyword in Java is used for memory management mainly.
We can apply static keyword with variables, methods, blocks and
nested classes. The static keyword belongs to the class than an
instance of the class. ... Variable (also known as a class variable)
hashCode() does not return the object's reference, but a hash of the
object, computed in some way. equals(obj2) is true then obj1.
hasCode() must be true to be a valid implementation.
Reason: hashCode just returns int value for an Object, even
two different objects can have same hashCode integer.