392 Object-Based Programming Chapter 8 Software Engineering Observation (Web domain)
392 Object-Based Programming Chapter 8 Software Engineering Observation 8.12 A Java source code file has the following order: a package statement (if any), zero or more import statements, then class definitions. Only one of the class definitions in a particular file can be public. Other classes in the file are also placed in the package, but are reusable only from other classes in that package they cannot be imported into classes in another package. They are in the package to support the reusable class in the file. In an effort to provide unique names for every package, Sun Microsystems specifies a convention for package naming that all Java programmers should follow. Every package name should start with your Internet domain name in reverse order. For example, our Internet domain name is deitel.com, so we began our package name with com.deitel. If your domain name is yourcollege.edu, the package name you would use is edu.yourcollege. After the domain name is reversed, you can choose any other names you want for your package. If you are part of a company with many divisions or a university with many schools, you may want to use the name of your division or school as the next name in the package. We chose to use jhtp4 as the next name in our package name to indicate that this class is from Java How to Program: Fourth Edition. The last name in our package name specifies that this package is for Chapter 8 (ch08). [Note: We use our own packages several times throughout the book. You can determine the chapter in which one of our reusable classes is defined by looking at the last part of the package name in the import statement. This appears before the name of the class being imported or before the * if a particular class is not specified.] Step 3 is to compile the class so it is stored in the appropriate package. When a Java file containing a package statement is compiled, the resulting .class file is placed in the directory structure specified by the package statement. The preceding package statement indicates that class Time1 should be placed in the directory ch08. The other names com, deitel and jhtp4 are also directories. The directory names in the package statement specify the exact location of the classes in the package. If these directories do not exist before the class is compiled, the compiler creates them. When compiling a class in a package, there is an extra option (-d) that must be passed to the javaccompiler. This option specifies where to create (or locate) the directories in the package statement. For example, we used the compilation command javac -d . Time1.java to specify that the first directory specified in our package name should be placed in the current directory. The . after -d in the preceding command represents the current directory on the Windows, UNIX and Linux operating systems (and several others as well). After executing the compilation command, the current directory contains a directory called com, com contains a directory called deitel, deitelcontains a directory called jhtp4 and jhtp4 contains a directory called ch08. In the ch08 directory, you can find the file Time1.class. The package directory names become part of the class name when the class is compiled. The class name in this example is actually com.deitel.jhtp4.ch08.Time1 after the class is compiled. You can use this fully qualified name in your programs or you can import the class and use its short name (Time1) in the program. If another package also contains a Time1 class, the fully qualified class names can be used to distinguish between the classes in the program and prevent a naming conflict (also called a name collision). Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision tomcat hosting services