Array's initialization Array is actually a set of objects or a set of basic data types of data, and the data in each Array must be the same type, and in one indicator is packaged, for example, int [] i; or int i []; Now you declare an array, but the Array is actually a set of handles, not specific data objects, you must write the initialization statement to make Array make meaning, initialization, and 2 inti [] = New INT [3]; or INT i [] = {1, 2, 3}; it is necessary to note that the second initialization method can only occur when Array is generated. Java allows you to assign an Array to another Array, and if you pass, it is just a handle, let's see an example.
Public class arrays {public static void main (string args []) {int [] i = {1, 2, 3}; // declare an array, and initialize int [] II; // only declare an array II = i The // // handle does not pass the value within the array, in other words, the handle of II and I is always pointing to the same memory address for (int J = 0; j } We discovered that the value of i changed with the change of II, this phenomenon we have already said it when assigning the arithmetic. We need to know that any array has a feature. Through him, you can know the number of elements in Array, that is, because Java starts retrieving arrays from 0, that is, the maximum index value of the array is Length. -1. If your index value is greater than / less than the actual accommodation element value, it will get an array crimfer exception to the execution period of the program, because Java will border check the array, so ARRAY is not very high. If you don't know what you need to accommodate how many elements, you need such an Array, you can use new way to generate Public class arrays {public static void main (string args []) {INT i [] = new int [3]; for (int J = 0; j The basic type of Array will automatically initialize 0 (the same as the initialization value of the member data of the basic data type), but if you generate an object array, you must specify the initialization value. Public class arrays {public static void Go (Object [] O) // You can accept array {for (INT i = 0; i Public class arrays {public static void main (string args []) {system.out.println ("this is mulitdimentsional arrays demo one"); int [] [] II = {{1, 2, 3}, {2, 3, 4}}; for (int i = 0; I Class test {protected () {system.out.println ("Finalize () running ...");} public static void main (String args []) {new test (); // Note Why is new test (), not written as test t = new test (); reason is to write more easily to pay attention to the garbage collector's attention system.gc ();}} Using system.gc (); may make you Finalize () calls, remember that we just say possible, system.gc (); just a request, but as for execution, it is not known. Everyone must remember that whether garbage recovery is still ending, it is not necessarily guaranteed, if JVM does not face resources tight, then he will not perform the cleaning action to save system spending Basically, There's no Way To EnSure That Finalize () WILL BE CALLED. 13. Write a class named TANK, this class is full or empty, his death conditions are, the object must be empty when cleaning, please write Finalize () function to determine if the death conditions are established, and several possible conditions detected in Main Class Tank {static int counter = 0; int id = counter ; boolean full = false; public tank () {system.out.println ("tank" ID "created"); fullic void Empty ) {Full = false;} protected void finalize () {if (full) system.out.println ("Error: Tank" ID "Must Be Empty At Cleanup"); Else System.Out.println ("Tank" ID "cleaned up ok");}}} class tanktest {public static void main (string args []) {new tank (); new tank (). EMPTY (); system.gc ();}} 16, Write a class, including 2 String data, one initialized in the constructor, one initialized at the definition, what is the difference between this 2 China France Class test {string S1 = "Hello!"; String S2; public test (string s) {s2 = s;} public static void main (string args []) {test t = new test ("Goodbye"); system. Out.println (T.S1); // static function can only call Static's data and functions, but the object. In addition to system.out.println (t.s2);}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} The function call is completed before, while S2 is also initialized, but he is initialized into NULL, and then S2 can vary depending on the value of the value transmitted to the constructor, more flexibility. 18. Write a class, there is a String data, use the entity to initialize the way, and speak different purposes with this book. Class test {string s; {s = "hello!"; // Notice not to write String S = "Hello", otherwise it will become a local variable! System.out.println ("Instance Before Constructor");} Test () {system.out.println (S "from test ()");} public static void main (string args []) {test t = new test ();}} The use of the book is that this usage must be used in anonymous internal classes (now there is still not learned), because constructor needs to have a function name, but anonymous internal classes are no name So we need to use this method to initialize the data! Let's use it again: In the general class, the physical initialization method is called before the constructor call, then in this case, this program will first display the Instance Before Constructor and then display Hello! From test (), enough to explain the problem. 20. Write a function, can generate a three-dimensional array and initialize, the capacity of the array is determined by the number of functions, and the initial value of Array must be within the range specified by the function factor, and then write a function. An array of different capacities is required in the main function Class Test {// Accept the quotient function, x, y, z represent the elements in the array, D1, D2 represent the range of array, and the function can return a array public static double [] [] CreateArray (INT X) , int y, int z, double d1, double d2) {double [] [] [] DARRAY = new double [x] [y] [z]; // Define an array, not initialization Double Incr = (D1-D2 ) / (x * y * z); // calculate the increment of each array value, because the value of our array is in the range of D1-D2 Double Value = D2; // A value of each element in the array, and Let him initial value equal to the minimum value of the transfer quotes for (INT i = 0; i