File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes final and const Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "final and const" Watch "final and const" New topic
Author

final and const

aakash bhatt
Ranch Hand

Joined: Jan 09, 2003
Posts: 182
What is the difference between final and const keyword
Regards,
aakash
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
The const keyword doesn't have any function in Java.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
"const" is a C++ keyword, the equivalent of "final". It's reserved in Java, presumably in case they ever decide to implement it. If they do, they will probably implement it in method parameters to let the compiler know that the values passed in cannot be modified.
Currently, final works for parameters, but const would probably have one difference: When using final on an object reference, the reference itself is final, not the object. By using const, the object could be marked unchangeable, at least by the method that sees the const reference.
Regards,
Jeff


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Nischal Tanna
Ranch Hand

Joined: Aug 19, 2003
Posts: 182
final keyword in Java can be used with:
methods,variables and classes
1.if used with a method .the method cannot be overridden by a child class.
2.if used with a variable,the variable value remains constant
3.if used with a class,the class cannot be inherited i.e., no child of a final class..
hope this works..
Nischal


Thnx
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: final and const