[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
JavaImport
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.
In this case, we must specify which class we want, calling it java.util.Date or java.sql.Date whenever we declare it.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
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
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.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
