Thursday, 29 October 2015

Wednesday, 28 October 2015

JAVA : JVM Architecture

JAVA : JVM Architecture


eg : -Doracle.adfm.usemds=true -Xms256m -Xmx1024m -XX:PermSize=96m -XX:MaxPermSize=1024m -XX:CompileThreshold=8000 -Djbo.debugoutput=silent





Tuesday, 27 October 2015

JAVA : SingleTon correct Implementation

JAVA : SingleTon correct Implementation

As discussed in previous session, there are many ways that singleton can break.
We can over come with those situations by implementing the singleton as shown below.


Monday, 26 October 2015

JAVA : SingleTon Break

JAVA : SingleTon Break




Overcome


Overcome


  • Preferred way is not to implement Cloneable interface as why should one wants to create clone() of Singleton 
  • And if you still do, then just throw Exception from clone() method as “Can not create clone of Singleton class”.





JAVA : Singleton Implementation

JAVA : Singleton Implementation




  • Synchronization is very expensive when we are talking about the performance. 
  • We can see that the synchronized method getInstance does not need to be checked for syncronization after the object is initialized

Tuesday, 20 October 2015

JAVA : HashSet -> Equals and hashCode

JAVA : HashSet -> Equals and hashCode


1. In HashSet(value) -> if we are adding string or int as then no need of equals and hascode override, If we are using object (Eg : Employee) as then we need to override equals and hashcode method.

Below screen shot, since we are going to use Employee object in HashSet, If we dont override hashCode method how HashSet behaves.

WithOut hashCode override:




With hashCode override:


Ref: https://www.youtube.com/watch?v=IwUwIrz9Ge8

JAVA : HashMap -> Equals and HashCode

JAVA : HashMap -> Equals and HashCode


1. In HashMap (key, value) -> if we are adding string or int as key then no need of equals and hascode override, If we are using object (Eg : Employee) as a key then we need to override equals and hashcode method.

Below screen shot, since we are going to use Employee object as a key in HashMap, If we dont override hashCode method how HashMap behaves.

WithOut hashCode override:




With hashCode override:

Ref : https://www.youtube.com/watch?v=IwUwIrz9Ge8

EXCEL : Check 1st column value in 2nd column, if not there then add 1st column value in 4th column.

EXCEL : Check 1st column value in 2nd column, if not there then add 1st column value in 4th column.



Thursday, 15 October 2015

JAVA : COLLECTION Tips

1. Check Duplicate in collection.



2. Want to add objects in order



3. SORT HASHTABLE -> JUST CONVERT HASHTABLE TO TREEMAP (Automatically will be sorted)

public static void main (String[] args) {
Hashtable<String, String> ht= new Hashtable<String, String>();
       ht.put("zac", "Chaitanya");
       ht.put("abc", "Ajeet");
       ht.put("yyt", "Test");
       ht.put("ddc", "Demo");
       ht.put("ssa", "Anuj");

    Map<String, String> map = new TreeMap<String, String>(ht);
    for(Map.Entry<String,String> entry : map.entrySet()) {
          String key = entry.getKey();
          String value = entry.getValue();
        
          System.out.println(key + " => " + value);
    }

OR

    Map hm = new TreeMap(ht);
    Set<String> keys = hm.keySet();
        for(String key: keys){
            System.out.println("Value of "+key+" is: "+hm.get(key));
        }


}

Thursday, 1 October 2015