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

Static vs. Final

 
Dan Grindstaff
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All, I am wondering when it is appropriate to use Static and/or Final and what the difference is. TIA.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is a bit like asking whether you should eat ice cream or drink coffee. The two are as different as chalk and cheese.

If you can manage it, use final a lot on variables. It means a variable can be set up once and once only. After that it cannot be reassigned. It makes it easier to watch the values of variables. The final keyword can be applied both to fields and to local variables. It can also be applied to classes and methods, but that is something different.

The static keyword means the field (or method, or nested class) "belongs" to the class, not to an individual instance, and this is totally different. A static field is one you want to share between all instances of the class (or public static final = use as a constant). A static method is one which takes no information from a particular instance of the class and applies no information fro any particular instances.

I am sure other people will have their own opinions
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic