my dog learned polymorphism*
The moose likes Beginning Java and the fly likes difference between final variable in JAVA and constant in C Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "difference between final variable in JAVA and constant in C" Watch "difference between final variable in JAVA and constant in C" New topic
Author

difference between final variable in JAVA and constant in C

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
What are difference between final variable in JAVA and constant in C? or variable use define keyword in C?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18553
    
  40

abalfazl hossein wrote:What are difference between final variable in JAVA and constant in C? or variable use define keyword in C?


By "constant in C", I am assuming through the use of the "const" keyword?


In Java, variables that are defined as final, can't be modified. In this regard, it is very similar to variables in C, that are declared as const. Furthermore, the java compiler has the concept of compile time constants, and can treat variables as "constant variables" (variables that are compile time constants). In this regard, it is probably more similar to preprocesor constants in C (using the #define macro).

So... depending on how the final variable is declared in Java, it can be closer to "const" variables or "#define" constants, when comparing to C.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between final variable in JAVA and constant in C
 
Similar Threads
Compile time constant ?
Difference between const & final in java ?
final static int i =0 Whizlabs says i is variable and i feel it is a constant
Diff between instance variable and class variable
java [question -- difference between java and c]