| Author |
difference between final variable in JAVA and constant in C
|
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
|
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: 16811
|
|
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)
|
 |
 |
|
|
subject: difference between final variable in JAVA and constant in C
|
|
|