aspose file tools*
The moose likes Beginning Java and the fly likes Reference Variable in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reference Variable in Java" Watch "Reference Variable in Java" New topic
Author

Reference Variable in Java

Saathvik Reddy
Ranch Hand

Joined: Jun 03, 2005
Posts: 228
Hi,

I am very new to java world. I have a question regarding reference variable
I am creating an object by doing

Blah blah = new Blah();

blah is just a reference to the actual blah object but it doest hold the actual object correct me if i am wrong.
i guess blah occupies some space to store the reference to the object. what would be the max. size of blah reference variable and what type of value can it hold.

Thanks,
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

In the Java VM spec, a reference variable is said to occupy "one stack position", which is typically 32 bits for a 32-bit implementation. But as with many things in Java, the actual size is implementation dependent and not knowable from within your program. In a 64-bit JVM implemenation, a stack slot is probably 64 bits wide.


[Jess in Action][AskingGoodQuestions]
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
I'm curious to know why someone learning Java needs or wants to know this? How are you better off knowing this it 32 bits versus 128 bits? Wouldn't it be better to think of the size of a reference as unimportant? Implementation details usually don't clarify anything.


There is no emoticon for what I am feeling!
Saathvik Reddy
Ranch Hand

Joined: Jun 03, 2005
Posts: 228
Thanks for your reply Ernest!!
Jeff, as a newbie to java world i know not to worry about JVM specs but, i was just curious to know about that.

Thanks,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reference Variable in Java