abhay :
Th important thing to note is that the use of the address is as a hash, not for memory 
access.
hashCode() is a transforamtion which is generically known in computer science as a 
"hash
function". It is used to compute an index into an associative collection, which is 
generally less
expensive on later retrieval. 

(q.v. http://ciips.ee.uwa.edu.au/~morris/Year2/PLDS210/hash_tables.html )
--- "U. Penski" <[EMAIL PROTECTED]> wrote:
> Hello,
>   -----Original Message-----
>   From: abhay [mailto:[EMAIL PROTECTED]]
>   Sent: Monday, December 30, 2002 4:40 AM
>   To: JDJList
>   Subject: [jdjlist] hashCode ??
> 
> 
>   >....
> 
>   > The API says ...
> 
>    > "As much as is reasonably practical, the hashCode method defined by
> class Object does return distinct integers for distinct objects. (This is
> typically
> 
>   > implemented by converting the internal address of the object into an
> integer, but this implementation technique is not required by the JavaTM
> 
>   > programming language.) "
> 
>    > So can we safely assume that its the address of the object in memory ?
> (a pointer in C or C++)
>    > So if java a developer need not be concerned about pointers, what is
> this method doing here ?
> 
>   not safely - watch the word "typically" !
> 
>   Early versions of the Windows memory handler (AFAIK at least versions 3.0
> and 3.1) allowed the handle of an allocated fixed memory block to contain
> its physical adress in memory.
> 
>   There was expressively no guarantee for the programmer that later versions
> still use this technique
> 
>   (should be the same in this case).
> 
> 
> 
>    >...
> 
>    > This means if you have a two objects with equal values inside (for
> instance ..
>    >     String str1 = new String("Abhay");
>    >     String str2 = new String("Abhay");
> 
>    > and if hashCode() returns the address then does it means that these 2
> objects are physically one and
>    > the same in the memory ? I dont get it ...
> 
>    > Please share your knowledge..
> 
>   duplicate string elimination is an old subject (e.g. since Borland C++ 4.x
> or earlier) and has already been discussed
> 
>   months or even years ago in this newsgroup  for the Java world (***).
> 
>   If you use
> 
>   Map table=new HashMap();
> 
>    and  table.put( ... )  for duplicate objects (with the same content) then
> these objects should be referred to with ONE  integer (adress or handle -
> depending on implementation).
> 
>   Outside HashMap usage the two strings (str1 and str2) might still have 2 -
> visible or invisible - memory adresses (see *** above)
> 
>    regards,
>   U. Penski
> 
>   [EMAIL PROTECTED]
> 
>   [ sorry to all the firewalls out there that I have to use Outlook again to
> send this eMail - my Outlook Express installation currently probably dreams
> about a better memory handler ]
> 
> 
> 
> 
> 
> ____________________________________________________
> To change your JDJList options, please visit:
> http://www.sys-con.com/java/list.cfm
> 
> Be respectful! Clean up your posts before replying
> ____________________________________________________
> 


=====

Mark Zawadzki Performance Engineer/DBA/Programmer extraordinaire� [EMAIL PROTECTED] 
[EMAIL PROTECTED]

 "Democracies die behind closed doors," - Judge Damon Keith

 "The people of this country, not special interest big money, should be
the source of all political power. Government must remain the domain of
the general citizenry, not a narrow elite." - Sen. Paul Wellstone



__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Be respectful! Clean up your posts before replying
____________________________________________________

Reply via email to