This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Difference  between const & final  in java ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference  between const & final  in java ?" Watch "Difference  between const & final  in java ?" New topic

Difference between const & final in java ?

Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
dear friends,

Both const & final are used to represent Constant value .

what is difference between const & final in java.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
const is not used to represent anything. It is reserved, but isn't used.
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
const is a reserved keyword that is not currently used. Its inclusion as a keyword was to assist compilers in catching out programs where this C++ keyword had been used in error.
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
final on a reference variable just means that the reference cannot be changed to reference a different object.

As far as I know, const in C++ means that you actually cannot change the object itself (for example by calling mutator methods).

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
Consider Paul's rocket mass heater.
subject: Difference between const & final in java ?
It's not a secret anymore!