It's not a secret anymore!
The moose likes Beginning Java and the fly likes import statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "import statement" Watch "import statement" New topic

import statement

Jason sigel
Ranch Hand

Joined: Oct 07, 2003
Posts: 30
I am new to java programming . Is this statement
import com.sybase.jdbc.*;
means I should be connected to net while running this programs.
I want to know what is the difference between package and import
statement.what I know is that if I give package directory in classpath then
all files would be included automatically else i have to use import
I am using classpath as .
and when I run this example
// Inheritance & upcasting
package c07;
class Note {
private int value;
private Note(int val) { value = val; }
public static final Note
middleC = new Note(0),
cSharp = new Note(1),
cFlat = new Note(2);
} // Etc.
class Instrument {
public void play(Note n) {
// Wind objects are instruments
// because they have the same interface:
class Wind extends Instrument {
// Redefine interface method:
public void play(Note n) {
public class Music {
public static void tune(Instrument i) {
// ...;
public static void main(String[] args) {
Wind flute = new Wind();
tune(flute); // Upcasting
} ///:~

it give me error and when I remove package statement then I could run the

Steven YaegerII
Ranch Hand

Joined: May 31, 2000
Posts: 182
I'll take a swing. First, when using both package and import - first comes the package statement, second comes the import statement, and then comes the class declaration.
Use a package statement when you have several files that are all related. You probally have other files with 'package c07;' at the top. Also keep in mind the default or package access when not declaring a public, private, or protected keyword. All the classes in your program that have none of the above access identifiers can be accessible from every file in the package.
Use the import statement to make other classes/API available for use: such as import javax.swing.*; ...for making graphical user interfaces (GUI's). Some of this may collide with more expert answers. Hope this helps a little.
[This message has been edited by Steven YaegerII (edited August 21, 2000).]

[This message has been edited by Steven YaegerII (edited August 21, 2000).]
I agree. Here's the link:
subject: import statement
jQuery in Action, 3rd edition