[HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Username987654
Posts: 95
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

[HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by Username987654 »

Pg 131, Sec. 4.3.1 Multidimensional Arrays
2. int[][] iaa = new int[3][];
should be
2. int[][] iaa = new int[2][];
as illustrated in following paragraph where
Example 1 has [2][3], while here, it is [2][].

Online
admin
Site Admin
Posts: 10034
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by admin »

You are right. Added to errata.
Thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Username987654
Posts: 95
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by Username987654 »

Thanks for listening. (Looking at it again, you likely noticed that that specific change alone will not be enough since it "sets the table" for the following paragraphs.)

Online
admin
Site Admin
Posts: 10034
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by admin »

Didn't notice it earlier :oops:
I think that statement is ok. The text needs to change to "Example 1 has [2][3], while here, it is [3][]".
If you like our products and services, please help us by posting your review here.

Username987654
Posts: 95
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by Username987654 »

In that case, as I previously alluded,
[2] implies
that you want to store two references. In other of words, the length of your array
(which is of type array of ints) is 2.
should be
[3] implies
that you want to store three references. In other of words, the length of your array
(which is of type array of ints) is 3.
?

Online
admin
Site Admin
Posts: 10034
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by admin »

Correct. In addition, explanation to why int[][2] isn't valid has also been updated.
If you like our products and services, please help us by posting your review here.

Username987654
Posts: 95
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by Username987654 »

explanation to why int[][2] isn't valid has also been updated.
I think the 3rd create should be care? (I really like this explanation. This helps me tremendously compared to the previous explanation.)

Username987654
Posts: 95
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by Username987654 »

ia should be iaa starting with paragraph "In this figure" throughout the paragraph "But in case of an array of array of ints". (I just now was able to figure out why I was not understanding this text as written.)

Online
admin
Site Admin
Posts: 10034
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by admin »

Username987654 wrote:
Sun Dec 02, 2018 10:52 pm
explanation to why int[][2] isn't valid has also been updated.
I think the 3rd create should be care? (I really like this explanation. This helps me tremendously compared to the previous explanation.)
Sorry, I did not understand what you mean by this? Could you please elaborate a bit?
If you like our products and services, please help us by posting your review here.

Online
admin
Site Admin
Posts: 10034
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by admin »

Username987654 wrote:
Sun Dec 02, 2018 11:14 pm
ia should be iaa starting with paragraph "In this figure" throughout the paragraph "But in case of an array of array of ints". (I just now was able to figure out why I was not understanding this text as written.)
Correct. Should be fixed.
If you like our products and services, please help us by posting your review here.

Username987654
Posts: 95
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by Username987654 »

admin wrote:
Sun Dec 02, 2018 11:37 pm
Username987654 wrote:
Sun Dec 02, 2018 10:52 pm
explanation to why int[][2] isn't valid has also been updated.
I think the 3rd create should be care? (I really like this explanation. This helps me tremendously compared to the previous explanation.)
Sorry, I did not understand what you mean by this? Could you please elaborate a bit?
You cannot, however, leave out the size of a higher dimension if you want to specify the size of a lower dimension. For example, you cannot do new int[][2]; The reason is simple - new int[][2] tries to create an array of int[2] objects. But it it does not tell the JVM how many int[2] objects you want to store. Without this information, the JVM has no idea how much space it needs to allocate for this array. On the other hand, new int[2][] is fine because now, you are telling the JVM that you want to create an array of length 2. In this case, the JVM is clear that it needs to allocate space to store 2 references. Remember that the size of a reference doesn't depend on the length of the array to which it points. So, the JVM doesn't create about the length of the arrays to which these two references will refer. It simply allocates space to store 2 references.
should likely be
You cannot, however, leave out the size of a higher dimension if you want to specify the size of a lower dimension. For example, you cannot do new int[][2]; The reason is simple - new int[][2] tries to create an array of int[2] objects. But it it does not tell the JVM how many int[2] objects you want to store. Without this information, the JVM has no idea how much space it needs to allocate for this array. On the other hand, new int[2][] is fine because now, you are telling the JVM that you want to create an array of length 2. In this case, the JVM is clear that it needs to allocate space to store 2 references. Remember that the size of a reference doesn't depend on the length of the array to which it points. So, the JVM doesn't care about the length of the arrays to which these two references will refer. It simply allocates space to store 2 references.
?

Online
admin
Site Admin
Posts: 10034
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by admin »

Oh yes. I'm going blind as a bat.
If you like our products and services, please help us by posting your review here.

Username987654
Posts: 95
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by Username987654 »

iaa[0] = new int[2]; //ia[0] points to an array of ints of length 2
iaa[1] = new int[3]; //ia[1] points to an array of ints of length 3
ia should be iaa?

Online
admin
Site Admin
Posts: 10034
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by admin »

Yes, added to errata.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Username987654
Posts: 95
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by Username987654 »

In both the cases, iaa refers to an array of length 1.
should be
In both the cases, iaa refers to an array of array of ints. The length of the array is 1.
?

Online
admin
Site Admin
Posts: 10034
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by admin »

No, it is fine because the point that it is trying to make is that iaa refers to an array of length one. It is true that the element of that array itself is an array but that is not relevant in this sentence. It is made clear in the next sentence, "The first and only element in this array refers to an array of ints of length 2."
If you like our products and services, please help us by posting your review here.

Username987654
Posts: 95
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by Username987654 »

admin wrote:
Fri Nov 22, 2019 9:51 am
No, it is fine because the point that it is trying to make is that iaa refers to an array of length one. It is true that the element of that array itself is an array but that is not relevant in this sentence. It is made clear in the next sentence, "The first and only element in this array refers to an array of ints of length 2."
I thought that was the intent. I (wrongfully?) separated those sentences: As a point of clarification, is it consistently stated with other parts of the text? If not, could it be a source of confusion to some readers? Number 4, immediately under it, mentions Object[] obj[] as "an array of array of objects". The last lines in Section 4.3.2 go into specific detail here as well. In other words, iaa[0] is the real single dimensional array that refers to a single dimensional array of length two. A single dimensional array of ints cannot contain an array. Correct?

I say all of that to the text's point, especially when dealing with multi-dimensional arrays,
You need to be very clear about this concept because it gets confusing very quickly

Online
admin
Site Admin
Posts: 10034
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by admin »

You might have overlooked the first paragraph of this section that deals with multi-dimensional arrays, which makes it clear :
The phrase multidimensional array brings a picture of a matrix to mind. But it is important to understand that Java doesn’t have matrix kind of multidimensional arrays. What Java has is arrays whose elements themselves can be arrays. Recall that, in Java, every array object is an object of a
specific class. For example, the class of an array of ints is [I. Now, what if you want to have an array of objects of this class. In other words, an array of “array of ints”. You can declare it like this:
int[][] iaa;
So, yes, it is consistently stated that a multi dimensional array in Java is actually just an array of arrays. In other words, an "array of arrays" is an array!

The discussion in the paragraph that you are referring to is about the length of an array. The fact that something is an array of arrays is immaterial to determine its length.
iaa[0] is the real single dimensional array that refers to a single dimensional array of length two
There is nothing like real or fake single dimensional array. Actually, if it helps your understanding, you can safely say that Java doesn't have the concept of single or multi dimensional arrays. Java has, just, arrays. If the elements of an array are themselves arrays, then we call them multi-dimensional arrays from human perspective. From the language perspective, it is just an array like any other array.

The syntax int[][] is not for declaring a multi-dimensional array of ints (although we commonly call it that way). It is for declaring an array of "array of ints".
If you like our products and services, please help us by posting your review here.

Username987654
Posts: 95
Joined: Sat Dec 26, 2015 6:37 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by Username987654 »

With the help of this fantastic text, I completely understand. My only intention was to attempt to offer a very humble suggestion of consistency of terminology, even when discussing the length of an array, in an effort to possibly help even more readers follow along more easily. Also, at first read, I honestly thought that maybe it was a typo. You are absolutely right: clarity was indeed a word that I should not have used. Your response points to intention of terminology. Thank you for your detailed feedback!

Online
admin
Site Admin
Posts: 10034
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 130, Sec. 4.3.1 - multidimensional-arrays]

Post by admin »

May be this additional insight should be added to the text.
thanks for the discussion.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests