How do you declare constant values in java

Showing Answers 1 - 17 of 17 Answers


  • Jun 23rd, 2005

Using Final keyword we can declre the constant values

Murtuza F.S.

  • Oct 6th, 2005

By declaring it with static final

  Was this answer useful?  Yes


  • Oct 29th, 2005

A variable can be made constant only with the help of a final keyword. If you want to make it to be accessible from other classes then you need static.

  Was this answer useful?  Yes

vivek verma

  • Nov 2nd, 2006

Information provided in this site is really needful and i think that they provide this for a long time.

  Was this answer useful?  Yes

1.constant values can be declared  by using the   final keyword.  variables should be intialized. variable cannot be reintialized  once intialized the value. reference variables cannot refer to a different object  once the object 
    hasbeen assigned to the final variable. reference variables must be initialized before the constructor completes.

  Was this answer useful?  Yes


  • Aug 31st, 2007

We want constant using final keyword only ok. There is no using static

  Was this answer useful?  Yes

Amit Patil

  • Sep 17th, 2007

Rightly said, Using final is enuf, there is absolutely No need for keyword static

  Was this answer useful?  Yes


  • Oct 15th, 2007

Yes, Using final Keyword is enuough for making a var constant. Could anybody can diff STATIC and FINAL.

  Was this answer useful?  Yes


  • Oct 26th, 2007

Final values must be initialized ..

This is partly true.. You can have blank final variables. which may not be initailized during declaration . They have to be initialized once and only once in constructor.

  Was this answer useful?  Yes


  • Nov 5th, 2007

We can declared the constant variable through final keyword
   in this once you assign the value for the final variable ,it cant modified entire the program , if you want modify the compilation error will be occurred

  Was this answer useful?  Yes


  • Feb 14th, 2008

we declare constant in java by final keyword and we have to intilize by our own JVM is not respnsble fr it

  Was this answer useful?  Yes

For declaring constant in Java,  Java gives us 3 suggestion.

1. Declare constant variable as a final.
2. Also constant variable declare as a final.
3. All the letter of constant variable is capital.

For example Maths. PI is a final static constant.It is a built in constant reside in java.lang package.
These 3 are only suggestion not a rule, it means Java not fores to you for applying.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions