|
|
|
|
Java has no Preprocessor like C and C++. Here's how Java does things that you often use the preprocessor to do in C/C++: Defining constantsInstead of:#define PI 3.14159 // C or C++ in Java, use something like:
Note:
Defining macrosInstead of:write it as a function and trust the compiler to do the right thing.#define min(x, y) (((x) < (y))? (x) : (y)) // C or C++ A good Java compiler will inline code where appropriate Including filesJava does not have any way to include a file. It has no need, because:
Conditional CompilationJava has no equivalent to the C and C++ #ifdef ... #endif directives for conditional compilation.In theory, Java doesn't need conditional compilation, because it's much more portable at the source code level than is either C or C++. In practice, it is still used: Note that, here, if the value of DEBUG (a static final)is
set to false, then the compiler will notice that the debugging code
will never be invoked, and simply not include it (optimize it out) in the resulting class file.
|
|
This page was last modified on 02 October, 2007 |