Web hosting unlimited bandwidth - 394 Object-Based Programming Chapter 8 1. providing the
394 Object-Based Programming Chapter 8 1. providing the -classpath option to the javac compiler, or 2. setting the CLASSPATH environment variable (a special variable that you define and the operating system maintains so that applications can search for classes in the specified locations). In each case, the class path consists of a list of directories and/or archive files separated by semicolons (;). Archive files are individual files that contain directories of other files, typically in compressed format. For example, the standard classes of Java are contained in the archive file rt.jar that is installed with the J2SDK. Archive files normally end with the .jaror .zipfile name extensions. The directories and archive files specified in the class path contain the classes you wish to make available to the Java compiler. For more information on the class path, visit java.sun.com/j2se/1.3/docs/tooldocs/ win32/classpath.html for Windows or java.sun.com/j2se/1.3/docs/ tooldocs/solaris/classpath.html for Solaris/Linux. [Note: We discuss archive files in more detail in Section 8.8.] Common Programming Error 8.5 Specifying an explicit class path eliminates the current directory from the class path. This prevents classes in the current directory from loading properly. If classes must be loaded from the current directory, include the current directory (.) in the explicit class path. Software Engineering Observation 8.13 In general, it is a better practice to use the -classpath option of the compiler, rather than the CLASSPATH environment variable, to specify the class path for a program. This enables each application to have its own class path. Testing and Debugging Tip 8.2 Specifying the class path with the CLASSPATH environment variable can cause subtle and difficult-to-locate errors in programs that use different versions of the same packages. For the example of Fig. 8.4 and Fig. 8.5, we did not specify an explicit class path. Thus, to locate the classes in the com.deitel.jhtp4.ch08 package from this example, the compiler looks in the current directory for the first name in the package com. Next, the compiler navigates the directory structure. Directory comcontains the subdirectory deitel. Directory deitel contains the subdirectory jhtp4. Finally, directory jhtp4 contains subdirectory ch08. In the ch08 directory is the file Time1.class, which is loaded by the compiler to ensure that the class is used properly in our program. Locating the classes to execute the program is similar to locating the classes to compile the program. Like the compiler, the java interpreter searches the standard classes and extension classes first, then searches the class path (the current directory by default). The class path for the interpreter can be specified explicitly by using either of the techniques discussed for the compiler. As with the compiler, it is better to specify an individual program s class path via command-line options to the interpreter. You can specify the class path to the java interpreter via the -classpathor -cpcommand line options followed by a list of directories and/or archive files separated by semicolons (;). 8.6 Initializing Class Objects: Constructors When an object is created, its members can be initialized by a constructor method. A constructor is a method with the same name as the class (including case sensitivity). The pro Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01
Note: In case you are looking for affordable webhost to host and run your web application check Vision cheap hosting services