In Java, array is a class and extends Object. I am curious to know about this special array class. I don’t find the class definition anywhere. Doing a getClass().getName() gives strange result.
String[] array = new String[]{"one","two"};
System.out.println(array.getClass().getName()); // prints [Ljava.lang.String;
I want to understand how array works under the hood. Is the array class definition hardcoded in the JVM?
Any resources, books, links on this will be helpful.
Thank you.
Yes, basically arrays are something the VM knows about intimately, like the primitive types. There are specific bytecode instructions to work with arrays – creating them, indexing into them etc.
As for resources to find out more – the JVM specification is probably the best starting point. Section 7.9 has some examples of bytecode working with arrays.