Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reference Variable in Java

 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Saathvik Reddy
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic