This link has been bookmarked by 31 people . It was first bookmarked on 31 May 2007, by spdhillon.
-
16 Jul 17
-
Our
CLASSPATHthen needs to be changed to point to the new location of the packageworldaccordingly.
Thus, Java will look for java classes from the current directory and C:\myclasses directory instead.set CLASSPATH=.;C:\myclasses;
Someone may ask "Do we have to run the
HelloWorldat the directory that we store its class file everytime?". The answer is NO. We can run theHelloWorldfrom anywhere as long as we still include the packageworldin theCLASSPATH. -
How to use package
There are 2 ways in order to use the public classes stored in package.
1. Declare the fully-qualified class name. For example,
2) Use an "... world.HelloWorld helloWorld = new world.HelloWorld(); world.moon.HelloMoon helloMoon = new world.moon.HelloMoon(); String holeName = helloMoon.getHoleName(); ...
import" keyword:import world.*; // we can call any public classes inside the world package import world.moon.*; // we can call any public classes inside the world.moon package import java.util.*; // import all public classes from java.util package import java.util.Hashtable; // import only Hashtable class (not all classes in java.util package)
-
Note that if the package is stored inside a jar file, we have to include the jar file with its extension (.jar) in the
CLASSPATH. However, if the package is a plain directory, we just put the name of directory into theCLASSPATH.
-
-
10 Aug 14
-
03 Jun 14
-
22 Sep 12
-
C:\world>java world.HelloWorld
-
fully-qualified class name is the name of the java class that includes its package name
-
set CLASSPATH=.;C:\myclasses;
-
import world.*; // we can call any public classes inside the world package import world.moon.*; // we can call any public classes inside the world.moon package import java.util.*; // import all public classes from java.util package import java.util.Hashtable; // import only Hashtable class (not all classes in java.util package)
-
Normally, we can see what is inside a jar file by using the command
jar -tvf fileName.jar -
Note that if the package is stored inside a jar file, we have to include the jar file with its extension (.jar) in the
CLASSPATH. However, if the package is a plain directory, we just put the name of directory into theCLASSPATH.
-
-
12 Sep 12
-
02 May 11
-
02 Dec 10
-
11 Feb 10
-
13 May 09
-
21 Aug 08
-
13 Dec 07
-
26 Oct 07
-
21 Mar 07
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.