Arrays are supported in almost all programming languages. Using arrays in C and C + + is very dangerous because those arrays are just blocks of memory. If a program accesses an array other than its own memory block, or uses memory (which is a general programming error) before initialization, it can have unpredictable consequences (note ②).
②: in C + +, try not to use arrays, swapping the more secure containers in the Standard Template Library (Standard templatelibrary).
One of the main design goals of Java is security. So many of the problems that plague programmers in C and C + + are not repeated in Java. A Java can be guaranteed to be initialized and cannot be accessed outside its scope. Because the system automatically checks the scope, there must be a cost: For each array, as well as the checksum of the index during run time, a small amount of memory overhead will be incurred. But the result is higher security and higher productivity. It is worthwhile to pay a little price for it.
When you create an array of objects, you actually create an array of handles. And each handle is automatically initialized to a special value with its own keyword: null (NULL). Once Java sees NULL, it knows that the handle does not point to an object. You must assign an object to each handle before you can use it formally. If you try to use a handle that is still null, you will report the problem at run time. As a result, typical array errors are avoided in Java.
You can also create an array of main types. Similarly, the compiler can guarantee initialization of it, because the memory of that array is divided into 0.
The array question will be discussed in more detail in a later section.