I have a single validation class which has various validate methods. like
public class GlobalValidationClass {
public void validatefields(String s) {
//My Work here
}
In methods of other classes, I create an instance of the above class and then call the validatefields
method.
Like
public class FirstClass {
public void firstPage() {
GlobalValidationClass fp = new GlobalValidationClass();
fp.validatefields("first page");
}
public void secondPage() {
GlobalValidationClass sp = new GlobalValidationClass();
sp.validatefields("second page");
}
My question is will it increase performance if I make the methods in my validation class static? Or it wont as the java's garbage collector will garbage collect the objects at the end of each method and there wont be any performance impact if I am following the approach of creating instance of classes in every method?