Results 1 to 4 of 4
Thread: What is an Immutable Class
- 02-06-2009, 10:41 AM #1
- 02-06-2009, 01:46 PM #2
Senior Member
- Join Date
- Nov 2008
- Posts
- 286
- Rep Power
- 5
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, 07: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"
s.concat("123")
s.o.p(s)
StringBuffer sb = new StringBuffer()
sb.append("abc123")
s.o.p(sb.toString())
1->abc
2->abc123
nw to correct first use
s = s.concat("123") rather than s.concat("123") , it does not store anything.
- 02-06-2009, 08:12 PM #4
Quick comment...
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.
Thanks,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
Similar Threads
-
Calling a method on original class from created class
By kpedersen in forum Advanced JavaReplies: 4Last Post: 08-20-2008, 12:25 AM -
Able to find class file in WEB-INF/classes but not after add sub folders in class dir
By vitalstrike82 in forum Web FrameworksReplies: 0Last Post: 05-13-2008, 06:16 AM -
Class Reflection: Finding super class names
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:12 PM -
what is the Priority for execution of Interface class and a Abstract class
By Santoshbk in forum Advanced JavaReplies: 0Last Post: 04-02-2008, 07:04 AM -
Strings are immutable yet they can be changed ?
By anjanesh in forum New To JavaReplies: 4Last Post: 05-19-2007, 03:08 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks