This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes immutable objects.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "immutable objects...." Watch "immutable objects...." New topic
Author

immutable objects....

prateek sharmaa
Ranch Hand

Joined: May 15, 2010
Posts: 38
hi all,
can anyone please tell me that what are immutable objects in Java other than the following :
(1) String
(2) Wrapper Objects

and how can we make objects immutable??
Istvan Kovacs
Ranch Hand

Joined: May 06, 2010
Posts: 100
http://java.sun.com/docs/books/tutorial/essential/concurrency/imstrat.html

(Under the hood, String isn't completely immutable, it's effectively immutable. The string's hash code is cached in an instance variable, but is not computed until it is first accessed.)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19552
    
  16

prateek sharmaa wrote:and how can we make objects immutable??

Please SearchFirst. This question has been asked several times before.
prateek sharmaa
Ranch Hand

Joined: May 15, 2010
Posts: 38
thanks Rob and Istvan for the reply and i am really sorry for posting the question without searching.

now can you please give me the answer of my first question that whether any other objects are there other thatn Strings and Wrapper objects that are immutable??
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19552
    
  16

java.lang.Class
java.lang.Object
java.net.URI

And then I got bored

In essence, any class that does not allow its internal state (fields) to be changed is immutable. Any stateless object (like instances of java.lang.Object) are inherently immutable.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: immutable objects....
 
Similar Threads
Strange answers about "Strings" by JAMIE JAWORSKI
Confusion about string objects
Wrapper Classes
HashMap keys
Immutable classes in java