My Thinking in Java Learning Notes (8)

xiaoxiao2021-03-06  92

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. In fact, it is actually 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; // just declare an array II = i; // The passage of the handle, does not pass the value in the array, that is, II and i's handle is always pointing to the same memory address for (int J = 0; j

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 whether the death conditions are established, and detect several possible cases of possible Class Tank {static int counter = 0; int ID = counter ; boolean ful = false; public tank () {system. Out.println ("Tank" ID "created"); full = true;} public void Empty () {full = false;} protected void finalize () {if (full) system.out.println ("Error: " ID " Must Be Empty At Cleanup "; Else System.Out.println (" Tank " ID " Clealed Up OK ");}} Class TankTest {Public Static Void Main (String Args [] { New tank (); new tank (). EMPTY (); system.gc ();}} 16, write a class, 2 String data, one initialization in the constructor, one initialized at the definition, what is the difference between the 2 Chinese method Class Test {String S1 = "Hello!"; String s2; public test (String S2; Public Test 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 and function data, the object data except the embodiment System.out.println (t.s2);.}} s1 is initializing operation before complete the constructor call ~, s2 and at the same time is also initialized, but He was initialized into null,

Since then S2 can vary depending on the change in the value of the configuration function, more flexibility. 18. Write a class, there is a String data, using the entity initialization method, and tells the use of different uses of the book Class test {string S; {s = "hello!"; // Don't 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.

In the main function, you need to generate a function of the array class test {// accept the quotes, X, Y, and Z represent the range of the array, D1, D2 represent the range of the array, and the function can return a array public static. DoubleRray (int X, int y, int z, double d1, double d2) {double [] [] [] DARRAY = new double [x] [y] [z]; // Define one Array, Double Incr = (D1-D2) / (x * Y * z) is not initialized; // calculate the increment of each array value, because the value of our array is in the range of D1-D2 Double Value = D2; // Value of each element in the array, and let him initial value equal to the minimum value for the transfer quotes for (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-122222.html

New Post(0)