View RSS Feed

Java Basic

Using Imports to Change Behaviour

Rate this Entry
by , 11-30-2011 at 02:36 AM (861 Views)
One thing that would be great to have is a feature that I know well from my previous experience coding in C. That is the possibility to conditional compile in order to modify the behavior of the application. A feature that is missing from Java is Cís conditional compilation, which allows you to change a switch and get different behavior without changing any other code. I think is was left out of Java is that I remember using this feature often to address issues related to compiling a program on different platforms. As java was built to be cross-platform, I guess they deemed such a feature to be unnecessary.

There are still other valuable uses for conditional compilation such as for debugging. It would be very straightforward to be able to enable features for debugging during development and disable them for a production. Now I discovered that a way to move from debug to production versions of a package is to change the package being imported. This is a technique that I use quite often when going from simulated to real versions of packages with which I need to integrate.

Submit "Using Imports to Change Behaviour" to Facebook Submit "Using Imports to Change Behaviour" to Digg Submit "Using Imports to Change Behaviour" to del.icio.us Submit "Using Imports to Change Behaviour" to StumbleUpon Submit "Using Imports to Change Behaviour" to Google

Categories
Tutorial , Import

Comments