Skip to main content

Why declare a method static

Static methods can be called without using the class reference (object). Following are the two reasons, one can use static methods:

Documentation Anyone seeing that a method is static will know how to call it (see below). Similarly, any programmer looking at the code will know that a static method can't interact with instance variables, which makes reading and debugging easier.

Efficiency A compiler will usually produce slightly more efficient code because no implicit object parameter has to be passed to the method.

Comments

Popular posts from this blog

SVN red book

I normally use Subclipse plugin for Eclipse for SVN operations. It really makes life easy. I am a novice when it comes to performing svn operations using SVN commands. I found a very useful resource for that: HTML version of SVN red book (for subversion 1.5) Hope you find this useful :)

JAR file

The JAR file format is based on the popular ZIP file format, and is used for aggregating many files into one. Unlike ZIP files, JAR files are used not only for archiving and distribution, but also for deployment and encapsulation of libraries, components, and plug-ins, and are consumed directly by tools such as compilers and JVMs. Special files contained in the JAR, such as manifests and deployment descriptors, instruct tools how a particular JAR is to be treated. A JAR file might be used: * For distributing and using class libraries * As building blocks for applications and extensions * As deployment units for components, applets, or plug-ins * For packaging auxiliary resources associated with components