• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

package name question (from OCA8 book)

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic