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.
A compile-time constant is a value that can be (and is) computed at compile-time. A runtime constant is a value that is computed only while the program is running. If you run the same program more than once:
A compile-time constant will have the same value each time the application is run. A runtime constant can have a different value each time the application is run.
Maybe you encountered the term when you read that there is a big-time gotcha with respect to compile-time constants. Consider the following scenario...
Now, if you compile these two java files and run class B, it will print out, "Hello". If you then change the "MESSAGE" variable in A.java to "Hello, World", compile A.java, and then run class B again, it'll print "Hello" still! It will not lookup the value of the "MESSAGE" variable dynamically at runtime. So, be careful. It helps if you use an IDE which keeps track of that stuff and knows that B needs to be recompiled because one of its dependencies has changed. [ March 08, 2005: Message edited by: James Carman ]
James Carman, President<br />Carman Consulting, Inc.