aspose file tools*
The moose likes Java in General and the fly likes final classes vs immutable classes?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "final classes vs immutable classes?? " Watch "final classes vs immutable classes?? " New topic
Author

final classes vs immutable classes??

viki Bhardwaj
Ranch Hand

Joined: Nov 07, 2011
Posts: 74

Hi Ranchers!

I have a bit doubt in the case of final and immutable classes in java, please explain the concepts with example .
is it both having same meaning ??
awaiting for genuine reply......

Thanks..
Vivek
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

here you go !
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14107
    
  16

When a class is final, it just means that you cannot subclass it. Immutable means that you cannot change the state of an object after it has been created. Making classes immutable has many advantages, see this article for more details.

When you want to make a class immutable, you should make it final. But just making it final does not by itself make the class immutable.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
viki Bhardwaj
Ranch Hand

Joined: Nov 07, 2011
Posts: 74

Jesper de Jong wrote:When a class is final, it just means that you cannot subclass it. Immutable means that you cannot change the state of an object after it has been created. see this article for more details.



yes! this is pretty enough to clear my doubt...
Thanks ... Jesper!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: final classes vs immutable classes??