by making that class final
An immutable class is any data storage class in which the data cannot be changed. The most common example of this in Java is the String class.
StringBuffer is java class available in java.lang package which provides mutable String object where String is immutable class. The methods of this class like reverse(), append(),insert() gives facility to insert data of the same object.
lmutable object
We can create a exception sub class by extending Exception class available in java
class is a blueprint which does not have its own existence but it can pass all of its feature to its child classes.
You create a text file with a .java extension. Then you put a proper class definition.
You need to use File class to create file in java and than Reader class implementation such as BufferedReder to read content.
It means that something can be changed after it is created. Immutable means that it can't be changed.
Remote
An immutable object is classed in Java programming as an object that cannot be changed after it is made. YouTube has videos that can be viewed on this subject as well as Vimeo.
Define your own class which will have all members final & methods to return values of variable only /* javavishal.blogspot.com This code shows the way to make a class immutable */ // The immutable class final class VImmutableClass { // instance var are made private & final to restrict the access private final int prop1; // Constructor where we can provide the constant value public VImmutableClass(int vprop1) { prop1 = vprop1 } // provide only methods which return the instance var // & not change the values public int getProp1() { return prop1; } } // class MyImmutable public class MyImmutable { public static void main(String[] args) { VImmutableClass obj1 = new VImmutableClass(3); System.out.println(obj1.getProp1()); // there is no way to change the values of count & value- // no method to call besides getXX, no subclassing, no public access to var -> Immutable } }
Constructors are used to create the instance of a class.