my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why Are Long Package Names Atomic? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why Are Long Package Names Atomic?" Watch "Why Are Long Package Names Atomic?" New topic

Why Are Long Package Names Atomic?

Kevin Simonson
Ranch Hand

Joined: Oct 22, 2011
Posts: 103
With directory structure:

| |
| |
| |---animal
| | |---mammal
| | | |
| | | `
| | |---reptile
| | | |
| | | `
| | `---bird
| | |
| | `
| `---plant
| |
| `

and file "" written like so:

I can change to directory "Life\source" and type in:

javac -d ..\target

and that command will compile all the source code and put class files under "Life\target" (including the class file for class <UseLife1>).

But if file "" is written like so:

and I, once again from directory "Life\source", type in:

javac -d ..\target

I get error message: cannot find symbol
symbol : class reptile
location: package animal
import animal.reptile;
^ package reptile does not exist
reptile.Snake sn = new reptile.Snake();
^ package reptile does not exist
reptile.Snake sn = new reptile.Snake();
3 errors

This is actually exactly what Sun Certified Programmer for Java 6 Study Guide says should happen, because package names are atomic, and can't be split up like I'm doing here. But why exactly was it decided to make package names atomic like this? Wouldn't it be a handy shorthand to be able to import <animal.reptile> like "" does and then refer to <reptile.Snake>?

Kevin Simonson
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

As for why it was decided by the original designers... you'll have to hunt down the original designers and ask them.

To me it seems like your proposal is just another source of ambiguity which would have to have rules written and documented (in the Java Language Specification) and implemented (in compilers) for little or no benefit.
It is sorta covered in the JavaRanch Style Guide.
subject: Why Are Long Package Names Atomic?
Similar Threads
Eclips error
Set Ant Classpath for Compile
Why Doesn't my Code Work with this Jar File?
errors generated when running Ant build file in Eclipse
package org.apache.struts.action does not exists