Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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

 
Ranch Hand
Posts: 41
Mac OS X Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 26963
84
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 13505
305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 24875
174
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roel,

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

Thanks & Regards
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic