[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
JavaImport

Java's import

Java's import statement is used to look for packages and include them in a program. Packages are Java's way of organizing the classes most commonly used by all Java programmers. For example, if I want to open a file, I wouldn't want to write all the file-handling routines all over again, since that's too much work; instead, I would use Java's file-handling classes:

import java.io.*;


This allows me to use the File class (you're welcome to use it too). The File class is in the io subpackage, which in turn is in the java package.

If we didn't put in the import statement, we wouldn't be able to get the File class whenever we wanted--we'd have to call it by its full name, java.io.File, every time we used it.

The import statement doesn't actually load every single class in java.io; that would take a while. Instead, it makes the package open to easy access.

Conflicts

import java.util.*;
import java.sql.*;
So what if both the java.util subpackage and the java.sql subpackage have a class called Date? (They do, in fact)

In this case, we must specify which class we want, calling it java.util.Date or java.sql.Date whenever we declare it.

last edited (December 22, 2002) by chrisarts, Number of views: 2144, Current Rev: 2 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.