Class for constants
Thread priorities are not portable
Here are some ways to ensure your application remains portable:
\r
or \n
. Instead,
use the System.getProperty(String)
method to refer to items which depend on the system, such as line terminators and path separators.
Path
class,
and allow file locations to be configured during deployment, or at runtime.Runtime.exec
and Method.invoke
.native
methods.LayoutManager
instead.java.awt.Toolkit.getScreenResolution
instead. For web apps, CSS media queries can help you adapt to a wide range of screen sizes.java.awt.Color
and java.awt.SystemColor
instead.Common System.getProperty(String)
items can be placed in a general purpose
constants class:
/** * Collected constants of very general utility. * * All constants must be immutable. * No instances of this class can be constructed. */ public final class Consts { /** * Prevent object construction outside of this class. */ private Consts(){ //empty } /** * Only refer to primitives and immutable objects. * * Arrays present a problem since arrays are always mutable. * DO NOT USE public static final array fields. * One style is to instead use an unmodifiable List, built in a * static initializer block. * * Another style is to use a private array and wrap it up like so: * <pre> * private static final Vehicle[] PRIVATE_VEHICLES = {...}; * public static final List VEHICLES = * Collections.unmodifiableList(Arrays.asList(PRIVATE_VEHICLES)); * </pre> */ //characters public static final String NEW_LINE = System.getProperty("line.separator"); public static final String FILE_SEPARATOR = System.getProperty("file.separator"); public static final String PATH_SEPARATOR = System.getProperty("path.separator"); public static final String EMPTY_STRING = ""; public static final String SPACE = " "; public static final String PERIOD = "."; public static final String TAB = "\t"; //algebraic signs public static final int POSITIVE = 1; public static final int NEGATIVE = -1; public static final String PLUS_SIGN = "+"; public static final String NEGATIVE_SIGN = "-"; }