Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



What are an Immutable Objects in Java?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 19-02-2010
Member
 
Join Date: Jul 2006
Posts: 218
What are an Immutable Objects in Java?
  

Hi friends,
I have recently started with the threads of Java programming. Before doing Java, I did C++ and HTML programming language. But I never heard about the immutable objects. Hoping that guys over there would help me on this topic. Please tell me what are an Immutable Objects in Java? And also please tell me how to define an Immutable Objects.!! Help me as soon as possible.!!

__________________
~*~Silent~Kid~*~
"To The World You May Be Just One Person, But To One Person You May Be The World"
Reply With Quote
  #2  
Old 19-02-2010
Member
 
Join Date: Aug 2006
Posts: 235
Re: What are an Immutable Objects in Java?

The following rules define a simple strategy for creating immutable objects. Not all classes documented as "immutable" follow these rules. An immutable object is an object whose state cannot be modified after it is created. An object can be either entirely immutable or some attributes in the object may be declared immutable. Such strategies require sophisticated analysis and are not for beginners. It will be better for you to not have a look on this rules. Because you will not understand anything of that.
__________________
3.2 (northwood)
2gig ram
ATI AIW X800xt 256mb
Gigabyte GA-8knxp 875p Chipset
Optiwrite 8X DVD Burner
Win XP PRO Sp2 (Works Perfectly)
2 SATA Raptor 74gig Raid 0
2 7200 IDE 320gig HD
Reply With Quote
  #3  
Old 19-02-2010
Member
 
Join Date: Aug 2006
Posts: 227
Re: What are an Immutable Objects in Java?

In object-oriented and functional programming, an immutable object is an object whose state cannot be modified after it is created. Since you have done C++, I would like to add that its similar using the const member data attribute in the C++ programming language. In some cases, an object is considered immutable even if some internally used attributes change but the object's state appears to be unchanging from an external point of view. An object is considered immutable if its state cannot change after it is constructed.
__________________
I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame.
Reply With Quote
  #4  
Old 19-02-2010
Member
 
Join Date: Jul 2006
Posts: 442
Re: What are an Immutable Objects in Java?

Maximum reliance on immutable objects is widely accepted as a sound strategy for creating simple, reliable code. Immutable objects are particularly useful in concurrent applications. Since they cannot change state, they cannot be corrupted by thread interference or observed in an inconsistent state. All Java variables are by default mutable. You can make them immutable by using the final keyword. You can also make them private and provide no accessors to the outside world to change them. Programmers are often reluctant to employ immutable objects, because they worry about the cost of creating a new object as opposed to updating an object in place.
__________________
"When they give you ruled paper, write the other way..." J.R.J.
Reply With Quote
  #5  
Old 19-02-2010
Member
 
Join Date: Jul 2006
Posts: 286
Re: What are an Immutable Objects in Java?

Mutable objects are objects whose state can change. Immutable objects are objects whose state never changes after creation. Immutable objects have many desirable properties. You can share immutable objects between threads without danger of changes confusing the other thread. Immutable objects are thread-safe. Threads cannot corrupt what they cannot change. Immutable objects make good hash keys, since their hash codes cannot change. Two threads can both work on an immutable object at the same time without any possibility of conflict.
__________________
IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people....
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What are an Immutable Objects in Java?"
Thread Thread Starter Forum Replies Last Post
Advanced Cache Objects in Java StudyBoy Tips & Tweaks 3 31-07-2010 03:41 PM
Return value of generic objects in java Amy Adams Software Development 4 30-03-2010 11:42 AM
Array of objects in java Ash maker Software Development 5 27-02-2010 01:05 AM
What is mutable and immutable Strings Bottlenecked Software Development 5 03-02-2010 12:05 PM
Access to Objects In A JavaBean From Another Java Bean ramsun Software Development 5 30-01-2010 12:18 PM


All times are GMT +5.5. The time now is 02:55 AM.