I am programming Android applications, and the best way here may or may not be the same as Java in general.
I simply want to be able to set a debug flag that will on
This works for me with code if (BuildConfig.DEBUG), using the BuildConfig class. This is a safe and easy code to do. Be careful when using this style of code. Don't use it such that there are 2 different distinct branches of code, between Release and Debug versions. If you do, it might invalidate the app testing for the Release version. For me, I have used it only to skip calling Log messaging.
More details on this class BuildConfig @ Build System Concepts.