File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using "final" inside an applet

 
Paul Chamsay
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Looking around, I see lots of people using the modifier final when declaring swing components like:



Is this a good practice? Is final used sparingly or liberally? Thanks!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Final has no cost associated with it in terms of performance or memory use, but from a software-engineering perspective, it has some nice benefits. This is pretty obvious, but a final variable's value can't change. Therefore, reading code that involves final variables is easier; you know more about the data involved than you would know if the variables weren't final.

In theory, at least, "final" allows the JVM to do more runtime optimizations, too: if you know a value will never change, for instance, you can cache it in a register rather than refetching it from memory.

So there are many plusses, and really no minuses. Using final whenever you can -- i.e., whenever you have a variable whose value will never change -- is a good practice.
 
Paul Chamsay
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ernest for a very clear answer
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic