import java.util.HashMap;
class Sample{
private
String key = "ABC";
public Sample(){
HashMap map = new HashMap();
map.put(key, "XYZ");
System.out.println("Attribute created");
String s = (String)map.get(key);
System.out.println("Value == "+ s);
}
public static void main(String[] arg){
long time;
System.out.println(time = System.currentTimeMillis());
Sample s = new Sample();
System.out.println(System.currentTimeMillis() - time);
}
}
/////////////////////////////////////////////////////////////////////////
import java.util.HashMap;
class Sample1{
public Sample1(){
HashMap map = new HashMap();
map.put("ABC", "XYZ");
System.out.println("Attribute created");
String s = (String)map.get("ABC");
System.out.println("Value == "+ s);
}
public static void main(String[] arg){
long time;
System.out.println(time = System.currentTimeMillis());
Sample1 s = new Sample1();
System.out.println(System.currentTimeMillis()- time);
}
}
//////////////////////////////////////////////////////////////
Which of the two above codes is better in terms of
1. Performance
2. Execution Time
3. Good coding practise
Or any other criteria that compare two similer applications.
[ May 08, 2007: Message edited by: Sunil Kumar Gupta ]