What is static method?
In general, main motivation for making a method static is convenience. You can call a static method without creating any object, just by using it's class name.So if you need a method, which you want to call directly by class name, make that method static. Utility classes e.g. java.lang.Math
or StringUtils
, are good examples of classes, which uses static methods.
What static method does?
- Static method doesn't modify state of object. Since state of object
is maintained as instance variables
- Static method mostly operates on arguments, almost all static method
accepts arguments, perform some calculation and return value.
What setConfiguration does?
setConfiguration(Configuration conf)
-
Set the static configuration for UGI. In particular, set the security authentication mechanism and the group look up service.
How can we connect to multiple clusters at the same time from single
JVM? I think this is a very basic scenario currently not being
supported by Hadoop API.
Ans: Hadoop API is using like singleton design pattern here. You cannot do that because if you can imagine ever requiring to use object inheritance or needing to use polymorphism for your method, you should definitely skip the static and make it an instance method.
A good scenerio is described here: Static methods are a code smell
Resource Link:
- When to make a method static in Java
- Java Singleton Design Pattern Best Practices with Examples