This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes compile time constant. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compile time constant." Watch "compile time constant." New topic

compile time constant.

Milton Ochoa
Ranch Hand

Joined: Oct 23, 2007
Posts: 336

What these are?
Mark Newton
Ranch Hand

Joined: Jan 31, 2006
Posts: 129
Constants. At compile time.
Milton Ochoa
Ranch Hand

Joined: Oct 23, 2007
Posts: 336

but, which ones? gime some example please,

and.. which no? gime som example too please.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 44449
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11876

this term generally refers to some variable that YOU create. the compiler is able to know what it will be.

something like

int x = getValueFromUser()

would not be a constant, because it could change. even

final int x = getValueFromUser()

would not be a COMPILE

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Milton Ochoa
Ranch Hand

Joined: Oct 23, 2007
Posts: 336

I Get it!!

Thank you Fred and Campbell
[ January 18, 2008: Message edited by: Milton Ochoa ]
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
You can also find detailed rules about exactly what is considered a compile-time constant expression in JLS 15.28.

"I'm not back." - Bill Harding, Twister
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3381

A compile time constant is a value which can be very well identified (determined) during the compilation time itself. It does NOT need to wait till runtime.

Some examples are: string literals whatever you type within double quotes (eg. "Sample String"), all constant values like INTEGER.MAX_VALUE etc.,

Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
I agree. Here's the link:
subject: compile time constant.
It's not a secret anymore!