While i am defining a class, i prefer to use following format.
public class ClassName{
private String var1 = null;
private Map<String,String> map1 = null;
public void process(){
try{
var1 = "Variable1";
map1 = new HashMap<String,String>();
// Do Some Stuffs Here with the varaibles.
} catch(Exception e){
e.printStackTrace();
} finally{
var1 = null;
map1 = null;
}
}
}
But my friends suggest me to use following way,
public class ClassName{
public void process(){
String var1 = null;
Map<String,String> map1 = null;
try{
var1 = "Variable1";
map1 = new HashMap<String,String>();
// Do Some Stuffs Here with the varaibles.
} catch(Exception e){
e.printStackTrace();
} finally{
}
}
}
My question is which is better and why?.