Java Interview Guide: How to Build Confidence With a Solid Understanding of Core Java Principles pdfdrive com



Yüklə 0,53 Mb.
Pdf görüntüsü
səhifə9/47
tarix06.05.2023
ölçüsü0,53 Mb.
#108601
1   ...   5   6   7   8   9   10   11   12   ...   47
Java Interview Guide

HashCode
The hashCode() method digests the state of an object into an integer, which is
primarily useful for hash table data structures. By default, the hash code
is implemented by converting the internal address of an object into an integer.
The hash code must be consistently returned and should always return equal
values for objects that are equal according to the equals() method.


ToString
The toString() method returns a textual representation of an object, which is
primarily useful for logging and debugging. By default, the toString()
method returns the class of the object followed by a hexadecimal representation
of its hash code value.


GetClass
The getClass() method returns a Class object that contains information
about a class and utility methods for reflection-based access to fields and
methods. The getClass() method is final and cannot be overridden
by subclasses.


Finalize
The finalize() method was originally designed to be invoked before
an object was destroyed by the garbage collector. However, an object might not
become eligible for garbage collection if it’s never dereferenced or if the
application exits before the garbage collector runs. It’s generally discouraged
to rely on this method for cleanup operations due to its uncertainty and the
possibility that an object can be unintentionally revived by creating additional
references to it.


Wait, Notify, NotifyAll
The final methods wait(), notify(), and notifyAll() provide low-
level concurrency operations that allow communication between threads.
For example, one thread could halt its execution until it receives a notification
from another thread. Java provides high-level concurrent data structures in the
java.util.concurrent
package.


Questions
What is the difference between a shallow copy and a deep copy?
Why is a copy constructor preferable to the clone method?
What is the difference between the identity operator and the equals() method?
What is the relationship between the hashCode() method and the
equals() method?
What is the default implementation of the toString() method?
Why is the finalize() method unreliable for cleanup operations?



Yüklə 0,53 Mb.

Dostları ilə paylaş:
1   ...   5   6   7   8   9   10   11   12   ...   47




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin