Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes what is array of pointers & pointers in array? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is array of pointers & pointers in array?" Watch "what is array of pointers & pointers in array?" New topic

what is array of pointers & pointers in array?

Raams Raj

Joined: Sep 10, 2009
Posts: 2
Hi to all,
what is array of pointers & pointers in array??
Henry Wong

Joined: Sep 28, 2004
Posts: 20531

Raams Raj wrote:Hi to all,
what is array of pointers & pointers in array??

Can you give us some context for this question? Technically, Java references (although they point to objects), are not really pointers ... meaning Java doesn't really support pointers.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
marc weber

Joined: Aug 31, 2004
Posts: 11343

Raams Raj wrote:...what is array of pointers & pointers in array?? ...

A Java array of non-primitives holds references to objects, rather than holding the objects themselves. My guess is that's what this is saying.

But as Henry said, Java does not directly use pointers, and we need more context.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Max Rahder
Ranch Hand

Joined: Nov 06, 2000
Posts: 177
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).
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3381

Raams Raj wrote:Hi to all,
what is array of pointers & pointers in array??

Hi Raams,

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?

Simply speaking,

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.

Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
I agree. Here's the link:
subject: what is array of pointers & pointers in array?
It's not a secret anymore!