Refer to the classes in a package Assignment Help

Assignment Help: >> Creating your own packages >> Refer to the classes in a package

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

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

  1. Higher degree holder and experienced experts network
  2. Punctuality and responsibility of work
  3. Quality solution with 100% plagiarism free answers
  4. Time on Delivery
  5. Privacy of information and details
  6. Excellence in solving java programming language queries in excels and word format.
  7. Best tutoring assistance 24x7 hours

 

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd