• Post Reply Bookmark Topic Watch Topic
  • New Topic

Where does the variable name or Identifier gets stored, Stack or Heap?  RSS feed

 
Ranch Hand
Posts: 41
Eclipse IDE Mac OS X Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I had an interesting discussion with one of my colleague today. I was sure that variable gets stored in stack, and by variable I mean the name of the variable or identifier to be precise. The variable's value however depends on type and scope of the variable. On the other hand my colleague says that variable name or identifier gets stored on perm gen or class metadata. Well now I had no idea what perm gen or class metadata is and where does it gets stored. Can some one help me to understand this ?

Thanks & Regards
Jeetendra
 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally variable names don't get stored anywhere at run time. Certainly local variable names aren't stored. However instance variables and static variables of a class can be accessed by reflection code, so presumably they are part of the class. They certainly wouldn't be stored separately from the class, there would be no point in doing that.
 
jeetendra Choudhary
Ranch Hand
Posts: 41
Eclipse IDE Mac OS X Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

Thanks for the reply. Is there any way we can debug or do something to confirm it?

Thanks & Regards
Jeetendra
 
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can inspect the .class files with javap.exe . Likely, member variables and methods will still have their names. Method bodies however will have been converted to byte-code instructions.

At runtime, you can use reflection to inspect Class objects.
 
Saloon Keeper
Posts: 18800
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PermGen went away with Java 8, thank goodness.

External names are compiled as their signatures for binding purposes. I know that simple names are stored with the class definition, which should put them in a class heap which depending on JVM implementation might not be the same as the general heap. Names are included when the compiler generates debug code for the debugger's benefit. Names will also be defined in the class metadata for anything that might be resolved by name or signature via class introspection. If it can be determined that none of the above apply, then the compiler would be free to avoid storing the name in the class metadata.

In other words, private members are unlikely to have their names stored within the class file at all the class was compiled with the debug option turned off.
 
Sheriff
Posts: 11338
177
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jeetendra Choudhary wrote:Can some one help me to understand this ?

I see you have also posted this question on Stack Overflow. Here at CodeRanch we are fine with cross-posting, however we ask you to disclose this. That way someone doesn't reproduce the effort in answering a question that has already been answered. Thanks for your friendly cooperation!

 
jeetendra Choudhary
Ranch Hand
Posts: 41
Eclipse IDE Mac OS X Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roel,

Thanks I will keep that in mind and will follow the practice going forward.

Thanks & Regards
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!