Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

IMMUTABLE

Ads

 
 

Share on Google+Share on Google+

bhaskarreddy
IMMUTABLE
2 Answer(s)      7 years ago
Posted in : Java Interview Questions
Ads
View Answers

October 13, 2009 at 4:11 PM


Hi Friend,

To make a class immutable we must restrict changing the state of the class object.We can achieve this through a final and private modifier.Therefore,make all fields final and private.Don't provide any methods that modify the object.

for example,

final class ImmutableClass{
private final int count;
public ImmutableClass(int cout){
count = cout;
}
public int getCount(){
return count;
}
}
public class Immutable{
public static void main(String[] args) {
ImmutableClass cl = new ImmutableClass(5);
System.out.println(cl.getCount());
}
}

Thanks


October 24, 2010 at 10:35 AM


Please see here **Deleted**


Ads









Related Tutorials/Questions & Answers:
immutable class
immutable class  How to make a class immutable
String immutable - Java Beginners
String immutable  Why is String immutable?  See here Why String is immutable in Java
Advertisements
IMMUTABLE - Java Interview Questions
IMMUTABLE  How To Make A Class Immutable?  Hi Friend, To make a class immutable we must restrict changing the state of the class...; } } public class Immutable{ public static void main(String[] args
Version of com.dampcake>gson-immutable dependency
List of Version of com.dampcake>gson-immutable dependency
Version of com.qifun>immutable-future_2.10 dependency
List of Version of com.qifun>immutable-future_2.10 dependency
Version of com.qifun>immutable-future_2.11.0-RC4 dependency
List of Version of com.qifun>immutable-future_2.11.0-RC4 dependency
Mutable and immutable Objects - Java Beginners
Mutable and immutable Objects  Hi, Please tell me about Mutable and immutable Objects. What is mutable object and immutable object and how... we can alter. like any primitive. Immutable are those object whcih we can
what is mutable and immutable object in java ?difference ?
what is mutable and immutable object in java ?difference ?  what is mutable and immutable object in java ?difference
STRING IMMUTABLE - Java Interview Questions
STRING IMMUTABLE  Why string objects are immutable? what is the region behind?i want regione plz replyyyyyyyyy  Hi Friend, JVM maintains... object is immutable. Thanks
Maven Dependency gson-immutable >> 1.0
You should include the dependency code given in this page to add Maven Dependency of com.dampcake >> gson-immutable version1.0 in your project
Maven Dependency gson-immutable >> 1.1
You should include the dependency code given in this page to add Maven Dependency of com.dampcake >> gson-immutable version1.1 in your project
Maven Dependency gson-immutable >> 1.1.1
You should include the dependency code given in this page to add Maven Dependency of com.dampcake >> gson-immutable version1.1.1 in your project
Maven Dependency gson-immutable >> 1.2
You should include the dependency code given in this page to add Maven Dependency of com.dampcake >> gson-immutable version1.2 in your project
Maven Dependency immutable-future_2.10 >> 0.1
You should include the dependency code given in this page to add Maven Dependency of com.qifun >> immutable-future_2.10 version0.1 in your project
Maven Dependency immutable-future_2.11.0-RC4 >> 0.1
You should include the dependency code given in this page to add Maven Dependency of com.qifun >> immutable-future_2.11.0-RC4 version0.1 in your project
Immutable Image using Canvas Class
Immutable Image using Canvas Class       This is the immutable image example which shows how to create the immutable image using canvas. In this example ImageCanvas class
Immutable Image MIDlet Example
Immutable Image MIDlet Example       This is the immutable image example, which shows how to create a immutable image in MIDlet. In this example we are creating
StringBuffer related.
StringBuffer related.  how to make StringBuffer as immutable
core java - Java Beginners
core java  hi, we know that String object is immutable in nature so like string object can we create our own object and that object should be immutable i mean we cant modify our own object plzzzzzzzzzzzzz tell me the answer
java interview
java interview  what is infterface? and it is uses? what is ast class? and it is uses? what is ast methods? what is immutable? what is mutable? what are the final class in java? what is the static methods
j2me image application
j2me image application  i can not get the image in my MIDlet .........please tell me the detailed process for creating immutable image without Canvas class
CORE JAVA
CORE JAVA  Static methods can be participated in inheritance? What is static keyword? What is static keyword? How to write code for static factory method? What is mutable and immutable
What is ROWID?
of the Oracle ROWID datatype. It is intended to be immutable. The user should not try
Java object
Java object  What is mutable object and immutable object?  An Immutable object is a kind of object whose state cannot be modified after... after it is created. The basic way to create an immutable object is to make all
(ii) String and String Buffer Class
between String and StringBuffer 1) String object is immutable
Wrapper Class
of the primitive wrapper classes in Java are immutable i.e. once assigned a value to a wrapper... are immutable i.e. once assigned a value to a wrapper class instance cannot be changed
Session Factory
Session Factory  Define the session factory interface in hibernate?   Hi Samar, It creates new hibernate sessions by referencing immutable... sessions by referencing immutable and thread safe objects. Application using
'String' vs 'StringBuffer' - Java Beginners
'String' vs 'StringBuffer'  What should i use String or StringBuffer?  Hi, First you need to rectify the question. Because StringBuffers append the data, and Strings concatenate the data. Since Strings are immutable
java code - Java Beginners
java code  write a program for immutable class  Hi Friend, Try the following code: final class ImmutableClass{ private final String product; private final double price; public ImmutableClass(String
String and stringbuffer object - Java Beginners
are constants and immutable while StringBuffer objects are not. 4)StringBuffer
wrapper classes
of the primitive wrapper classes in Java are immutable i.e. once assigned a value