• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

"Observable" packages?

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am unable to understand the meaning of observable as talked about with respect to Scope of a Package as stated in JLS.
The only information I could get in this regard was the Observable class in the java.util package, which requires objects to be implemented with the Observer interface. This doesn't appear to be releavant to package declarations.
My questions are -
1. How do we set packages observable/not-observable. Sec7.4.3 states that a package is only observable is either a compilation unit or a subpackage is observable??
2. How do we know whether a package is observable or not-observable
3. How do we set compilation units observable/or not-observable. Refer question 1 above.
4. What do you mean by the sentence above - "subpackage declarations are never in scope". You can always declare subpackages as - myPackage.mySubPackage.
Following are quotes from various sections of JLS -
JLS Scope of a Package Declaration states -


I have quoted from different parts of JLS Chap 7 which talk about "observable" in this regard -
JLS 7.2 -

JLS 7.3 -

JLS 7.4.3


[This message has been edited by Jane Griscti (edited March 08, 2001).]
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Niraj,
Based on the wording in the JLS, I think they are using observable to mean if the system can locate....
For example, let's say you have application file <code>MyApp</code> stored in the directory <code>c:\myJava</code> which uses the <code>Test.class</code> stored in <code>c:\javaLibrary</code>.
You change directories so you are in <code>c:\myJava</code> and enter <code>javac MyApp.java</code>. The compiler throws up an error saying it can't find the class <code>Test</code>. The JVM cannot find Test.class. It is not observable!
Why not? You know it's on your system? Then you realize you forgot to set the <code>CLASSPATH</code>. So, you try to another compile using <code>javac -classpath .;c:\javaLibrary MyApp.java</code> and the code compiles with no errors.
By setting the <code>CLASSPATH</code> you gave the JVM a way to observe the <code>Test.class</code>.

  1. a compilation unit, subpackage, package are observable if the JVM can locate them on the system. In DOS this can involve setting the PATH or CLASSPATH environment variables.
  2. we know if something is observable if we've configured our system correctly; provided the JVM a means of locating the file
  3. the location we store a file determines wether or not it is observable; if it's somewhere along the classpath then the JVM can find it; otherwise, it's not observable

  4. Your last question relates to scope which is not quite the same as observable.
    packages and subpackages are only used to help you organize your compilation units. They don't infer any special privileges on the classes they contain.
    For example, if you have the following directory structure:

    Classes in the <code>sub1</code> package are not automatically accessible to all the classes in the <code>mypkg</code>. You cannot reference <code>class2</code> from <code>class1</code> just because it's in a subdirectory of mykg</code>. You would need to specifically import <code>class2</code> or use it's explicit name <code>mypkg.sub1.class2</code>.
    Hope that helps.
    ------------------
    Jane Griscti
    Sun Certified Programmer for the Java� 2 Platform

    [This message has been edited by Jane Griscti (edited March 08, 2001).]
 
niraj singh
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jane,
Thanks a lot for clearing that one up. It was a real help.
 
reply
    Bookmark Topic Watch Topic
  • New Topic