• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Either incorrect question Or answer of flashcards OCAJP 8 Sybex

 
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79703
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I agree: no arrays are created. Also both arrays are one‑dimensional.
 
Ganesh Patekar
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79703
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79703
381
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I think so ...
 
Campbell Ritchie
Marshal
Posts: 79703
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic