In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "there are several methods of Object class". In daily operation, I believe that many people have doubts about several methods of Object class. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "Object class has several methods". Next, please follow the editor to study!
Interview questions
How many methods are there for Object?
Java is a single inheritance structure language, and all classes in Java share a common ancestor. This ancestor is the Object class.
If a class does not explicitly indicate that it inherits from a class with extends, it inherits the Object class by default.
We basically use the Object method at ordinary times, but if we are not prepared to be asked suddenly, we are still a little confused.
Analysis.
The Object class is the base class for all classes in Java. There are 13 methods in the java.lang package. As shown in the following figure: specific answer
There is nothing to say about 1.Object (), the constructor of the Object class. (unfocused)
2.registerNatives () they are named in a certain way in order for JVM to discover native functionality. For example, for java.lang.Object.registerNatives, the corresponding C function is named Java_java_lang_Object_registerNatives.
By using registerNatives (or rather, the JNI function RegisterNatives), you can name any C function you want. (unfocused)
The purpose of the 3.clone () clone () function is to save a currently existing object. This method can be called only if the Cloneable interface is implemented, otherwise a CloneNotSupportedException exception is thrown. (note: answering questions here may lead to design patterns.)
The 4.getClass () final method, which is used to get the type of the runtime. This method returns the class object / runtime class object Class of this Object object. The effect is the same as Object.class. (note: answering here may lead to questions about class loading, reflection and other knowledge points.)
5.equals () equals is used to compare whether the contents of two objects are equal. By default (inherited from the Object class), equals and = = are the same unless overridden (override). (note: this may lead to the more frequently asked questions about "the difference between equals and =" and the principle of hashmap implementation)
6.hashCode () this method is used to return the physical address (hash code value) of the object it belongs to, and is often overridden at the same time as the equals method to ensure that two equal objects have equal hashCode. (again, it may lead to questions about the principle of hashmap implementation.)
The 7.toString () toString () method returns a string representation of the object, which has nothing to say.
8.wait () causes the current thread to wait until another thread calls the object's notify () method or notifyAll () method. (leads to the question of thread communication and "the difference between wait and sleep")
9.wait (long timeout) causes the current thread to wait until another thread calls the object's notify () method or notifyAll () method, or exceeds a specified amount of time. (leads to the question of thread communication and "the difference between wait and sleep")
10.wait (long timeout, int nanos) causes the current thread to wait until another thread calls the object's notify () method or notifyAll () method, or some other thread interrupts the current thread, or an actual amount of time has been exceeded. (leads to the question of thread communication and "the difference between wait and sleep")
11.notify () wakes up a single thread waiting on this object monitor. (leads to the question of thread communication)
12.notifyAll () wakes up all threads waiting on this object monitor. (leads to the question of thread communication)
13.finalize () this method is called by the object's garbage collector when the garbage collector determines that no more references to the object exist. (beside the point, but be careful to raise questions about garbage collection)
Extend frequently asked questions
What is the difference between equals () and = =?
What is the connection between hashCode () and equals ()?
The difference between wait () method and sleep () method
Why do you have to rewrite equals if you rewrite hashCode?
The realization principle of HashMap
Talking about the Mechanism of Class loading
At this point, the study of "there are several methods for the Object class" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.