Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!usenet.ukfsn.org!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: Unable to use package...why ??? Date: Wed, 26 Oct 2011 00:06:01 +0000 (UTC) Organization: UK Free Software Network Lines: 39 Message-ID: References: <280344ac-b398-44b3-b775-e84859feb5f0@gy7g2000vbb.googlegroups.com> <9gne1vFvskU1@mid.individual.net> <02de641c-1c6a-420b-b059-c17444e1ff3e@g25g2000yqh.googlegroups.com> <9gnn4cFbaqU1@mid.individual.net> <2482c1e3-adde-4a2f-a245-a129958b4ba6@n13g2000vbv.googlegroups.com> NNTP-Posting-Host: 84.45.235.129 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: localhost.localdomain 1319587561 5138 84.45.235.129 (26 Oct 2011 00:06:01 GMT) X-Complaints-To: usenet@localhost.localdomain NNTP-Posting-Date: Wed, 26 Oct 2011 00:06:01 +0000 (UTC) User-Agent: Pan/0.135 (Tomorrow I'll Wake Up and Scald Myself with Tea; GIT 30dc37b master) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9185 On Tue, 25 Oct 2011 15:10:43 -0700, PortisHead wrote: > The "imported" class is in c:\myclasses , OK , but why does it need also > a reference to the current directory ??? > The imported class has two rather different uses: 1)the compiler reads it so it can check that what you wrote does actually match the constructors and classes you're trying to call, but that is all it does with it. 'import' doesn't mean that the class is imported into your code. Instead it means that its symbol table is imported into the javac compiler. 2)the java command creates a JVM containing your class containing the static void mail(String[]) method and then searches the classpath to find *and load* the classes your source mentioned in import statements together with classes they imported and so on, in a cascade until all these references are satisfied. Then, and only then, can the program run. The loader is probably getting classes from a collection of jar files which are probably not in the same place in the filing system as they were when the code was compiled. Indeed, its quite likely that the imported class wasn't even in a jarfile at compile time. All that matters is that the packagename.ClassName is the same, relative to the runtime classpath, as the packagename.ClassName was relative to the classpath that was passed to the compiler. This is why the compiler class path needs to include "." if packagename is the name of the directory that contains ClassName.class relative to the directory where you ran the compiler BUT can still be found when packagename.ClassName.class has been packaged up in a jar file and put in some random directory and included in the runtime classpath. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |