This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Compile Time Constants... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Compile Time Constants..." Watch "Compile Time Constants..." New topic
Author

Compile Time Constants...

Dan Silva
Ranch Hand

Joined: Sep 05, 2007
Posts: 86
What does it mean to be a compile time constant?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

A compile time constant is one that can't be set or changed after compilation.

Examples:


The first is a compile time constant.
The compiler knows that the value will be 1 and that it can never change.

In the second example the assignment of SET_AT_RUNTIME is delayed until the construction of the class. The compiler has no idea what SET_AT_RUNTIME will be.

In the third example the value depends on another class which could change after this class has been compiled so it isn't a compile time constant.
[ March 01, 2008: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Dan Silva
Ranch Hand

Joined: Sep 05, 2007
Posts: 86
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compile Time Constants...
 
Similar Threads
compile time constant.
while statement error
How to know the type at runtime?
polymorphism
Conditional display of DisplayTable of DisplayTag