aspose file tools*
The moose likes Java in General and the fly likes Static classes and functions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Static classes and functions" Watch "Static classes and functions" New topic
Author

Static classes and functions

shahabas shabeer
Ranch Hand

Joined: Feb 23, 2004
Posts: 49
Hai,
Is there any disadvatage in using static classes and static functions ?
Please help me.

Thank you in advance...


The greatest pleasure in life is doing what peoples say you can not do.
Chris Shepherd
Ranch Hand

Joined: Jun 27, 2000
Posts: 286
no none. For the right purposes, they work perfectly.
Chris
shahabas shabeer
Ranch Hand

Joined: Feb 23, 2004
Posts: 49
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

Joined: Nov 20, 2003
Posts: 196
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

Joined: Nov 20, 2003
Posts: 196
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

Joined: Feb 23, 2004
Posts: 49
That was a clear explanation.
Thanks a lot...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static classes and functions