Hierarchy for Package Javax.management

Source: Internet
Author: User
Tags shallow copy

Java.lang.Object
GetClass Public final class<?> getclass ()
Each class in Java comes with a runtime class object that holds all the information needed to create the object. You can use. class to return the runtime class object of this object, or it can be obtained using getclass (). You can take advantage of this class object to do some reflection characteristics.
hashcode public int hashcode ()
Hashcode is the value of the JDK based on the address of an object or a string or a number, which is supported to improve the performance of a hash table, such as a hash table provided by the java.util.Hashtable.
During Java application execution, when the Hashcode method is called multiple times on the same object, the same integer must be returned consistently, provided that the information used to make the object hashcode compared has not been modified.
If two objects are equal according to the Equals (object) method, calling the Hashcode method on each object in both objects must produce the same integer result, note: Equals (Object). Method refers to the Equals method in the object class that is not overridden by the quilt class.
If two hashcode () return equal results, the Equals method of two objects is not necessarily equal.
If two objects are not equal according to the Equals (Java.lang.Object) method, calling the Hashcode method on any of these two objects does not necessarily produce a different integer result. However, programmers should be aware that generating different integer results for unequal objects can improve the performance of the hash table.
Equals public boolean equals (Object obj)
The comparison with NULL should return FALSE, NULL does not have the Equals method
Clone protected Object Clone () throws Clonenotsupportedexception
X.clone ()! = X is True, X.clone (). GetClass () = = X.getclass () is true X.clone (). Equals (x) is True
It's not a hard call.
The object itself hides the Clone method, and we need to implement it in our own class and call Super.clone ().
All arrays have implemented the Cloneable interface.
The class object does not itself implement the interface cloneable, so calling the Clone method on an Object whose class I s Object would result in throwing a exception at run time.
Note that all arrays is considered to implement the interface cloneable and that the return type of the Clone method of a n array type t[] is t[] where T is any reference or primitive type. Otherwise, this method creates a new instance of the class of this object and initializes all it fields with exactly the Contents of the corresponding fields of this object, as if by assignment; The contents of the fields is not themselves cloned. Thus, this method performs a "shallow copy" of the "of this object" and not a "deep copy" operation.
For primitive type, this replication is possible, and for non-primitive type, this replication is not feasible.

1 classA {2      PublicAinta) {3          This. A =A;4     }5      Public intA;6      Public voidAdd () {7A + = 5;8     }9 }Ten classBImplementscloneable { One      Public intb; A      PublicA ba =NewA (5); -      PublicObject Clone () { -B newb =NULL; the         Try { -Newb = (B)Super. Clone (); -}Catch(clonenotsupportedexception e) { - e.printstacktrace (); +         } -         returnnewb; +     } A } at classC { -      Public Static voidMain (string[] args) { -B FirB =NewB (); -firb.b = 5; -          -System.out.println ("Before Clone" +firb.b); inSystem.out.println ("Before Clone" +firb.ba.a); -          toB SECB =(B) Firb.clone (); +secb.b = 7; - SecB.ba.add (); theSystem.out.println ("After Clone FirB" +firb.b); *System.out.println ("After Clone FirB" +firb.ba.a); $System.out.println ("After Clone SECB" +secb.b);Panax NotoginsengSystem.out.println ("After Clone SECB" +secb.ba.a); -     } the}

The results are as follows:

You can modify the method above

classAImplementscloneable{ PublicAinta) { This. A =A; }     Public intA;  Public voidAdd () {a+ = 5; }     PublicObject Clone () {A Newa=NULL; Try{Newa= (A)Super. Clone (); } Catch(clonenotsupportedexception e) {e.printstacktrace (); }        returnNewa; }}classBImplementscloneable { Public intb;  PublicA ba =NewA (5);  PublicObject Clone () {B newb=NULL; Try{newb= (B)Super. Clone (); Newb.ba=(A) Ba.clone (); } Catch(clonenotsupportedexception e) {e.printstacktrace (); }        returnnewb; }}classC { Public Static voidMain (string[] args) {B FirB=NewB (); Firb.b= 5; System.out.println ("Before Clone" +firb.b); System.out.println ("Before Clone" +firb.ba.a); B SECB=(B) Firb.clone (); Secb.b= 7;        SecB.ba.add (); System.out.println ("After Clone FirB" +firb.b); System.out.println ("After Clone FirB" +firb.ba.a); System.out.println ("After Clone SECB" +secb.b); System.out.println ("After Clone SECB" +secb.ba.a); }}

reference:1727125#_toc174096679

ToString publicstring ToString ()
Return GetClass (). GetName () + ' @ ' + integer.tohexstring (hashcode ())


First we need to review the Java synchronized mechanism, each object has a listener (monitor), each Synchronizad () block of code in parentheses is an object, When a thread tries to get into the Synchronizad code block, it tries to obtain the monitor of the object, and the other thread under the same monitor will have to wait for this thread to release the monitor when it wants to enter the Synchronizad code block, of course, A thread will automatically release monitor when it finishes executing the SYNCHRONIZAD code block.

reference:http://blog.51cto.com/2925665/1324501

1. You can use the wait and notify functions to implement inter-thread communication. You can use them to achieve communication between multiple threads (>3).

2. Wait, notify, and Notifyall are always used in synchronized functions or objects, otherwise Java virtual opportunities generate illegalmonitorstateexception.

3. Always use wait in the while loop instead of the IF statement. In this way, the loop checks for wait conditions before and after the thread sleep, and processes the wake-up notification if the condition does not actually change.

4. Always use wait on objects that are shared between multiple threads (in the producer consumer model, the buffer queue).

Reference:http://www.importnew.com/16453.html

Notify ()

Throws: IllegalMonitorStateException -If the current thread isn't the owner of this object ' s monitor.

Notifyall ()
Throws: IllegalMonitorStateException -If the current thread isn't the owner of this object ' s monitor.
Wait ()

Public final void Wait (long timeout) throws Interruptedexception





Hierarchy for Package Javax.management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.