• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Either incorrect question Or answer of flashcards OCAJP 8 Sybex  RSS feed

 
Saloon Keeper
Posts: 1119
61
Eclipse IDE Hibernate jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As

10.2. Array Variables wrote:A variable of array type holds a reference to an object. Declaring a variable of array type does not create an array object or allocate any space for array components. It creates only the variable itself, which can contain a reference to an array.


Flashcards Set 2 --> Sequential --> Card No 21. 

I think either It should say how many arrays are declared then answer two would be correct Or It should change the answer from two to zero since arrays are not created.
Untitled.png
[Thumbnail for Untitled.png]
Untitled1.png
[Thumbnail for Untitled1.png]
 
Marshal
Posts: 60908
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I agree: no arrays are created. Also both arrays are one‑dimensional.
 
Ganesh Patekar
Saloon Keeper
Posts: 1119
61
Eclipse IDE Hibernate jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Also both arrays are one‑dimensional.

No, about dimensions It is correct.

JLS 9 10.2 wrote:The array type of a variable depends on the bracket pairs that may appear as part of the type at the beginning of a variable declaration, or as part of the declarator for the variable, or both. 


JLS 9  Example 10.2-2. wrote: The general rules for variable declaration, however, permit brackets to appear on both the type and in declarators, so that the local variable declaration statement:

is equivalent to the series of declarations:


The local variable declaration statement:
is equivalent to:

 
Campbell Ritchie
Marshal
Posts: 60908
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ganesh Patekar wrote:. . . No, about dimensions It is correct. . . .

No, it is incorrect; there is no such thing as a two‑dimensional array in Java®.
 
Ganesh Patekar
Saloon Keeper
Posts: 1119
61
Eclipse IDE Hibernate jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:there is no such thing as a two‑dimensional array in Java®.

Oh I see, I completely misunderstood you, I thought you missed the bracket next to type. Yes you are correct. Actually from implementation perspective (couldn't find a specific word for this) It is only one dimensional array. So It is an array of array .... sort of things.
For an example: I think most of the people (hope so) call them one dimensional Or two dimensional and so on, just for the sake of understanding.
Like It's easy to understand above declaration by calling It three dimensional array of short rather than calling It array of array of array of short since JVMS 9 also used these words like three dimensional array etc.

JVMS 9  3.9 Arrays wrote:For example, the three-dimensional array:

int[][][] create3DArray() {
    int grid[][][];
    grid = new int[10][5][];
    return grid;
}


And thank you for pointing out that


 
Campbell Ritchie
Marshal
Posts: 60908
190
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think array of arrays is the best way to describe the second array. The JLS section you quoted says that arrays can have other arrays as elements. You can also have arrays as members of themselves, but you need some strange code to achieve that:-Now the behaviour of all sorts of actions, including many methods of Arrays, becomes undefined
 
Ganesh Patekar
Saloon Keeper
Posts: 1119
61
Eclipse IDE Hibernate jQuery MySQL Database Spring Tomcat Server
 
Campbell Ritchie
Marshal
Posts: 60908
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not this? ()That is a new development: older editions of the JLS and JVMS did their best to avoid talking about dimensions of arrays. The Java6 edition of the JVMS doesn't show anything with ctrl‑F‑“dimension”. What does it say in the Java™ Tutorials?

the Java™ Tutorials wrote:You can also declare an array of arrays (also known as a multidimensional array) by using two or more sets of brackets, such as String[][] names. Each element, therefore, must be accessed by a corresponding number of index values.

In the Java programming language, a multidimensional array is an array whose components are themselves arrays. This is unlike arrays in C or Fortran. . . .

They used to be more definite that it was really an array of arrays. Also, does mention of Fortran belong in a tutorial?
 
Ganesh Patekar
Saloon Keeper
Posts: 1119
61
Eclipse IDE Hibernate jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Yes, this one is short and precise

That is a new development: older editions of the JLS and JVMS did their best to avoid talking about dimensions of arrays. The Java6 edition of the JVMS doesn't show anything with ctrl‑F‑“dimension”.


First time saw previous JVMS 6 pages, since 7 contents are really well structured and colored. I've checked JVMS 6, 7, 8 and 9 all of them have the same example only which mentions the three-dimensional array, will not find anywhere except here.

Campbell Ritchie wrote:They used to be more definite that it was really an array of arrays.


I think they have been. All JLS editions clearly states in the Introduction section: Chapter 10

JLS 9 1.1 wrote:The language supports arrays of arrays, rather than multidimensional arrays.




 
author & internet detective
Marshal
Posts: 38687
677
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've added this to the errata. The intent was if the reference had an array instantiated in the normal way next to it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!