jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes packaged class using unpackaged class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "packaged class using unpackaged class" Watch "packaged class using unpackaged class" New topic

packaged class using unpackaged class

David Duran
Ranch Hand

Joined: Feb 11, 2002
Posts: 122
Here's a quote from this site http://bdn.borland.com/article/0,1410,26969,00.html

If no package name is specified in a class or interface then that class or interface is said to be part of the "default" or "unnamed" package. Note that if you place your class or interface in the default package then all other classes or interfaces in all other packages will have access to that class (unless it is declared private). For this reason it is considered good practice to put all classes and interfaces in packages.

Unfortunately, that doesn't work me.
For example, I'll have those unnamed classes in a jar and put them in my classpath and reference them in another unnamed class. Works.
As soon as I put a package statement on MY unnamed class, it says it can't find the (unnamed) classes in the jar file.
Am I missing something? I assume from that quote I can reference the class as if it were part of the same package in the class, ie. no imports of the class are needed.
David Duran
Ranch Hand

Joined: Feb 11, 2002
Posts: 122
Apparently this page says the opposite of that quote - http://www.cs.wisc.edu/~hasti/cs368/JavaTutorial/NOTES/Packages.html
I guess unnamed-package classes can not use named-package classes.
Matt Cao
Ranch Hand

Joined: Apr 03, 2003
Posts: 715
Hi David,
Good detective practice. The other article using package in the POV of JBuilder not in term of the Java language.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
I guess unnamed-package classes can not use named-package classes.
Or the other way around perhaps - classes in named packages cannot use classes in the unnamed package, while classes in the unnamed package can use classes in named classes, provided the CLASSPATH is set correctly and the correct import statements are used.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: packaged class using unpackaged class
It's not a secret anymore!