when tinkering with classes, but as a (Web site builder) general

when tinkering with classes, but as a general rule, it’s bad practice to put the current directory in any kind of path. The Java interpreter and the other command-line tools also know how to find core classes, which are the classes included in every Java installation. The classes in the java.lang, java.io, java.net, and javax.swing packages, for example, are all core classes. You don’t need to include these classes in your class path; the Java interpreter and the other tools can find them by themselves. To find other classes, the Java interpreter searches the locations on the class path in order. The search combines the path location and the fully qualified class name. For example, consider a search for the class animals.birds.BigBird. Searching the class path directory /usr/lib/java means the interpreter looks for an individual class file at /usr/lib/java/animals/birds/BigBird.class. Searching a ZIP or JAR archive on the class path, say /home/vicky/Java/utils/classutils.jar, means that the interpreter looks for component file animals/birds/BigBird.class in the archive. For the Java interpreter, java, and the Java compiler, javac, the class path can also be specified with the -classpath option: % javac -classpath /pkg/sdk/lib/classes.zip:/home/pat/java:. Foo.java If you don’t specify the CLASSPATH environment variable, it defaults to the current directory (.); this means that the files in your current directory are always available. If you change the class path and don’t include the current directory, these files will no longer be accessible. 3.4 The Java Compiler In this section, we’ll say a few words about javac, the Java compiler that is supplied as part of Sun’s SDK. (If you are happily working in another development environment, you may want to skip ahead to the next section.) The javaccompiler is written entirely in Java, so it’s available for any platform that supports the Java runtime system. The ability to support its own development environments is an important stage in a language’s development. Java makes this bootstrapping automatic by supplying a ready-to-run compiler at the same cost as porting the interpreter. javac turns Java source code into a compiled class that contains Java virtual machine byte- code. By convention, source files are named with a .java extension; the resulting class files have a .class extension. Each source code file is a single compilation unit. As you’ll see in Chapter 6, classes in a given compilation unit share certain features, such as package and import statements. javac allows you one public class per file and insists the file have the same name as the class. If the filename and class name don’t match, javac issues a compilation error. A single file can contain multiple classes, as long as only one of the classes is public. Avoid packing many classes into a single source file. Including non-public classes in a .java file is one easy way to tightly couple such classes to a public class. But you might also consider using inner classes (see Chapter 6). Now for an example. Place the following source code in file BigBird.java: package animals.birds; public class BigBird extends Bird {
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision virtual web hosting services

Leave a Reply