Package test; public class systemdemo {public static void main (string [] ARGs) {string [] S = new string [] {"Liu "}; string [] S2 = new string [] {"Hai"}; string [] [] A = {s, S2, S, S2, S2, s }; string [] [] B = new string [10] [10];/** the system class contains some useful class fields and methods. It is a final class and cannot be inherited, the constructor is private and cannot create a system object. * All public attributes and methods are final static * // 1. array replication adopts local replication to achieve deep copy of system. arraycopy (A, 1, B, 0, 5); system. out. println (B [0] [0]); // 2. the number of millimeters that have passed, starting from-1. currenttimemillis (); // 3. prompts the virtual machine to recycle garbage by calling runtime. getruntime (). GC (); Implement system. GC (); // 4. system. getenv (); // 5. returns the current system property. System. getproperties (); // 6. it can be used to calculate the amount of time in the past system. nanotime (); // 7.0 indicates that the instance Exits normally, and the slave instance uses runtime. getruntime (). exit (0); system. exit (0); // 8. returns the hash code of the given object. The Code is the same as the Code returned by the default method hashcode (), regardless of whether the class of the given object overwrites hashcode (). System. identityhashcode (null );}}
Package test; public class objectdemo {/** 1. The object does not have public static attributes and Methods * 2. Public final native class <?> Getclass () returns the runtime class information, * 3. tostring returned class name + @ + hash code value * 4. the wait and notify methods are final and cannot be inherited * 5. the equals method only compares object references. The hashcode method returns the hash code value. * 6. Override the hashcode of the equals method, because the same object (returns true through equals comparison) * must return the same hash code. * 7. The Finalize method is a protected empty Method * 8. protected native object clone () returns a copy, and the object must implement the cloneable interface */}
Package test; import Java. util. arrays; public class arraysdemo {/** 1. the array class provides the sorting function. For the basic data type length <7, the sort is directly inserted. Otherwise, the sort is fast. If the object is in the array element, the sort is merged. * 2. provides the binary search method. When binary search is performed, the array is sorted first. Otherwise, an uncertain value */public static void main (string [] ARGs) is returned) {int [] [] A ={{ 1, 2 }}; int [] [] B ={{ 1, 2 }}; system. out. println (arrays. tostring (a); // 3. the tostringsystem of the multi-dimensional array. out. println (arrays. deeptostring (a); system. out. println (arrays. hashcode (a); system. out. println (arrays. deephashcode (a); system. out. println (arrays. equals (A, B); // 4. multi-dimensional array comparison system. out. println (arrays. deepequals (A, B); // 5. no multi-dimensional array replication int [] [] C = arrays. copyof (A, 1); // 6. fill in the array arrays. fill (A [0], 5); // changing the value of a affects the value of array C system. out. println (arrays. deeptostring (c); system. out. println (arrays. equals (a, c); system. out. println (arrays. deepequals (a, c ));}}
Package test; public class deepclonedemo {public static void main (string [] ARGs) {B = new B (2, new A (1); B b1 = (B) b. clone (); system. out. println (B = b1); system. out. println (B. equals (B1); system. out. println (B. getclass () = B. getclass (); system. out. println ("before changing B's copy B1: Y =" + B. gety () + ", x =" + B. geta (). getx (); b1.sety (5); b1.geta (). setx (100); system. out. println ("Change B's copy B1: Y =" + B. gety () + ", x =" + B. geta (). Getx (); system. Out. println ("Deep clone successful !!! ") ;}} Class A implements cloneable {private int X; // to achieve deep cloning of public object clone () {A = NULL; try {A = (a) super. clone ();} catch (clonenotsupportedexception e) {e. printstacktrace ();} return a;} public a (int x) {This. X = x;} public int getx () {return X;} public void setx (int x) {This. X = x ;}} Class B implements cloneable {private int y; private A; // overwrite the clone method in the object // protected native object clone () throws clonenotsupportedexception; // note protected. Change the permission to publicpublic object clone () {B = NULL; try {B = (B) super. clone (); // implements deep cloning. Without this statement, only references B of A are cloned. A = (a). clone ();} catch (clonenotsupportedexception e) {e. printstacktrace ();} return B;} public B (INT Y, a A) {This. y = y; this. A = A;} public int Gety () {return y;} public a geta () {return a;} public void sety (INT y) {This. y = y;} public void Seta (A) {This. A = ;}}