Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Oct 1996 11:27:26 -0700 (PDT)
From:      Jeffrey Hsu <hsu>
To:        hackers, questions,
Subject:   Java CLASSPATH
Message-ID:  <>

Next in thread | Raw E-Mail | Index | Archive | Help
The Java interpreter looks for a class using the following algorithm.

  1. Take the class name and append '.class' to it to form a filename.

	Object -> Object.class

  2. Take the package of the class, replace the dots with slashes,
     and prepends that directory to the filename in step 1.

	Object is in the java.lang package so the class java.lang.Object,
	 gets transformed into the path java/lang/Object.class.
	If the class doesn't have a package, then it uses the current
	  directory, '.'.

  3.  For every element in your CLASSPATH, look for the path formed in step 2.

	% setenv CLASSPATH .:/usr/local/java/

	This CLASSPATH has 3 elements: 2 directories, . and /usr/lib/classes,
	and one zip file /usr/local/java/  Zip files are
	collections of files with the full pathname of the files preserved.

	Given this CLASSPATH, first the Java interpreter looks in
	. for java/lang/Object.class, then it looks in the zipfile
	/usr/local/java/ for java/lang/Object.class,
	and finally, it looks in /usr/lib/classes for java/lang/Object.class.

Want to link to this message? Use this URL: <>