/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) John D. Mitchell, 1996 -- All Rights Reserved PROJECT: JavaWorld MODULE: Tips & Tricks FILE: Constants.java AUTHOR: John D. Mitchell, Mar 1, 1996 REVISION HISTORY: Name Date Description ---- ---- ----------- JDM 96.03.01 Initial version. DESCRIPTION: Use interface to define '#define' constants' equivalent. This file defines a Java Interface which contains a number of compile time constants. This method has the class which wants to use the constants 'implement' the interface. This is a bit nicer than the alternative method of having to prefix each field name with the interface's name. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ interface ConstantsBase { public static final boolean DEBUG = false; public static final int GOLD_RECORDS = 10; public static final String BozoIdentity = "Homey"; } public class Constants implements ConstantsBase { public static void main (String args[]) { // Just access some of the constants. System.out.println ("GOLD_RECORDS = " + GOLD_RECORDS); System.out.println ("Bozo is really " + BozoIdentity); // If "DEBUG" is false, the compiler will collapse out the // entire guarded statement. if (DEBUG) System.out.println ("I'm here!!!"); } }