Qingnan Zhou said:
Hello, I am very new to Java.
In C++, I can use #include to include other .cpp files.
In Java, I know I am suppose to use import key word, but what type of
file should follow import? .class or .java or neither?
Thanks.
James
In Java, you don't import files as such, you import packages and classes.
So, if I want to import the Vector class to hold a lsit in, I would use
import java.util.Vector;
Here, java.util is the package, and Vector is the class.
However, java.util has LOTS of very useful classes -
http://java.sun.com/j2se/1.4.2/docs/api/java/util/package-frame.html - and I
might want to import them all, so I use
import java.util.*;
Now I can create a Vector:
Vector v = new Vector();
Sometimes, I don't want to import the class, as I only use it once, or the
name conflicts with another class. Then, I might just use a fully qualified
class name, without any code...
java.util.Vector v = new java.util.Vector(); // This will not require an
import statement.
When you compile your program, you need to make sure you have told the
compiler where to find the classes/packages you have imported by using
the -classpath switch, or setting the CLASSPATH environment variable.
If you do a google search, or go to java.sun.com, there is FAR more
information out there on all these concepts - I suggest you read it
through - classes and packages are very confusing to begin with, but really
useful when you use them properly.