== No precompiler in JAVA - How can I do? ==
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   laeticia_corlean
Posted On:   Friday, October 4, 2002 02:01 AM

Hi,


In JAVA we don't have the C/C++ precompiler thus #ifdefine macro does not exists :o( How could I do to add/remove code from my code in case I am in DEBUG or RELEASE version?
a.k.a In release I would like a lot of traces to go away.


If I have to use something like if( DEBUG = true ) { } all over my JAVA code this is not going to go away in my final release and the segment of code (the "if") will always be tested -> overhead


Is this right ???

Re: == No precompiler in JAVA - How can I do? ==

Posted By:   Zac_Jacobson  
Posted On:   Friday, October 4, 2002 12:22 PM

The Java purists won't like this one, but:

The C preprocessor is agnostic regarding the language it uses. It's just a macro processor. You can run cpp on your java code before compilation during the build process (don't overwrite the original!).

Re: == No precompiler in JAVA - How can I do? ==

Posted By:   Anonymous  
Posted On:   Friday, October 4, 2002 04:04 AM

That is an aspect of AOP (aspect oriented programming). There are some add´s to java to realize AOP (e.g. AspectJ). Logging can be done with the Logging API of JDK 1.4 or with Apaches log4j. Log4J is configured by XML-file, so you can log with different levels.


If you want to do some more, you can write your own precompiler (parses your code and generate "standard" java source code).


If you want do something before/after invoking methods you can use Proxies.

Re: == No precompiler in JAVA - How can I do? ==

Posted By:   eimi_nos  
Posted On:   Friday, October 4, 2002 03:42 AM

You can define two packages "debug" and "release" like these, and when debugging you would import the package "debug" and when releasing you can import "release" instead.

package debug;
public Class Debug{
public void debugging(){
//do something
}
}

and

package release;
public class Debug{
public void debugging(){} //do nothing
}
About | Sitemap | Contact