• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

when final variable occupy memory ?

 
Ranch Hand
Posts: 53
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ,

can anyone please let me know when final variable occupy memory in java?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Someone here COULD...but it would be better if you tell us what YOU think first. That leads to a discussion, which is much more interesting and useful than a simple answer to your question.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:Someone here COULD...


You think? I'm not sure I could answer that one definitively. Or at least not without a lot of JLS trawling.

@phooton: And the reason is that it just doesn't matter. If the field wasn't final it might, or if you're doing something so tortuous that knowing precisely when everything is done in the construction phase of a Java object is essential knowledge; but in 99.99[999]% of the cases, it doesn't. And in those that it does, it's probably bad design.

Java is not C or C++, and with good reason. It is a memory-managed language, and that means that you leave it up to the JVM and the garbage-collector to deal with memory; you initialize variables eagerly (if required); and basically, you don't leave anything up to the whims of a complex construction algorithm that you have absolutely NO control over.

Old proverb: An ounce of prevention is worth a pound of cure.

Winston
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think you will find the answer in the JLS, nor the JVM specification. It can probably vary from implementation to implementation.

And what makes you think there is any difference in behaviour between final variables and non‑final?
 
reply
    Bookmark Topic Watch Topic
  • New Topic