Home arrow static arrow Java Programming [Archive] - Meeting trouble when retrieving a byte array.
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Meeting trouble when retrieving a byte array.
This topic has 47 replies on 4 pages.    « Previous | 1 | 2 | 3 | 4 | Next »

Posts:2,830
Registered: 9/1/03
Re: Meeting trouble when retrieving a byte array.  
Aug 3, 2004 3:54 AM (reply 15 of 47)



 
Why? Can you explain the reason, silk.m buddy?

because the number you are seeing (depending on jvm) is the memory
address of that object.

java as no way to create (get) an object based on an address in memory.

so you can't do it, that's why :) hope it's clear...
 

Posts:536
Registered: 6/29/03
Re: Meeting trouble when retrieving a byte array.  
Aug 3, 2004 3:54 AM (reply 16 of 47)



 
Thanks, jsalonen buddy!

Suppose I have a string whose value is "Hello, jsalonen!" and I output its reference value (or internal address of Java virtual machine), which is "[B@2aa02aa0", then I assign this value to a byte array.

And what I am going to do is retrieve the content value, i.e. "Hello, jsalonen!" from the byte array, whose value is "[B@2aa02aa0", i.e. the byte array contains the reference value of the content.

Can you help?

Best regards,
George

 

Posts:536
Registered: 6/29/03
Re: Meeting trouble when retrieving a byte array.  
Aug 3, 2004 3:56 AM (reply 17 of 47)



 
Oh! If you are correct, I have only two choices,

- rewrite my project;

- rewrite Java VM;

Hope you are not correct, :)

Thanks,
George

 

Posts:2,830
Registered: 9/1/03
Re: Meeting trouble when retrieving a byte array.  
Aug 3, 2004 3:59 AM (reply 18 of 47)



 
Oh! If you are correct, I have only two choices,

- rewrite my project;

I'd suggest you take this option :)
 

Posts:536
Registered: 6/29/03
Re: Meeting trouble when retrieving a byte array.  
Aug 3, 2004 4:02 AM (reply 19 of 47)



 
Woooh! Hope some day Java VM can be more magic and at the same time, secure enough.

George

 

Posts:11,200
Registered: 7/22/99
Re: Meeting trouble when retrieving a byte array.  
Aug 3, 2004 4:05 AM (reply 20 of 47)



 
Even though it looks like an address, "[B@2aa02aa0" does not reflect the value of a reference or an address in any way.
 

Posts:2,909
Registered: 13.8.2003
Re: Meeting trouble when retrieving a byte array.  
Aug 3, 2004 4:13 AM (reply 21 of 47)



 
We already have C if we want to access memory directly (even though these days it's not totally direct, since you'll be segfaulting fast if you just use random memory places). Java was never intended for that kind of jobs.

What were you hoping to accomplish by getting a reference by it's address, maybe there's a better way?
 

Posts:2,830
Registered: 9/1/03
Re: Meeting trouble when retrieving a byte array.  
Aug 3, 2004 4:29 AM (reply 22 of 47)



 
Even though it looks like an address, "[B@2aa02aa0"
does not reflect the value of a reference or an
address in any way.

"(This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the Java TM programming language.)
"
 

Posts:536
Registered: 6/29/03
Re: Meeting trouble when retrieving a byte array.  
Aug 3, 2004 10:16 PM (reply 23 of 47)



 
Thanks, Kayaman buddy!

I think you are correct. Someone passed me a byte array which contains the value of the reference (for example, "[B@2aa02aa0") of an object, and I want to restore the object by the give reference value. But from silk's reply, I think this method can not work in Java dues to the underlying mechanism of Java VM. Am I correct?

Best regards,
George

 

Posts:536
Registered: 6/29/03
Re: Meeting trouble when retrieving a byte array.  
Aug 3, 2004 10:19 PM (reply 24 of 47)



 
Thanks, jsalonen buddy!

And How should I name the values such as "[B@2aa02aa0" in a formal way other than "reference value" of an object?

Best regards,
George

 

Posts:536
Registered: 6/29/03
Re: Meeting trouble when retrieving a byte array.  
Aug 3, 2004 10:28 PM (reply 25 of 47)



 
Thanks, silk buddy!

Do you mean we can not do this in Java?

Best regards,
George

 

Posts:11,200
Registered: 7/22/99
Re: Meeting trouble when retrieving a byte array.  
Aug 4, 2004 12:45 AM (reply 26 of 47)



 
And How should I name the values such as "[B@2aa02aa0"
in a formal way other than "reference value" of an
object?
"string representation" -- the string representation of a byte array object is like that. Here are string representation of a couple of other objects:
bsh % print(new Object().toString());
java.lang.Object@787c16
bsh % print(new Integer(123).toString());
123
bsh % print(new Date().toString());
Wed Aug 04 10:44:23 EEST 2004
bsh % print(new byte[0].toString());
[B@196f4b5
> Do you mean we can not do this in Java?

There's absolutely no way.
 

Posts:11,200
Registered: 7/22/99
Re: Meeting trouble when retrieving a byte array.  
Aug 4, 2004 12:53 AM (reply 27 of 47)



 
Even though it looks like an address, "[B@2aa02aa0"
does not reflect the value of a reference or an
address in any way.

"(This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the Java TM programming
language.)
"

But the thing after the @-sign is supposed to be the hash code of the object, which is not necessarily the "identity hash code," and even if it was the identity hash code it would still be useless because the hashcode of an object cannot change when the garbage collector moves objects around in memory. Even if the value was originally obtained by converting the internal address to an integer it would not be the address of the object after a while.
 

Posts:2,909
Registered: 13.8.2003
Re: Meeting trouble when retrieving a byte array.  
Aug 4, 2004 1:34 AM (reply 28 of 47)



 
I hate it how jsalonen is always right ;)
 

Posts:2,830
Registered: 9/1/03
Re: Meeting trouble when retrieving a byte array.  
Aug 4, 2004 1:45 AM (reply 29 of 47)



 
I hate it how jsalonen is always right ;)

but he isn't ...

he said: "Even though it looks like an address"[B@2aa02aa0" does not reflect the value of a reference or an address in any way."

When infact it does reflect an address. It reflects the original address of
the object when it was created. Perhaps the object moves from this position
to another during the gc-cycle, it's irellevant. It does reflect an address :)
 
This topic has 47 replies on 4 pages.    « Previous | 1 | 2 | 3 | 4 | Next »