This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes compile time constant and final variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "compile time constant and final variable" Watch "compile time constant and final variable" New topic
Author

compile time constant and final variable

Harsha Subbarayappa
Greenhorn

Joined: Oct 19, 2010
Posts: 5
Can anyone please explain

what is the diff between initializing final variable in same line where it is declared and initializing in other line inside a method.

Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

A compile time constant is a final variable with a value at compile time (e.g. final int i=5;). A final variable is a variable that can only be assigned once. But that doesn't have to mean that is has a value at compile time (e.g. final int i; i=5);

The switch statement only accepts the first.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

You can go through a tutorial like this to get info on the difference between the two...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Harsha Subbarayappa
Greenhorn

Joined: Oct 19, 2010
Posts: 5
it's the link to the same page....
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Harsha Subbarayappa wrote:it's the link to the same page....

Oops, its fixed now
Harsha Subbarayappa
Greenhorn

Joined: Oct 19, 2010
Posts: 5
Thank you very much.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: compile time constant and final variable
 
Similar Threads
about the usage of switch and case
Initializing variables
Case constant must be compile time constant?
Compile Time Constant
Question about local variables in switch