One is the static method Integer.valueOf(String), which
returns a Java Integer object when passed a String that properly represents an integer number.
The Java Math class provides many more examples of static methods. Any object can take advantage of
the static methods in the Math class to compute a transcendental function, square root, log, etc. The object
using the routine must simply reference the class name, followed by the dot notation, and the name of the static
method; for example, Math.sqrt(X) will return the square root of X.
Unless there is a special reason to do so, such as providing a library of functions as the Math class does,
it is better practice to avoid static methods. The reason is the same as for static variables; the shared code
provides more opportunity for unexpected ???side effects??? to occur. The exception to this rule is the Java
program??™s main() method. The JVM must find a public static method called main in the class being
executed.
Visual Basic .NET uses the term ???shared??? instead of ???static,??? and the word shared is a better description
of the concept. The term static has been used in several ways in different programming languages. For instance,
a static variable in a C procedure (C is a procedural language, not an OO language) is one whose address does
not change between executions of the procedure.
Pages:
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155