This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi, java.lang.Math class is defined as final and hence it cannot be subclassed and is immutable. Here is the heirarchy: java.lang.Object | java.lang.Math public final class Math extends Object. Note: java.lang.String and all Wrapper classes (Byte,Integer,Long,Double,Float...) are also immutable. - Suresh Selvaraj
Suresh Selvaraj, (author of JQuiz)<br />SCJP2<br /><a href="http://www.decontconsulting.com" target="_blank" rel="nofollow">www.decontconsulting.com</a>
Suresh, Immutability has nothing to do with being able to subclass a class. These two are totally different things. Immutable means the contents cannot be changed once the class is instantiated and initialized with some value. For example, when you create an instance of <code>Double</code> with a value 2.3, you will not be able to make it hold another value, say 5.7. It is like putting something into a box and sealing it. The box remains sealed with the original content. There is no way you can re-open it and put something else inside. That is immutability. Extensibility or subclassing is a different thing altogether. When a class is declared final, it means you will have to feel satisfied with its current implementation and use it as it is. By no means you will be able to specialize the class by subclassing and add desired behaviour to it. When someone designed the class he felt good about the initial design and thought it may not be necessary for somone to extend it. Hence it was made final A final class may be mutable and my favourite example is the <code>StringBuffer</code> class. You cannot extend the <code>StringBuffer</code> class but you can change the contents of a <code>StringBuffer</code> instance any number of times after it is created. Hope that helps, Ajith
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Actually, there is no such thing as an immutable class. A class is a class is a class. You can't change a class.
Objects can be immutable. A class can have mutable or immutable instances. The math class however has no instances. It's a utility class.
From a theoretical point of view, you could consider the Math class an instance of the Class class. In this case Math should be considered mutable, because it has a method which' output changes between invocations: the random() method.
The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com