Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-10-2008, 11:20 AM
Member
 
Join Date: Sep 2008
Posts: 7
tapies is on a distinguished road
A variable pointer
Hi,

could you please advise me how can I get a variable pointer (address) to see where it points to?

Thanks a lot,
T.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-10-2008, 01:31 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,564
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
It's not possible in Java, and it's foolish think to try. There is no point to deal with variable address in Java.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-10-2008, 03:54 PM
Member
 
Join Date: Sep 2008
Posts: 7
tapies is on a distinguished road
Yes, I see. I just wanted to use that to check e.g. whether two different variables pointed to the same or different memory spot.

Thank you Eranga.
T.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-10-2008, 04:45 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
whether two different variables pointed to the same
Use the == operator with the two variables
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 09-11-2008, 05:44 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,564
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by tapies View Post
Yes, I see. I just wanted to use that to check e.g. whether two different variables pointed to the same or different memory spot.

Thank you Eranga.
T.
You mean pointed to the same memory address? Say you have two int variables as follows,

Code:
int i = 10; int j = 10;
So you want to know that bot i and j use the same memory address, right?

The answer is no. Whenever the new variable is declared it allocated a memory space as well as address.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 09-11-2008, 06:42 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 475
fishtoprecords is on a distinguished road
Quote:
Originally Posted by Eranga View Post
It's not possible in Java, and it's foolish think to try. There is no point to deal with variable address in Java.
More, Java was carefully designed so you could not do this. It was a bug farm in C, and the Java designers did not want to maintain the bugs.

While you can do things like use == and .equals() to get an idea, none of them are guaranteed to give you the information. Its a secret and supposed to stay that way.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 09-11-2008, 06:46 AM
Member
 
Join Date: Sep 2008
Posts: 4
ChazZeromus is on a distinguished road
If you wanted a pointer like variable manipulation. You can created a class that makes and stores variables in a table and then you can "address" then use an index acting as an address. Lol, just trying to make a useful reply.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 09-11-2008, 08:16 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,564
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
However my thoughts on this is, very bad idea. Dealing with the memory address in Java is not required in any way, link in C/C++
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 09-11-2008, 09:33 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 475
fishtoprecords is on a distinguished road
Quote:
Originally Posted by ChazZeromus View Post
If you wanted a pointer like variable manipulation. You can created a class that makes and stores variables in a table and then you can "address" then use an index acting as an address. Lol, just trying to make a useful reply.
Your reply is technically correct, but a really bad idea. This is not the Java Way. If you want to write low level code, just use C.

I would argue with your claim that it is a useful reply.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 09-11-2008, 10:24 AM
Member
 
Join Date: Sep 2008
Posts: 7
tapies is on a distinguished road
I see, that is not the Java Way.
Thanks a lot to all of you.
F.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 09-11-2008, 02:55 PM
Member
 
Join Date: Sep 2008
Posts: 4
ChazZeromus is on a distinguished road
*Shrug*
Yeah, well it's the closest thing to addresses I could think of
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 09-12-2008, 11:33 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,564
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by ChazZeromus View Post
*Shrug*
Yeah, well it's the closest thing to addresses I could think of
The way you are talking is correct as fishtoprecords says in his last post. And also he said that it's a bad idea. In simple word the reason is, Java is a high level language, so we never worried about in memory management.

Say you have define an array as follows in C++ and Java

Code:
int[] temp = new int[12];
Then you are using it and do some processing. After that what are you doing? In Java, nothing. But in C++, you have to clear the memory, simply delete the array.

Code:
delete[] temp;
I hope you are much clever than me on C++. If so I no need to talk about what happen if I forget to delete the array.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 09-12-2008, 11:55 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 475
fishtoprecords is on a distinguished road
Quote:
Originally Posted by Eranga View Post
Code:
delete[] temp;
what happen if I forget to delete the array.
What happens is, of course, that you get a nearly impossible to find memory leak. And you not only have to remember to write the code to do the delete, but you have to make sure that its executed on every path in your code, including any and all exceptions.

Don't forget to trap all exceptions that you never heard of, because some other developer changed code way down in the call tree in ways you never expected.

There are real engineering reasons why Java has garbage collection: it makes the computer do what programmers and other humans do poorly.

Back in the mid-1990s, folks had theological arguments that garbage collection was too slow. And it can be too slow for realtime work. So the solution is to not use Java for real time work.

The theological arguments ignored the cost and slowness of finding memory leaks in complex systems.
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 09-12-2008, 12:44 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,564
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Thanks for the info. Actually I'm not at good in C++. Just learning in my free time.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
null pointer exception cityguy503@yahoo.com New To Java 4 08-22-2008 09:22 PM
Null pointer Exception peiceonly New To Java 3 08-12-2008 03:36 PM
Avoiding null pointer exception JavaForums Java Blogs 0 07-20-2008 06:00 PM
getting a null pointer exception Rjava XML 4 07-16-2008 07:56 AM
statement null pointer exception bbq Database 1 07-05-2007 06:23 AM


All times are GMT +3. The time now is 10:25 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org