Java Reference
In-Depth Information
standsfor“createnewarchive”andthe f optionstandsfor“specifyarchivefi-
lename.”)
Youshouldnowfinda logger.jar fileinthecurrentdirectory.Toprovetoyour-
selfthatthisfilecontainsthefourclassfiles,execute jar tf logger.jar .(The t
option stands for “list table of contents.”)
You can run TestLogger.class by adding logger.jar to the classpath. For
example,youcanrun TestLogger underWindowsvia java -classpath log-
ger.jar;. TestLogger .
Static Imports
An interface should only be used to declare a type. However, some developers violate
thisprinciplebyusinginterfacestoonlyexportconstants.Suchinterfacesareknownas
constant interfaces , and Listing 3-22 presents an example.
Listing 3-22. Declaring a constant interface
interface Directions
{
int NORTH = 0;
int SOUTH = 1;
int EAST = 2;
int WEST = 3;
}
Developers who resort to constant interfaces do so to avoid having to prefix a con-
stant'snamewiththenameofitsclass(asin Math.PI ,where PI isaconstantinthe
java.lang.Math class). They do this by implementing the interface—see Listing
3-23 .
Listing 3-23. Implementing a constant interface
class TrafficFlow implements Directions
{
public static void main(String[] args)
{
showDirection((int)(Math.random()*4));
}
Search WWH ::




Custom Search