Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #9185

Re: Unable to use package...why ???

From Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Unable to use package...why ???
Date 2011-10-26 00:06 +0000
Organization UK Free Software Network
Message-ID <j87it8$50i$1@localhost.localdomain> (permalink)
References (2 earlier) <02de641c-1c6a-420b-b059-c17444e1ff3e@g25g2000yqh.googlegroups.com> <9gnn4cFbaqU1@mid.individual.net> <j86i64$j5u$1@dont-email.me> <f756ecfd-0c89-4ab0-abb8-d94be8ac2361@o19g2000vbk.googlegroups.com> <2482c1e3-adde-4a2f-a245-a129958b4ba6@n13g2000vbv.googlegroups.com>

Show all headers | View raw


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       |

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Unable to use package...why ??? PortisHead <massivetdm850@gmail.com> - 2011-10-25 00:06 -0700
  Re: Unable to use package...why ??? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-10-25 10:32 +0100
    Re: Unable to use package...why ??? PortisHead <massivetdm850@gmail.com> - 2011-10-25 04:10 -0700
      Re: Unable to use package...why ??? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-10-25 13:07 +0100
        Re: Unable to use package...why ??? markspace <-@.> - 2011-10-25 07:47 -0700
          Re: Unable to use package...why ??? PortisHead <massivetdm850@gmail.com> - 2011-10-25 15:03 -0700
            Re: Unable to use package...why ??? PortisHead <massivetdm850@gmail.com> - 2011-10-25 15:10 -0700
              Re: Unable to use package...why ??? Martin Gregorie <martin@address-in-sig.invalid> - 2011-10-26 00:06 +0000
                Re: Unable to use package...why ??? Martin Gregorie <martin@address-in-sig.invalid> - 2011-10-26 00:08 +0000
              Re: Unable to use package...why ??? Martin Gregorie <martin@address-in-sig.invalid> - 2011-10-26 00:06 +0000
          Re: Unable to use package...why ??? PortisHead <massivetdm850@gmail.com> - 2011-10-25 15:21 -0700
            Re: Unable to use package...why ??? markspace <-@.> - 2011-10-25 15:57 -0700
            Re: Unable to use package...why ??? Lew <lewbloch@gmail.com> - 2011-10-25 20:05 -0700
          Re: Unable to use package...why ??? Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-10-26 09:55 +0100
            Re: Unable to use package...why ??? PortisHead <massivetdm850@gmail.com> - 2011-10-26 13:08 -0700
  Re: Unable to use package...why ??? Roedy Green <see_website@mindprod.com.invalid> - 2011-10-27 07:20 -0700
  Re: Unable to use package...why ??? Lew <lewbloch@gmail.com> - 2011-10-27 07:33 -0700
    Re: Unable to use package...why ??? PortisHead <massivetdm850@gmail.com> - 2011-10-28 12:57 -0700

csiph-web