Things I learned by reading this post * Java arrays can have 0 dimensions * When declaring arrays, trailing comma is allowed after the last element * In multi-dimensional arrays, only the last dimension contains actual values. Other dimensions are just pointers to arrays. Good read.
Inside the JVM: Arrays and how they differ from other objects
11–20 of 133 posts
Re: Inside the JVM: Arrays and how they differ from other objects
#12What are the advantages of representing multidimensional arrays with pointers to arrays instead of a "flat" version where everything is stored contiguously and access is simply pointer arithmetic? EDIT: For the JVM, not manually. I'm asking about the internal representation, not a manual flattening by the user.
Maintenance, probably. Puting data in a structure that mirrors the real thing normally helps when trying to understand it
Re: Inside the JVM: Arrays and how they differ from other objects
#13> (Note that the comma after the last value is accepted in Java and won’t cause an error.) Why have I been 15 years programming in Java and I discovered this today? On a more serious note, I prefer this kinds of posts to the traditional "Look at this shiny new thing" because without fundamental stuff the next big thing can't be built and normally this information makes you a slightly better programmer.
Re: Inside the JVM: Arrays and how they differ from other objects
#14Things I learned by reading this post * Java arrays can have 0 dimensions * When declaring arrays, trailing comma is allowed after the last element * In multi-dimensional arrays, only the last dimension contains actual values. Other dimensions are just pointers to arrays. Good read.
The way you've phrased it is a bit ambiguous.
Having 0 dimension sounds like
x = new int[7][5]; // 2 dimensions
y = new int[9]; // 1 dimension
z = new int; // no dimensions, not an array, not allowed
The phrasing you mean is "dimensions can have zero size".Re: Inside the JVM: Arrays and how they differ from other objects
#15What are the advantages of representing multidimensional arrays with pointers to arrays instead of a "flat" version where everything is stored contiguously and access is simply pointer arithmetic? EDIT: For the JVM, not manually. I'm asking about the internal representation, not a manual flattening by the user.
int[][] x = new int[2][];
x[0] = new int[] { 1, 2, 3 };
x[1] = new int[] { 1, 2, 3, 4 };Re: Inside the JVM: Arrays and how they differ from other objects
#16> (Note that the comma after the last value is accepted in Java and won’t cause an error.) Why have I been 15 years programming in Java and I discovered this today? On a more serious note, I prefer this kinds of posts to the traditional "Look at this shiny new thing" because without fundamental stuff the next big thing can't be built and normally this information makes you a slightly better programmer.
I believe that comma thing was added recently.
"A trailing comma may appear after the last expression in an array initializer and is ignored"
https://titanium.cs.berkeley.edu/doc/java-langspec-1.0/10.do...
Re: Inside the JVM: Arrays and how they differ from other objects
#17Things I learned by reading this post * Java arrays can have 0 dimensions * When declaring arrays, trailing comma is allowed after the last element * In multi-dimensional arrays, only the last dimension contains actual values. Other dimensions are just pointers to arrays. Good read.
> Java arrays can have 0 dimensions The way you've phrased it is a bit ambiguous. Having 0 dimension sounds like x = new int[7][5]; // 2 dimensions y = new int[9]; // 1 dimension z = new int; // no dimensions, not an array, not allowed The phrasing you mean is "dimensions can have zero size".
Re: Inside the JVM: Arrays and how they differ from other objects
#18I was pretty disappointed that, for a blog called "Inside the JVM", very little in the blog entry discussed goings on inside the JVM. For example, when does the JVM typically optimize away bounds or null checks? How are arrays of booleans packed and what is their efficiency compared to arrays of bytes or words?
Otherwise is like trying to discuss what does a C compiler do, when only looking through the lens of the C abstract machine in ISO C.
Re: Inside the JVM: Arrays and how they differ from other objects
#19In my experience, just a little bit of insider knowledge goes a long ways to making better code. Arrays are fun things, especially when you do a deep dive into the System.arraycopy() function. But the same goes for all Collections in Java. For instance, most of them have a default size (mostly 10), and growing them is a costly operation. So knowing beforehand how large your collection can or may be, can benefit code.…
For better or worse, it shows me that the author isn't that into Java.
Re: Inside the JVM: Arrays and how they differ from other objects
#20What are the advantages of representing multidimensional arrays with pointers to arrays instead of a "flat" version where everything is stored contiguously and access is simply pointer arithmetic? EDIT: For the JVM, not manually. I'm asking about the internal representation, not a manual flattening by the user.
Sometimes that can be useful, and sometimes not.