I think you misunderstood what the author said. Note:
This is a static array in Java:
String[] suit = { "item 1", "item 2", "item 3", "item 4" };
Now Java does not allow you to declare real dynamic arrays, such as Delphi and other languages, for dynamic, we must choose another data structure called ArrayList , like this example:
List<String> list = new ArrayList<String>();
If the user wants to use a static array with a specific execution length, in the most flexible way he can do the following:
int maxsize = Integer.ParseInt(JOP.ShowInputDialog("give me a number")...); int[] myArray = new int[maxsize]();
This is a static array in Delphi:
const MyStaticArray : array [0..3] of Integer = (0, 1, 2, 3);
And this is a dynamic array
var MyDinamicArray : array of Integer; MaxSize: Integer; begin MaxSize := StrToInt(InputBox(..,'Give me a number', ..)); SetLength(MyDinamicArray, MaxSize); //Defines the array size, in runtime; end;
My question is how in any language it can be compiled during array or variable initialization, if the user is going to supply it only at runtime, and memory allocation for variables occurs at runtime. Without knowing the memory address, how can an array be initialized?
However, we can easily see that THIS is the initialization of the "compilation time" (it does not matter, the fact of implementation details)
String[] suit = { "item 1", "item 2", "item 3", "item 4" };
After the array is initialized, the size CANNOT BE ; therefore, the OS can allocate memory where it wants. And since arrays are sequential in memory using indexes, Java knows what address you want to get.
Given the array above, this is a memory sketch:
// Program memory
address 00A1 value | 00BA | alias suit
// OS memory
address 00BA 00BB 00BC 00BD value | "item 1" | "item 2" | "item 3" | "item 4" | alias suit[0] suit[1] suit[2] suit[3]
The string is here to make it understandable; in fact, String is also a pointer to something.
Alias โโis how Java hides pointer arithmetic, that is, it allows us to access indexes instead of memory addresses.
Here are some docs about arrays:
Read Static Arrays and see List of Arrays