|
| ||||||||||
| Tags: immutable objects, java, programming language, thread |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| What are an Immutable Objects in Java?
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" |
|
#2
| ||||
| ||||
| 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 ramATI 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 |
|
#3
| ||||
| ||||
| 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. |
|
#4
| ||||
| ||||
| 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. |
|
#5
| ||||
| ||||
| 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.... |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |