• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between final variable in JAVA and constant in C

 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are difference between final variable in JAVA and constant in C? or variable use define keyword in C?
 
Henry Wong
author
Marshal
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic