This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static classes and functions

 
shahabas shabeer
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,
Is there any disadvatage in using static classes and static functions ?
Please help me.

Thank you in advance...
 
Chris Shepherd
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no none. For the right purposes, they work perfectly.
Chris
 
shahabas shabeer
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can we determin whether to use an instance or a static method ?
Is there any performance issue in using static methods and variables ?
 
Arnold Reuser
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static class fields are shared among all instances of a particular class, but only within a single Java Virtual Machine. Updating a static class field implies an intent to share the field's value among all instances of the class. But if a class is running in several JVMs simultaneously, only those instances running in the same JVM as the updating instance will have access to the new value. In other words, a nonfinal static class field will behave differently if running in a single JVM, than it will running in multiple JVMs. Maybe you can't call it a disadvantage, but is certainly something to remember when you are programming in a distributed environment.
Read the J2EE blue print if you're interested in these kind of situations.
It is available over here : http://java.sun.com/blueprints/guidelines/designing_enterprise_applications/ejb_tier/qanda/restrictions.html
[ March 05, 2004: Message edited by: Arnold Reuser ]
 
Arnold Reuser
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Refactoring :
1. methods that do not use the unique data of a class instance and
2. variables that are not unique to an instance
By making these methods and variables static is worth the effort.
There are a lot of papers written about java performance, just google it.
 
shahabas shabeer
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was a clear explanation.
Thanks a lot...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic