Refer to the classes in a package:
If the class you want is in the same package as the class you are working on, then you use the simple name of the class you want, as normal. If the class is in a different package - whether it is one written by you or by someone else in your team, or it is in a standard Java package - you use the import facility.
Consider Figure, which shows the structure of a file directory for a project. A project will typically have a top-level directory (or folder) with a number of subdirectories and possibly several levels of subdirectories for a complex project. We assume here the commonly used approach whereby the Java system expects to find each package in a separate subdirectory, with the subdirectory having the same name as the package.
![1853_refer to class in package.png](https://www.expertsmind.com/CMSImages/1853_refer%20to%20class%20in%20package.png)
A directory structure for class files in asoftware project
If we have grouped a number of classes in a package defined as:
package tools;
then these classes will be stored in the tools subdirectory of the top-level directory projectlibrary. When we want to import one of the classes in this package, say the Formatter class, we use:
import tools.*;
or:
import tools.Formatter;
In large projects, we may wish to arrange a package to havea number of subpackages. Suppose we have grouped a number of utility classes in a subpackage defined as:
package general.utilities;
In this case, the classes must be in the utilities subdirectory of the general directory, as shown in Figure 1. So the components of a package name are separated by dots and each component corresponds to a subdirectory, starting from the top-level directory for the project.
Let us focus on the NewUtility.class file, which contains the compiled code (bytecode) for a class that we want to use. If we wanted to use the class contained in the file NewUtility.class that is contained in the directory utilities, which in turn is held in the directory general that forms part of the top-level directory projectlibrary, then we would write:
import general.utilities.NewUtility;
To have access to any class in this package we can use the import-on-demand style:
import general.utilities.*;
The import declarations in a source file are placed immediately after the package declaration, if any.
Java Assignment Help - Java Homework Help
Struggling with java programming language? Are you not finding solution for your Refer to the classes in a package homework and assignments? Live Refer to the classes in a package experts are working for students by solving their doubts & questions during their course studies and training program. We at Expertsmind.com offer Refer to the classes in a package homework help, java assignment help and Refer to the classes in a package projects help anytime from anywhere for 24x7 hours. Computer science programming assignments help making life easy for students.
Why Expertsmind for assignment help
- Higher degree holder and experienced experts network
- Punctuality and responsibility of work
- Quality solution with 100% plagiarism free answers
- Time on Delivery
- Privacy of information and details
- Excellence in solving java programming language queries in excels and word format.
- Best tutoring assistance 24x7 hours