This content has been marked as final. Show 4 replies
There is no constant keyword.
This is like asking what the difference is between a car and an airplane. If you want to figure out how they work, read the manual. A good Java book is what you need, but you may start with the Java tutorial:
http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html (lookout for "Constants")
Welcome to the forum!
What is difference between final ,static and constant keyword...
Friends i need simple definition with example
Then you need the Java Language Specification. That is the document that defines the entire Java language including 'final' and 'static'; there is no 'constant' keyword.
Section 4.14.4 defines final Variables and it includes an example
4.12.4. final Variables
A variable can be declared final. A final variable may only be assigned to once. Declaring a variable final can serve as useful documentation that its value will not change and can help avoid programming errors.
It is a compile-time error if a final variable is assigned to unless it is definitely unassigned (§16) immediately prior to the assignment.
A blank final is a final variable whose declaration lacks an initializer.
Once a final variable has been assigned, it always contains the same value. If a final variable holds a reference to an object, then the state of the object may be changed by operations on the object, but the variable will always refer to the same object.
This applies also to arrays, because arrays are objects; if a final variable holds a reference to an array, then the components of the array may be changed by operations on the array, but the variable will always refer to the same array.
As for static that keyword can be used for: import declarations (7.5.3, 7.5.4), fields in classes (220.127.116.11), static methods (18.104.22.168), member types (8.5.1)
See those sections for its use.
I suppose that you are C# programmer and interesting with Constant and Final and Static.
There is not Constant, in Java if you want declare as in C# Constant, you need declare Final Static.
for example in Java : final static int a = 10;
in C# : const int a = 10;
For understand keyword I read it 2 years ago, I advice :