aspose file tools*
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why Are Long Package Names Atomic?" Watch "Why Are Long Package Names Atomic?" New topic
Author

Why Are Long Package Names Atomic?

Kevin Simonson
Ranch Hand

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

Life
|---source
| |---UseLife1.java
| |---UseLife2.java
| |---animal
| | |---mammal
| | | |---Whale.java
| | | `---Dog.java
| | |---reptile
| | | |---Snake.java
| | | `---Lizard.java
| | `---bird
| | |---Ostrich.java
| | `---Canary.java
| `---plant
| |---Bush.java
| `---Flower.java
`---target

and file "UseLife1.java" written like so:



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

javac -d ..\target UseLife1.java

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 "UseLife2.java" is written like so:



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

javac -d ..\target UseLife2.java

I get error message:

UseLife2.java:2: cannot find symbol
symbol : class reptile
location: package animal
import animal.reptile;
^
UseLife2.java:9: package reptile does not exist
reptile.Snake sn = new reptile.Snake();
^
UseLife2.java:9: 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 "UseLife2.java" does and then refer to <reptile.Snake>?

Kevin Simonson
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why Are Long Package Names Atomic?