/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
	  String sl = "First Name";  // a string literal
	  String so = new String("First Name"); // a string object
	  StringBuffer sb = new StringBuffer("First Name"); // a stringBuffer object
	  

	  System.out.println("s1 = " + sl + " hashCode = "+ mimicObjectToString(sl));
	  sl += "Kumar"; // appended ,
	  System.out.println("s1 = " + sl + " hashCode = "+ mimicObjectToString(sl)+ "\n");
	  // if the output differs it means a new reference has been created during appending
	  
	  System.out.println("so = " + so + " hashCode = "+ mimicObjectToString(so));
	  so += "Kumar";
	  System.out.println("so = " + so + " hashCode = "+ mimicObjectToString(so)+ "\n");
	  
	  System.out.println("sb = " + sb + " hashCode = "+ mimicObjectToString(sb));
	  sb.append("Kumar");
	  System.out.println("sb = " + sb + " hashCode = "+ mimicObjectToString(sb)+ "\n");
	    
	  System.out.println("Changed hashCode denotes different reference has been created, implying its \"immutable\" nature");
	}
	public static String mimicObjectToString(Object o) {
        //prevent a NullPointerException by returning null if o is null
        String result = null;
        if (o !=null)  {
            result = o.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(o));
        }
        return  result;
    }
}
