Results 1 to 4 of 4
Thread: What is an Immutable Class
- 02-06-2009, 11:41 AM #1
- 02-06-2009, 02:46 PM #2Senior Member
- Join Date
- Nov 2008
- Rep Power
Usually an immutable object/class is one which has all its fields declared as final, though more loosely, the term is sometimes used to mean any object that doesn't provide methods to change its state once instantiated (more strictly, you could use the term "unmodifiable" for this).
The distinction is important in concurrent programming because if a field is declared final, then the JVM guarantees that it is safe to access that field from other threads without synchronization (as of Java 5).Neil Coffey
Javamex - Java tutorials and performance info
- 02-06-2009, 08:33 PM #3
Immutable means not subject to change i.e static.
eg:String objects are constants and immutable whereas String Buffer/String Builder(JDK 5.0) not , they are growable and modifiable objects.
try this u will get the answer:
String s = "abc"
StringBuffer sb = new StringBuffer()
nw to correct first use
s = s.concat("123") rather than s.concat("123") , it does not store anything.
- 02-06-2009, 09:12 PM #4
Rocky... a small comment... since your posting in the "New to Java" sub-forum, it's not a good idea to abriviate code like "s.o.p" (which I assume means "System.out.println") since it could confuse the new posters to this forum.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- By kpedersen in forum Advanced JavaReplies: 4Last Post: 08-20-2008, 12:25 AM
- By vitalstrike82 in forum Web FrameworksReplies: 0Last Post: 05-13-2008, 06:16 AM
- By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:12 PM
- By Santoshbk in forum Advanced JavaReplies: 0Last Post: 04-02-2008, 07:04 AM
- By anjanesh in forum New To JavaReplies: 4Last Post: 05-19-2007, 03:08 PM