This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Can someone please tell me whats causing the problem here?
I feel it's because, when we declare a variable as final, we HAVE to give the variable a value and it does not get a default value as variables which are not initialized(The not final variables). Is that correct?
Well you could but it would make writing the compiler a lot harder. It would have to check if there is a static initializer block somewhere that initializes the field, and more importantly - if the field is not used before that, either in the same block or a previous static initializer block.
If you don't know the direct value when compiling, it is possible to use the results of a static method:
That one is taken directly from java.io.File. System.getProperty is also an often used source for static final fields.