• Post Reply Bookmark Topic Watch Topic
  • New Topic

package name question (from OCA8 book)  RSS feed

 
Lane Moe
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I'm doing some review questions from an OCA8 study guide, the book gives a question about package name, just like:

the following class is in the file /my/directory/named/A/Bird.java
and we compile from /my/directory

...PACKAGE HERE...
public class Bird {}

I think both package named.A & package my.directory.named.A are OK, but the book says the latter one is wrong because "package names are case sensitive".
This explanation just makes no sense to me at all, so any advice would be much appreciated.
 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't matter what you call the package. You could type "package x.y.z;" and it will compile fine and exzecute fine if your classpath is correct and you store the Bird.class file in the proper directory structure: x/y/z/Bird.class

Now that said, it is probably not a good idea to do that.
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason package my.directory.named.A; is incorrect is because it implies a directory structure of

  /my/directory/my/directory/named/A

That is to say, package names are relative to the directory they're compiled from. I don't know why the book said something about case sensitivity. Can you quote the book exactly?
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I think the reason they say it is wrong is because the Java™ Tutorials recommend certain naming conventions, including using lower‑case names. I think you will get a package name in UPPER‑CASE past the compiler, however. Of course A is a bad name for anything except a formal type parameter.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!