This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Hi Raams: As you probably gathered from the other responses, the term "pointer" is a bit ambiguous. Both a "reference" and a "pointer" point to something, but reference values are basically hidden from you, whereas pointers can be manipulated. For example, you might do arithmetic on a pointer to change its value, and therefore, point to a different location. In languages with references you can't really get at, and can't manipulate the value. Java uses references, so from your perspective as the programmer, there's no way of knowing the physical location of that object on the heap. To get back to your question, an array of "pointers" probably means an array of some reference type.
Variable "strings" is a reference variable that points to a 2 element array. Each element in the array is also a reference -- the first one references the string "hi" (located at some unknowable location on the heap) and the second one references the string "there" (located at some other unknowable location on the heap).
Raams Raj wrote:Hi to all,
what is array of pointers & pointers in array??
Welcome to JavaRanch. Looks like you are from a C/C++ background. Is nt it? For sure you might get this question. Glad that you got it.
I guess other ranchers have given good answers. Does that help?
1. Java does NOT have a direct concept/terminology called Pointers. Indeed they are known as 'References'. Semantically the two words mean the same thing, pointing to an object/entity at run time.
2. Having agreed upon the aforesaid note, you can have an array of pointers [array of references] and pointers in array [references in array]. But they both drill down to the same thing finally.
Say for example:
where s1, s2 -> References to a String object.
strArray -> Reference to an object (which is nothing but an array here), holding some other references (s1,s2).
-- Array of References (Array of Pointers)
It can also be said that there are some References in Array (Pointers in Array).
NOTE: In Java you don't have a terminology of acccessing/modifying the content or value of an object being pointed by the pointer through indirection operator (*) and increment/decrement stuff. Because, Java does NOT support pointers.
Does that help?
Please post back if you need further clarifications.