Sunday 18 September 2016

Immutable

12.13 Immutable

Immutable 
  • Once if we create a String object we can not perform any changes in the existing object, String object never changeable, this behavior is called Immutable.
-------------------------------------------------------------------
Program         :        Program on immutable nature
Program name  :        ImmutableDemo1.java
Output             : 
                                Java

class ImmutableDemo1
{
public static void main(String args[])
{
        String s1 = new String("Java");
        s1.concat("Language");

        System.out.println(s1);
}
}

Compile          :          javac ImmutableDemo1.java
Run                :          java ImmutableDemo1
Output            :
                                 Java
-------------------------------------------------------------------
Note
  • String and all wrapper classes are having immutable nature.
  • Wrapper classes (Byte, Short, Integer, Short, Long, Float, Double, Character)
Thanks for your time.
Nireekshan